From 77733e03f9910d9cd8d2d426796d4007d11b5651 Mon Sep 17 00:00:00 2001 From: koaning Date: Tue, 31 Jul 2018 15:50:10 +0200 Subject: [PATCH] tests now have setup and teardown --- asekuro/commandline.py | 2 ++ tests/test_commandline.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/asekuro/commandline.py b/asekuro/commandline.py index 418bb5e..907d1b7 100644 --- a/asekuro/commandline.py +++ b/asekuro/commandline.py @@ -24,6 +24,8 @@ def _cwd(nbpath): logger.debug(f"directory of script calling {os.getcwd()}") folder = os.path.dirname(nbpath) filename = os.path.basename(nbpath) + if folder == "": + folder = os.getcwd() os.chdir(folder) logger.debug(f"directory for rest of script {os.getcwd()}") return folder, filename diff --git a/tests/test_commandline.py b/tests/test_commandline.py index 16691cf..51f6bc6 100644 --- a/tests/test_commandline.py +++ b/tests/test_commandline.py @@ -1,7 +1,35 @@ +import os import subprocess +from asekuro.commandline import _testfile -class TestCommandLine: +class TestPathHandlingLocal: + + @classmethod + def setup_class(cls): + os.chdir("tests") + + @classmethod + def teardown_class(cls): + os.chdir("..") + + def test_tempfile_creation(self): + assert _testfile("foobar.ipynb") == "foobar-test.ipynb" + + def test_good_nb(self): + status = subprocess.call(['asekuro', 'test', 'good-nb.ipynb']) + assert status == 0 + + def test_data_nb(self): + status = subprocess.call(['asekuro', 'test', 'data-nb.ipynb']) + assert status == 0 + + def test_bad_bn(self): + status = subprocess.call(['asekuro', 'test', 'bad-nb.ipynb']) + assert status == 2 + + +class TestCommandLineOuter: def test_good_nb(self): status = subprocess.call(['asekuro', 'test', 'tests/good-nb.ipynb'])