commit
37fd4c7fdc
@ -0,0 +1,34 @@
|
||||
from configparser import ConfigParser as CP
|
||||
from io import StringIO
|
||||
|
||||
|
||||
class ConfigParser(CP):
|
||||
'''
|
||||
ConfigParser class with to_string method to convert config to string
|
||||
and write it inside jinja template and read methods which return
|
||||
self object
|
||||
'''
|
||||
|
||||
def to_string(self):
|
||||
io = StringIO()
|
||||
self.write(io)
|
||||
return io.getvalue()
|
||||
|
||||
def read(self, *args, **kwards):
|
||||
super().read(*args, **kwards)
|
||||
return self
|
||||
|
||||
def read_dict(self, *args, **kwards):
|
||||
super().read_dict(*args, **kwards)
|
||||
return self
|
||||
|
||||
def read_file(self, *args, **kwards):
|
||||
super().read_file(*args, **kwards)
|
||||
return self
|
||||
|
||||
def read_string(self, *args, **kwards):
|
||||
super().read_string(*args, **kwards)
|
||||
return self
|
||||
|
||||
def __str__(self):
|
||||
return self.to_string()
|
@ -0,0 +1,19 @@
|
||||
from commons import clean_env
|
||||
|
||||
from pyentrypoint.configparser import ConfigParser
|
||||
|
||||
|
||||
def teardown_function(function):
|
||||
clean_env()
|
||||
|
||||
|
||||
def test_configparser():
|
||||
config = '''
|
||||
[ini]
|
||||
content = ok
|
||||
'''.strip()
|
||||
|
||||
c = ConfigParser()
|
||||
c.read_string(config)
|
||||
|
||||
assert str(c).strip() == config
|
Loading…
Reference in New Issue