|
5 | 5 | import logging |
6 | 6 | import os |
7 | 7 | import os.path |
| 8 | +import re |
8 | 9 | import shutil |
9 | 10 |
|
10 | 11 | import mock |
| 12 | +import pkg_resources |
11 | 13 | import pytest |
12 | 14 |
|
13 | 15 | from pre_commit import five |
|
24 | 26 | from testing.fixtures import git_dir |
25 | 27 | from testing.fixtures import make_config_from_repo |
26 | 28 | from testing.fixtures import make_repo |
| 29 | +from testing.fixtures import modify_manifest |
27 | 30 | from testing.util import skipif_slowtests_false |
28 | 31 | from testing.util import xfailif_no_pcre_support |
29 | 32 | from testing.util import xfailif_windows_no_node |
@@ -525,3 +528,33 @@ def test_hook_id_not_present(tempdir_factory, store, fake_log_handler): |
525 | 528 | 'Typo? Perhaps it is introduced in a newer version? ' |
526 | 529 | 'Often `pre-commit autoupdate` fixes this.'.format(path) |
527 | 530 | ) |
| 531 | + |
| 532 | + |
| 533 | +def test_too_new_version(tempdir_factory, store, fake_log_handler): |
| 534 | + path = make_repo(tempdir_factory, 'script_hooks_repo') |
| 535 | + with modify_manifest(path) as manifest: |
| 536 | + manifest[0]['minimum_pre_commit_version'] = '999.0.0' |
| 537 | + config = make_config_from_repo(path) |
| 538 | + repo = Repository.create(config, store) |
| 539 | + with pytest.raises(SystemExit): |
| 540 | + repo.install() |
| 541 | + msg = fake_log_handler.handle.call_args[0][0].msg |
| 542 | + assert re.match( |
| 543 | + r'^The hook `bash_hook` requires pre-commit version 999\.0\.0 but ' |
| 544 | + r'version \d+\.\d+\.\d+ is installed. ' |
| 545 | + r'Perhaps run `pip install --upgrade pre-commit`\.$', |
| 546 | + msg, |
| 547 | + ) |
| 548 | + |
| 549 | + |
| 550 | +@pytest.mark.parametrize( |
| 551 | + 'version', |
| 552 | + ('0.1.0', pkg_resources.get_distribution('pre-commit').version), |
| 553 | +) |
| 554 | +def test_versions_ok(tempdir_factory, store, version): |
| 555 | + path = make_repo(tempdir_factory, 'script_hooks_repo') |
| 556 | + with modify_manifest(path) as manifest: |
| 557 | + manifest[0]['minimum_pre_commit_version'] = version |
| 558 | + config = make_config_from_repo(path) |
| 559 | + # Should succeed |
| 560 | + Repository.create(config, store).install() |
0 commit comments