From 9aaf14573ad7a73008e6ced9179f2662a8fd9b5a Mon Sep 17 00:00:00 2001 From: "Mayr, Hannes" <hannes.mayr@stud.tu-darmstadt.de> Date: Thu, 24 Nov 2022 11:25:06 +0100 Subject: [PATCH] Skip unit tests that don't work if tests are run from command line. --- plotid/publish.py | 5 ++--- tests/test_publish.py | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/plotid/publish.py b/plotid/publish.py index 8912a2a..a6034ab 100644 --- a/plotid/publish.py +++ b/plotid/publish.py @@ -74,9 +74,8 @@ class PublishOptions: if not os.path.isfile(sys.argv[0]): raise FileNotFoundError( - "Cannot copy original python script. " - "Running publish from a shell is not " - "possible." + "Cannot copy original python script. Running publish from a shell is " + "not possible." ) # Check if self.src_datapaths are strings and existing files. diff --git a/tests/test_publish.py b/tests/test_publish.py index f279f7f..1f779de 100644 --- a/tests/test_publish.py +++ b/tests/test_publish.py @@ -45,8 +45,7 @@ class TestPublish(unittest.TestCase): # Skip test if tests are run from command line. @unittest.skipIf( not os.path.isfile(sys.argv[0]), - "Publish is not called " - "from a Python script. Therefore, the script cannot be " + "Publish is not called from a Python script. Therefore, the script cannot be " "copied.", ) def test_publish(self): @@ -112,6 +111,12 @@ class TestPublish(unittest.TestCase): with self.assertRaises(TypeError): publish(PlotIDTransfer(FIG, ["i", 4]), SRC_DIR, DST_PATH) + # Skip test if tests are run from command line. + @unittest.skipIf( + not os.path.isfile(sys.argv[0]), + "Publish is not called from a Python script. Therefore, the script cannot be " + "copied.", + ) def test_publish_multiple_src_files(self): """ Test publish with multiple source files and check @@ -137,6 +142,12 @@ class TestPublish(unittest.TestCase): with self.assertRaises(FileNotFoundError): publish(FIGS_AND_IDS, "not_existing_folder", DST_PATH) + # Skip test if tests are run from command line. + @unittest.skipIf( + not os.path.isfile(sys.argv[0]), + "Publish is not called from a Python script. Therefore, the script cannot be " + "copied.", + ) def test_src_directory_type(self): """Test if Error is raised when source directory is not a string.""" with self.assertRaises(TypeError): @@ -260,8 +271,7 @@ class TestPublish(unittest.TestCase): # Skip test if tests are run from command line. @unittest.skipIf( not os.path.isfile(sys.argv[0]), - "Publish is not called " - "from a Python script. Therefore, the script cannot be " + "Publish is not called from a Python script. Therefore, the script cannot be " "copied.", ) def test_dst_invisible_already_exists(self): @@ -290,6 +300,12 @@ class TestPublish(unittest.TestCase): with self.assertRaises(TypeError): publish(FIGS_AND_IDS, SRC_DIR, DST_PATH, ["test", 3]) + # Skip test if tests are run from command line. + @unittest.skipIf( + not os.path.isfile(sys.argv[0]), + "Publish is not called from a Python script. Therefore, the script cannot be " + "copied.", + ) def test_data_storage(self): """ Test if Error is raised when unsupported storage method was chosen. -- GitLab