|
57 | 57 | import tempfile |
58 | 58 | import textwrap |
59 | 59 | import time |
60 | | -import unittest |
61 | 60 |
|
62 | 61 | from . import __version__ |
63 | 62 |
|
@@ -143,7 +142,6 @@ def unsanitize_section(section): |
143 | 142 | return _unsanitize_section.get(section, section) |
144 | 143 |
|
145 | 144 | def next_filename_unsanitize_sections(filename): |
146 | | - s = filename |
147 | 145 | for key, value in _unsanitize_section.items(): |
148 | 146 | for separator in "/\\": |
149 | 147 | key = f"{separator}{key}{separator}" |
@@ -271,11 +269,6 @@ def __exit__(self, *args): |
271 | 269 | os.chdir(self.previous_cwd) |
272 | 270 |
|
273 | 271 |
|
274 | | -def safe_mkdir(path): |
275 | | - if not os.path.exists(path): |
276 | | - os.makedirs(path) |
277 | | - |
278 | | - |
279 | 272 | def version_key(element): |
280 | 273 | fields = list(element.split(".")) |
281 | 274 | if len(fields) == 1: |
@@ -485,22 +478,25 @@ def finish_entry(): |
485 | 478 | # we'll complain about the *first* error |
486 | 479 | # we see in the blurb file, which is a |
487 | 480 | # better user experience. |
488 | | - if key == "gh-issue" and int(value) < lowest_possible_gh_issue_number: |
489 | | - throw(f"The gh-issue number must be {lowest_possible_gh_issue_number} or above, not a PR number.") |
490 | | - |
491 | 481 | if key in issue_keys: |
492 | 482 | try: |
493 | 483 | int(value) |
494 | 484 | except (TypeError, ValueError): |
495 | | - throw(f"Invalid {issue_keys[key]} issue number! ({value!r})") |
| 485 | + throw(f"Invalid {issue_keys[key]} number: {value!r}") |
| 486 | + |
| 487 | + if key == "gh-issue" and int(value) < lowest_possible_gh_issue_number: |
| 488 | + throw(f"Invalid gh-issue number: {value!r} (must be >= {lowest_possible_gh_issue_number})") |
496 | 489 |
|
497 | 490 | if key == "section": |
498 | 491 | if no_changes: |
499 | 492 | continue |
500 | 493 | if value not in sections: |
501 | 494 | throw(f"Invalid section {value!r}! You must use one of the predefined sections.") |
502 | 495 |
|
503 | | - if not 'section' in metadata: |
| 496 | + if "gh-issue" not in metadata and "bpo" not in metadata: |
| 497 | + throw("'gh-issue:' or 'bpo:' must be specified in the metadata!") |
| 498 | + |
| 499 | + if 'section' not in metadata: |
504 | 500 | throw("No 'section' specified. You must provide one!") |
505 | 501 |
|
506 | 502 | self.append((metadata, text)) |
@@ -560,7 +556,7 @@ def __str__(self): |
560 | 556 |
|
561 | 557 | def save(self, path): |
562 | 558 | dirname = os.path.dirname(path) |
563 | | - safe_mkdir(dirname) |
| 559 | + os.makedirs(dirname, exist_ok=True) |
564 | 560 |
|
565 | 561 | text = str(self) |
566 | 562 | with open(path, "wt", encoding="utf-8") as file: |
@@ -642,42 +638,6 @@ def save_next(self): |
642 | 638 | return filename |
643 | 639 |
|
644 | 640 |
|
645 | | -tests_run = 0 |
646 | | - |
647 | | -class TestParserPasses(unittest.TestCase): |
648 | | - directory = "tests/pass" |
649 | | - |
650 | | - def filename_test(self, filename): |
651 | | - b = Blurbs() |
652 | | - b.load(filename) |
653 | | - self.assertTrue(b) |
654 | | - if os.path.exists(filename + '.res'): |
655 | | - with open(filename + '.res', encoding='utf-8') as file: |
656 | | - expected = file.read() |
657 | | - self.assertEqual(str(b), expected) |
658 | | - |
659 | | - def test_files(self): |
660 | | - global tests_run |
661 | | - with pushd(self.directory): |
662 | | - for filename in glob.glob("*"): |
663 | | - if filename[-4:] == '.res': |
664 | | - self.assertTrue(os.path.exists(filename[:-4]), filename) |
665 | | - continue |
666 | | - self.filename_test(filename) |
667 | | - print(".", end="") |
668 | | - sys.stdout.flush() |
669 | | - tests_run += 1 |
670 | | - |
671 | | - |
672 | | -class TestParserFailures(TestParserPasses): |
673 | | - directory = "tests/fail" |
674 | | - |
675 | | - def filename_test(self, filename): |
676 | | - b = Blurbs() |
677 | | - with self.assertRaises(Exception): |
678 | | - b.load(filename) |
679 | | - |
680 | | - |
681 | 641 | readme_re = re.compile(r"This is \w+ version \d+\.\d+").match |
682 | 642 |
|
683 | 643 | def chdir_to_repo_root(): |
@@ -848,36 +808,6 @@ def _find_blurb_dir(): |
848 | 808 | return None |
849 | 809 |
|
850 | 810 |
|
851 | | -@subcommand |
852 | | -def test(*args): |
853 | | - """ |
854 | | -Run unit tests. Only works inside source repo, not when installed. |
855 | | - """ |
856 | | - # unittest.main doesn't work because this isn't a module |
857 | | - # so we'll do it ourselves |
858 | | - |
859 | | - while (blurb_dir := _find_blurb_dir()) is None: |
860 | | - old_dir = os.getcwd() |
861 | | - os.chdir("..") |
862 | | - if old_dir == os.getcwd(): |
863 | | - # we reached the root and never found it! |
864 | | - sys.exit("Error: Couldn't find the root of your blurb repo!") |
865 | | - os.chdir(blurb_dir) |
866 | | - |
867 | | - print("-" * 79) |
868 | | - |
869 | | - for clsname, cls in sorted(globals().items()): |
870 | | - if clsname.startswith("Test") and isinstance(cls, type): |
871 | | - o = cls() |
872 | | - for fnname in sorted(dir(o)): |
873 | | - if fnname.startswith("test"): |
874 | | - fn = getattr(o, fnname) |
875 | | - if callable(fn): |
876 | | - fn() |
877 | | - print() |
878 | | - print(tests_run, "tests passed.") |
879 | | - |
880 | | - |
881 | 811 | def find_editor(): |
882 | 812 | for var in 'GIT_EDITOR', 'EDITOR': |
883 | 813 | editor = os.environ.get(var) |
@@ -1349,12 +1279,12 @@ def populate(): |
1349 | 1279 | Creates and populates the Misc/NEWS.d directory tree. |
1350 | 1280 | """ |
1351 | 1281 | os.chdir("Misc") |
1352 | | - safe_mkdir("NEWS.d/next") |
| 1282 | + os.makedirs("NEWS.d/next", exist_ok=True) |
1353 | 1283 |
|
1354 | 1284 | for section in sections: |
1355 | 1285 | dir_name = sanitize_section(section) |
1356 | 1286 | dir_path = f"NEWS.d/next/{dir_name}" |
1357 | | - safe_mkdir(dir_path) |
| 1287 | + os.makedirs(dir_path, exist_ok=True) |
1358 | 1288 | readme_path = f"NEWS.d/next/{dir_name}/README.rst" |
1359 | 1289 | with open(readme_path, "wt", encoding="utf-8") as readme: |
1360 | 1290 | readme.write(f"Put news entry ``blurb`` files for the *{section}* section in this directory.\n") |
@@ -1398,7 +1328,7 @@ def main(): |
1398 | 1328 | fn = get_subcommand(subcommand) |
1399 | 1329 |
|
1400 | 1330 | # hack |
1401 | | - if fn in (help, test, version): |
| 1331 | + if fn in (help, version): |
1402 | 1332 | sys.exit(fn(*args)) |
1403 | 1333 |
|
1404 | 1334 | try: |
|
0 commit comments