From 984c4d21f8c7a74ce44c3c0b832859ac7de12e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 22 Jul 2024 10:58:55 +0200 Subject: [PATCH] Allow running blurb test from blurb-* directories Fixes https://github.com/python/blurb/issues/21 --- src/blurb/blurb.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/blurb/blurb.py b/src/blurb/blurb.py index 4930bb4..d54a950 100755 --- a/src/blurb/blurb.py +++ b/src/blurb/blurb.py @@ -642,7 +642,7 @@ def save_next(self): tests_run = 0 class TestParserPasses(unittest.TestCase): - directory = "blurb/tests/pass" + directory = "tests/pass" def filename_test(self, filename): b = Blurbs() @@ -667,7 +667,7 @@ def test_files(self): class TestParserFailures(TestParserPasses): - directory = "blurb/tests/fail" + directory = "tests/fail" def filename_test(self, filename): b = Blurbs() @@ -820,6 +820,15 @@ def help(subcommand=None): subcommands["--help"] = help +def _find_blurb_dir(): + if os.path.isdir("blurb"): + return "blurb" + for path in glob.iglob("blurb-*"): + if os.path.isdir(path): + return path + return None + + @subcommand def test(*args): """ @@ -828,12 +837,13 @@ def test(*args): # unittest.main doesn't work because this isn't a module # so we'll do it ourselves - while not os.path.isdir("blurb"): + while (blurb_dir := _find_blurb_dir()) is None: old_dir = os.getcwd() os.chdir("..") if old_dir == os.getcwd(): # we reached the root and never found it! sys.exit("Error: Couldn't find the root of your blurb repo!") + os.chdir(blurb_dir) print("-" * 79)