forked from VenkateshDoijode/selenium_with_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigreader.py
More file actions
78 lines (61 loc) · 2.36 KB
/
Copy pathconfigreader.py
File metadata and controls
78 lines (61 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
@package base
ConfigReader class implementation
It reads the configuration files needed for the framework
All the methods to read different configuration file should be implemented in Util class
Example:
self.cfg = ConfigReader(fileName=fileName)
self.cfg.configRead()
value = self.cfg.getConfiguration(section, option)
"""
from configparser import ConfigParser
import os
class ConfigReader(object):
def __init__(self, fileName="messages.ini"):
self.parser = ConfigParser()
scriptDirectory = os.path.dirname(__file__)
relativePath = "../configfiles/" + fileName
absFilePath = os.path.join(scriptDirectory, relativePath)
self.file = absFilePath
# self.file = ['/auto/home.nas03/atomar/hg/ntests/cases/gui/configfiles/testenvironment.ini']
def configRead (self):
self.parser.read(self.file)
def configSectionMap(self, section):
"""
Returns a dictionary of 'Option and Value' under a section
Required Parameters:
section: Section in the file under which options exist
Look at messages.ini to understand the format of a configuration file
Optional Parameters:
None
Returns:
Dictionary of 'Option and Value'
"""
config = {}
options = self.parser.options(section)
for option in options:
try:
config[option] = self.parser.get(section, option)
if config[option] == -1:
print("skip: %s" % option)
except:
print("exception on %s!" % option)
config[option] = None
return config
def getConfiguration(self, section, option):
"""
Get value of the provided option and section
Required Parameters:
section: Section in the file under which options exist
option: Option whose corresponding value is needed
Optional Parameters:
None
Returns:
Value of the provided option
"""
config_map = self.configSectionMap(section)
option_value = config_map[option]
return option_value
def testMethod(self):
value = ConfigReader.getConfiguration(self,'Grid', 'remote')
print(value)