Skip to content

Commit

Permalink
Add more tests to improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
osantana committed Jan 31, 2019
1 parent bf02c30 commit ee8673e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
1 change: 0 additions & 1 deletion prettyconf/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ def __getitem__(self, item):


class RecursiveSearch(AbstractConfigurationLoader):

def __init__(self, starting_path, filetypes=(('.env', EnvFile), (('*.ini', '*.cfg',), IniFile),), root_path="/"):
"""
:param str starting_path: The path to begin looking for configuration files.
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cfgfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ def setUp(self):
super(IniFileTestCase, self).setUp()
self.inifile = self.test_files_path + "/config.ini"

def test_basic_config_object(self):
config = IniFile(self.inifile)

self.assertEqual(repr(config), 'IniFile("{}")'.format(self.inifile))

def test_fail_invalid_settings_file(self):
with self.assertRaises(InvalidConfigurationFile):
return IniFile(self.test_files_path + "/invalid_section.ini")['some_value']
Expand Down Expand Up @@ -58,3 +63,12 @@ def formatter(x):

self.assertIn("VAR", config)
self.assertEqual("test", config["VAR"])

def test_fail_missing_envfile_contains(self):
config = IniFile("does-not-exist.ini")
self.assertNotIn('error', config)

def test_fail_missing_envfile_get_item(self):
config = IniFile("does-not-exist.ini")
with self.assertRaises(KeyError):
return config['error']
4 changes: 3 additions & 1 deletion tests/test_commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_parse_args():


class CommandLineTestCase(BaseTestCase):

def setUp(self):
super(CommandLineTestCase, self).setUp()
parser = parser_factory()
Expand Down Expand Up @@ -47,3 +46,6 @@ def test_args():
config = CommandLine(parser=parser)
self.assertEquals(config['var'], 'bar')
self.assertEquals(config['var2'], 'bar2')

def test_contains_missing_keys(self):
self.assertNotIn('var3', self.config)
14 changes: 14 additions & 0 deletions tests/test_envfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def setUp(self):
super(EnvFileTestCase, self).setUp()
self.envfile = os.path.join(self.test_files_path, "envfile")

def test_basic_config_object(self):
config = EnvFile(self.envfile)

self.assertEqual(repr(config), 'EnvFile("{}")'.format(self.envfile))

def test_config_file_parsing(self):
config = EnvFile(self.envfile)

Expand Down Expand Up @@ -49,3 +54,12 @@ def formatter(x):

self.assertIn("VAR", config)
self.assertEqual("test", config["VAR"])

def test_fail_missing_envfile_contains(self):
config = EnvFile("does-not-exist.env")
self.assertNotIn('error', config)

def test_fail_missing_envfile_get_item(self):
config = EnvFile("does-not-exist.env")
with self.assertRaises(KeyError):
return config['error']

0 comments on commit ee8673e

Please sign in to comment.