Skip to content

Commit

Permalink
Merge pull request #6 from evaline-ju/better-errors
Browse files Browse the repository at this point in the history
🧑‍💻 Add better assertion messages
  • Loading branch information
gabe-l-hart authored Apr 28, 2023
2 parents 63d9b90 + b145bd5 commit 17b9e5b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions aconfig/aconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ def _verify_config_location(config_location):
config_location = os.path.normpath(config_location)

assert (config_location.endswith('.yml') or config_location.endswith('.yaml')), \
'Must send in a .yaml or .yaml file'
'Must send in a .yaml or .yaml file, you sent in: <{0}>'.format(config_location)

assert os.path.exists(config_location), \
'config_location does not exist or cannot be found!'
'config_location <{0}> does not exist or cannot be found!'.format(config_location)

# finally found it's valid
return config_location
Expand Down
2 changes: 2 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test__verify_config_location_fail(self):
bad_config2 = aconfig.Config._verify_config_location(fixtures.BAD_CONFIG_LOCATION)
raised_exception2 = ex2.exception
self.assertIsInstance(raised_exception2, AssertionError)
self.assertIn(fixtures.BAD_CONFIG_LOCATION, str(ex2.exception))
# make sure bad_config2 was NOT initialized
self.assertEqual(getattr(locals(), 'bad_config2', None), None)

Expand All @@ -56,6 +57,7 @@ def test__verify_config_location_fail(self):
bad_config3 = aconfig.Config._verify_config_location(fixtures.NOT_YAML_CONFIG_LOCATION)
raised_exception3 = ex3.exception
self.assertIsInstance(raised_exception3, AssertionError)
self.assertIn(fixtures.NOT_YAML_CONFIG_LOCATION, str(ex3.exception))
# make sure bad_config3 was NOT initialized
self.assertEqual(getattr(locals(), 'bad_config3', None), None)

Expand Down

0 comments on commit 17b9e5b

Please sign in to comment.