Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from __future__ import absolute_import
from __future__ import unicode_literals
import os
import mock
import pytest
from testfixtures import ShouldRaise
from testfixtures import StringComparison as S
import pgctl.config as C
class example1(object):
config = C.Config('example1')
ini = '''\
[example1]
pgdir = mypgdir
pgconf = my.conf
services_list =
first
second
third
'''
yaml = '''\
pgdir: mypgdir
pgconf: my.conf
services:
- first
def it_combines_all_the_configs(self, tmpdir):
config = Config('my', {'default': 'default'})
with setup(tmpdir):
conf = config.combined()
assert conf == {
'etc': 'etc',
'home': 'home',
'app': 'app',
'apps': ['1', '2', '3'],
'app/a': 'app/a',
'app/b': 'app/b',
'environ': 'environ',
'environs': ['1', '2', '3'],
}
def it_has_parity_with_file_configs(self):
config = C.Config(projectname='example1')
assert config.from_environ(example1.environ) == example1.parsed
def it_can_parse(self):
config = C.Config(projectname='my')
assert config.from_environ({'MY_X': 2, 'MYY': 3, 'Z': 4}) == {'x': 2}
def it_can_parse_the_environ(self):
config = C.Config(projectname='example1')
with mock.patch.dict(os.environ, example1.environ):
assert config.from_environ() == example1.parsed
def main():
from sys import argv
for project in argv[1:]:
print(json.dumps(
Config(project).combined(),
sort_keys=True,
indent=4,
))
def main(argv=None):
p = parser()
args = p.parse_args(argv)
config = Config('pgctl')
config = config.combined(PGCTL_DEFAULTS, args)
app = PgctlApp(config)
return app()