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_get_effective_mode(self):
self.assertEqual(Mode.PIPENV.get_effective_mode(), Mode.PIPENV)
self.assertEqual(Mode.PYTHONPATH.get_effective_mode(), Mode.PYTHONPATH)
self.assertEqual(Mode.POETRY.get_effective_mode(), Mode.POETRY)
self.assertEqual(Mode.UNDEFINED.get_effective_mode(), Mode.PYTHONPATH)
self.assertEqual(Mode.UNKNOWN.get_effective_mode(), Mode.PYTHONPATH)
def test_get_invalid_mode_from_string(self):
self.assertEqual(Mode.from_string('foo'), Mode.UNKNOWN)
self.assertEqual(Mode.from_string(None), Mode.UNDEFINED)
self.assertEqual(Mode.from_string(''), Mode.UNDEFINED)
def read_mode(self) -> Mode:
lines = self.pre_commit_hook.split('\n')
if len(lines) < 1 or len(lines[0]) == 0:
return Mode.UNDEFINED
shebang = lines[0][2:]
if shebang == PYTHON3_SHEBANG:
return Mode.PYTHONPATH
if shebang == POETRY_SHEBANG:
return Mode.POETRY
if shebang == PIPENV_SHEBANG:
return Mode.PIPENV
return Mode.UNKNOWN
def from_string(modestring: str) -> 'Mode':
if not modestring:
return Mode.UNDEFINED
try:
return Mode[modestring.upper()]
except KeyError:
return Mode.UNKNOWN
def get_mode(self) -> Mode:
if self.has_autohooks_config():
mode = self._autohooks_config.get_value('mode')
if not mode:
return Mode.UNDEFINED
try:
return Mode[mode.upper()]
except KeyError:
return Mode.UNKNOWN
return Mode.UNDEFINED
term.error(
'Missing {} file. Please add a pyproject.toml file and include '
'a "{}" section.'.format(str(pyproject_toml), AUTOHOOKS_SECTION)
)
else:
config = load_config_from_pyproject_toml(pyproject_toml)
if not config.is_autohooks_enabled():
term.error(
'autohooks is not enabled in your {} file. Please add '
'a "{}" section.'.format(str(pyproject_toml), AUTOHOOKS_SECTION)
)
elif pre_commit_hook.exists():
config_mode = config.get_mode()
hook_mode = pre_commit_hook.read_mode()
if config_mode == Mode.UNDEFINED:
term.warning(
'autohooks mode is not defined in {}.'.format(
str(pyproject_toml)
)
)
elif config_mode == Mode.UNKNOWN:
term.warning(
'Unknown autohooks mode in {}.'.format(str(pyproject_toml))
)
if (
config_mode.get_effective_mode()
!= hook_mode.get_effective_mode()
):
term.warning(
'autohooks mode "{}" in pre-commit hook {} differs from '
def get_mode(self) -> Mode:
if self.has_autohooks_config():
mode = self._autohooks_config.get_value('mode')
if not mode:
return Mode.UNDEFINED
try:
return Mode[mode.upper()]
except KeyError:
return Mode.UNKNOWN
return Mode.UNDEFINED