Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_missing_pre_commit(self):
config = AutohooksConfig({'tool': {'autohooks': {'foo': 'bar'}}})
self.assertTrue(config.has_config())
self.assertTrue(config.has_autohooks_config())
self.assertTrue(config.is_autohooks_enabled())
self.assertEqual(config.get_mode(), Mode.UNDEFINED)
self.assertEqual(len(config.get_pre_commit_script_names()), 0)
def test_get_mode_pipenv(self):
config = AutohooksConfig({'tool': {'autohooks': {'mode': 'pipenv'}}})
self.assertTrue(config.has_config())
self.assertTrue(config.has_autohooks_config())
self.assertTrue(config.is_autohooks_enabled())
self.assertEqual(config.get_mode(), Mode.PIPENV)
self.assertEqual(len(config.get_pre_commit_script_names()), 0)
def test_get_mode_unknown(self):
config = AutohooksConfig({'tool': {'autohooks': {'mode': 'foo'}}})
self.assertTrue(config.has_config())
self.assertTrue(config.has_autohooks_config())
self.assertTrue(config.is_autohooks_enabled())
self.assertEqual(config.get_mode(), Mode.UNKNOWN)
self.assertEqual(len(config.get_pre_commit_script_names()), 0)
def test_empty_config_dict(self):
config = AutohooksConfig({'foo': 'bar'})
self.assertTrue(config.has_config())
self.assertFalse(config.has_autohooks_config())
self.assertFalse(config.is_autohooks_enabled())
self.assertEqual(config.get_mode(), Mode.UNDEFINED)
self.assertEqual(len(config.get_pre_commit_script_names()), 0)
def test_get_mode_undefined(self):
config = AutohooksConfig({'tool': {'autohooks': {'mode': None}}})
self.assertTrue(config.has_config())
self.assertTrue(config.has_autohooks_config())
self.assertTrue(config.is_autohooks_enabled())
self.assertEqual(config.get_mode(), Mode.UNDEFINED)
self.assertEqual(len(config.get_pre_commit_script_names()), 0)
def test_empty_config(self):
config = AutohooksConfig()
self.assertFalse(config.has_config())
self.assertFalse(config.has_autohooks_config())
self.assertFalse(config.is_autohooks_enabled())
self.assertEqual(config.get_mode(), Mode.UNDEFINED)
self.assertEqual(len(config.get_pre_commit_script_names()), 0)
def test_get_config_dict(self):
config_in = {'tool': {'autohooks': {'lorem': 'ipsum'}}, 'foo': 'bar'}
config = AutohooksConfig(config_in)
self.assertTrue(config.has_config())
self.assertTrue(config.has_autohooks_config())
self.assertEqual(config.get_mode(), Mode.UNDEFINED)
config_out = config.get_config()
self.assertEqual(config_out.get_value('foo'), 'bar')
def from_pyproject_toml(pyproject_toml: Path = None) -> "AutohooksConfig":
if pyproject_toml is None:
pyproject_toml = get_pyproject_toml_path()
if not pyproject_toml.exists():
return AutohooksConfig()
config_dict = tomlkit.loads(pyproject_toml.read_text())
return AutohooksConfig(config_dict)
def from_pyproject_toml(pyproject_toml: Path = None) -> "AutohooksConfig":
if pyproject_toml is None:
pyproject_toml = get_pyproject_toml_path()
if not pyproject_toml.exists():
return AutohooksConfig()
config_dict = tomlkit.loads(pyproject_toml.read_text())
return AutohooksConfig(config_dict)
def load_config_from_pyproject_toml(
pyproject_toml: Path = None,
) -> AutohooksConfig:
return AutohooksConfig.from_pyproject_toml(pyproject_toml)