8000 Move 'blurb test' subcommand into test suite · python/blurb@bf284ae · GitHub
[go: up one dir, main page]

Skip to content

Commit bf284ae

Browse files
committed
Move 'blurb test' subcommand into test suite
1 parent 2a19feb commit bf284ae

File tree

4 files changed

+37
-70
lines changed

4 files changed

+37
-70
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ exclude_also =
1010
[run]
1111
omit =
1212
**/blurb/__main__.py
13+
**/blurb/_version.py

src/blurb/blurb.py

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import tempfile
5858
import textwrap
5959
import time
60-
import unittest
6160

6261
from . import __version__
6362

@@ -639,42 +638,6 @@ def save_next(self):
639638
return filename
640639

641640

642-
tests_run = 0
643-
644-
class TestParserPasses(unittest.TestCase):
645-
directory = "tests/pass"
646-
647-
def filename_test(self, filename):
648-
b = Blurbs()
649-
b.load(filename)
650-
self.assertTrue(b)
651-
if os.path.exists(filename + '.res'):
652-
with open(filename + '.res', encoding='utf-8') as file:
653-
expected = file.read()
654-
self.assertEqual(str(b), expected)
655-
656-
def test_files(self):
657-
global tests_run
658-
with pushd(self.directory):
659-
for filename in glob.glob("*"):
660-
if filename[-4:] == '.res':
661-
self.assertTrue(os.path.exists(filename[:-4]), filename)
662-
continue
663-
self.filename_test(filename)
664-
print(".", end="")
665-
sys.stdout.flush()
666-
tests_run += 1
667-
668-
669-
class TestParserFailures(TestParserPasses):
670-
directory = "tests/fail"
671-
672-
def filename_test(self, filename):
673-
b = Blurbs()
674-
with self.assertRaises(Exception):
675-
b.load(filename)
676-
677-
678641
readme_re = re.compile(r"This is \w+ version \d+\.\d+").match
679642

680643
def chdir_to_repo_root():
@@ -838,36 +801,6 @@ def _find_blurb_dir():
838801
return None
839802

840803

841-
@subcommand
842-
def test(*args):
843-
"""
844-
Run unit tests. Only works inside source repo, not when installed.
845-
"""
846-
# unittest.main doesn't work because this isn't a module
847-
# so we'll do it ourselves
848-
849-
while (blurb_dir := _find_blurb_dir()) is None:
850-
old_dir = os.getcwd()
851-
os.chdir("..")
852-
if old_dir == os.getcwd():
853-
# we reached the root and never found it!
854-
sys.exit("Error: Couldn't find the root of your blurb repo!")
855-
os.chdir(blurb_dir)
856-
857-
print("-" * 79)
858-
859-
for clsname, cls in sorted(globals().items()):
860-
if clsname.startswith("Test") and isinstance(cls, type):
861-
o = cls()
862-
for fnname in sorted(dir(o)):
863-
if fnname.startswith("test"):
864-
fn = getattr(o, fnname)
865-
if callable(fn):
866-
fn()
867-
print()
868-
print(tests_run, "tests passed.")
869-
870-
871804
def find_editor():
872805
for var in 'GIT_EDITOR', 'EDITOR':
873806
editor = os.environ.get(var)
@@ -1224,7 +1157,7 @@ def main():
12241157
fn = get_subcommand(subcommand)
12251158

12261159
# hack
1227-
if fn in (help, test, version):
1160+
if fn in (help, version):
12281161
sys.exit(fn(*args))
12291162

12301163
try:

tests/test_parser.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import glob
2+
import os
3+
import unittest
4+
5+
from blurb.blurb import Blurbs, pushd
6+
7+
8+
class TestParserPasses(unittest.TestCase):
9+
directory = "tests/pass"
10+
11+
def filename_test(self, filename):
12+
b = Blurbs()
13+
b.load(filename)
14+
self.assertTrue(b)
15+
if os.path.exists(filename + ".res"):
16+
with open(filename + ".res", encoding="utf-8") as file:
17+
expected = file.read()
18+
self.assertEqual(str(b), expected)
19+
20+
def test_files(self):
21+
with pushd(self.directory):
22+
for filename in glob.glob("*"):
23+
if filename[-4:] == ".res":
24+
self.assertTrue(os.path.exists(filename[:-4]), filename)
25+
continue
26+
self.filename_test(filename)
27+
28+
29+
class TestParserFailures(TestParserPasses):
30+
directory = "tests/fail"
31+
32+
def filename_test(self, filename):
33+
b = Blurbs()
34+
with self.assertRaises(Exception):
35+
b.load(filename)

tox.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ commands =
1717
--cov-report term \
1818
--cov-report xml \
1919
{posargs}
20-
blurb test
2120
blurb help
2221
blurb --version
23-
{envpython} -I -m blurb test
2422
{envpython} -I -m blurb help
2523
{envpython} -I -m blurb version

0 commit comments

Comments
 (0)
0