Skip to content

Commit f4d8ae4

Browse files
xelanderntpeterjc
authored andcommitted
Correctly clean up files generated by the Phylo tutorial.
1 parent f0973f6 commit f4d8ae4

2 files changed

Lines changed: 20 additions & 25 deletions

File tree

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ Tests/Cluster/cyano_result*
6363
# Created by Tests/test_BWA_tool.py:
6464
Tests/out.bam
6565

66-
#TODO - The Tutorial doctests should leave example files after
67-
#running Tests/test_Tutorial.py
68-
Doc/examples/other_trees.nwk
69-
Doc/examples/tree1.nwk
70-
7166
#Ignore LaTeX temp files, and compiled output
7267
Doc/*.aux
7368
Doc/*.gz

Tests/test_Tutorial.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -263,21 +263,29 @@ def test_doctests(self):
263263
name = test.name
264264
assert name.startswith("TutorialDocTestHolder.doctest_")
265265
failures.append(name[30:])
266-
# raise ValueError("Tutorial doctest %s failed" % test.name[30:])
267266
if failures:
268267
raise ValueError(
269268
"%i Tutorial doctests failed: %s" % (len(failures), ", ".join(failures))
270269
)
271270

272271
def tearDown(self):
273-
os.chdir(original_path)
274-
# files currently don't get created during test with python3.5 and pypy
275-
# remove files created from chapter_phylo.tex
276-
delete_phylo_tutorial = ["examples/tree1.nwk", "examples/other_trees.xml"]
272+
# make sure we are in the tutorial base directory
273+
os.chdir(tutorial_base)
274+
275+
# clean up files created in chapter_phylo.rst
276+
tutorial_phylo_base = os.path.abspath("..")
277+
278+
delete_phylo_tutorial = [
279+
"tree1.nwk",
280+
"tree1.xml",
281+
"other_trees.xml",
282+
"other_trees.nex",
283+
]
284+
277285
for file in delete_phylo_tutorial:
278-
if os.path.exists(os.path.join(tutorial_base, file)):
279-
os.remove(os.path.join(tutorial_base, file))
280-
# remove files created from chapter_cluster.tex
286+
if os.path.exists(os.path.join(tutorial_phylo_base, file)):
287+
os.remove(os.path.join(tutorial_phylo_base, file))
288+
# clean up files created in chapter_cluster.rst
281289
tutorial_cluster_base = os.path.abspath("../Tests/")
282290
delete_cluster_tutorial = [
283291
"Cluster/cyano_result.atr",
@@ -290,19 +298,11 @@ def tearDown(self):
290298
for file in delete_cluster_tutorial:
291299
if os.path.exists(os.path.join(tutorial_cluster_base, file)):
292300
os.remove(os.path.join(tutorial_cluster_base, file))
301+
# reset back to the original directory
302+
os.chdir(original_path)
293303

294304

295305
# This is to run the doctests if the script is called directly:
296306
if __name__ == "__main__":
297-
if missing_deps:
298-
print("Skipping tests needing the following:")
299-
for dep in sorted(missing_deps):
300-
print(f" - {dep}")
301-
print("Running Tutorial doctests...")
302-
with warnings.catch_warnings():
303-
warnings.simplefilter("ignore", BiopythonDeprecationWarning)
304-
warnings.simplefilter("ignore", BiopythonExperimentalWarning)
305-
tests = doctest.testmod(optionflags=doctest.ELLIPSIS)
306-
if tests.failed:
307-
raise RuntimeError("%i/%i tests failed" % tests)
308-
print("Tests done")
307+
runner = unittest.TextTestRunner(verbosity=2)
308+
unittest.main(testRunner=runner)

0 commit comments

Comments
 (0)