def test_read_version(self): template = PreCommitTemplate() with tempfile.TemporaryDirectory() as tempdir: tmp_hook_path = Path(tempdir) / 'pre-commit-test' # Find version using all shebang modes for mode in [m for m in Mode if m.value > 0]: with open(str(tmp_hook_path), 'w', encoding='utf-8') as tmpfile: tmpfile.write(template.render(mode=mode)) pre_commit_hook = PreCommitHook(tmp_hook_path) self.assertEqual(TEMPLATE_VERSION, pre_commit_hook.read_version())
def test_no_meta(self): path = FakeReadPath("\n# foo = bar") pre_commit_hook = PreCommitHook(path) self.assertEqual(pre_commit_hook.read_version(), -1)
def test_no_toml(self): path = FakeReadPath("\n# \n") pre_commit_hook = PreCommitHook(path) self.assertEqual(pre_commit_hook.read_version(), -1)
def test_empty_content(self): path = FakeReadPath("") pre_commit_hook = PreCommitHook(path) self.assertEqual(pre_commit_hook.read_version(), -1)
def test_read_version(self): path = FakeReadPath("\n# meta = {version=123}") pre_commit_hook = PreCommitHook(path) self.assertEqual(pre_commit_hook.read_version(), 123)