Skip to content
Snippets Groups Projects
Commit 34ee81df authored by Mayr, Hannes's avatar Mayr, Hannes
Browse files

Unittest for crashing publish and the cleanup of the partially copied data.

parent 38e88971
No related branches found
No related tags found
1 merge request!19merge dev for new release v.0.1.2
Pipeline #783605 passed
...@@ -57,4 +57,4 @@ IMGS_AS_LIST = [IMG1, IMG2] ...@@ -57,4 +57,4 @@ IMGS_AS_LIST = [IMG1, IMG2]
publish(['../README.md', '../docs', '../LICENSE'], publish(['../README.md', '../docs', '../LICENSE'],
'/home/chief/Dokumente/fst/plotid_python/data', '/home/chief/Dokumente/fst/plotid_python/data',
TAGGED_FIGS, 'Bild4') TAGGED_FIGS, 'Bild')
...@@ -164,7 +164,8 @@ class PublishOptions: ...@@ -164,7 +164,8 @@ class PublishOptions:
' removed? (yes/no[default])\n') ' removed? (yes/no[default])\n')
if delete_dir in ('yes', 'y'): if delete_dir in ('yes', 'y'):
shutil.rmtree(dst_path_invisible) shutil.rmtree(dst_path_invisible)
raise RuntimeError('Publishing was unsuccessful.') from exc raise RuntimeError('Publishing was unsuccessful. '
'Try re-running publish.') from exc
case _: case _:
raise ValueError(f'The data storage method {self.data_storage}' raise ValueError(f'The data storage method {self.data_storage}'
' is not available.') ' is not available.')
......
...@@ -175,13 +175,18 @@ class TestPublish(unittest.TestCase): ...@@ -175,13 +175,18 @@ class TestPublish(unittest.TestCase):
@unittest.skipIf(not os.path.isfile(sys.argv[0]), 'Publish is not called ' @unittest.skipIf(not os.path.isfile(sys.argv[0]), 'Publish is not called '
'from a Python script. Therefore, the script cannot be ' 'from a Python script. Therefore, the script cannot be '
'copied.') 'copied.')
def test_dst__invisible_already_exists(self): def test_dst_invisible_already_exists(self):
""" """
Test if publish succeeds when there is already an invisible Test if after a crash of publish the partially copied data is
directory from a previous run (delete the folder and proceed). removed.
To mock this, the invisible directory already exists.
""" """
os.mkdir(INVISIBLE_PATH) os.mkdir(INVISIBLE_PATH)
# Mock user input as 'yes'
with patch('builtins.input', return_value='yes'):
with self.assertRaises(RuntimeError):
publish(SRC_DIR, DST_PATH, FIG, PIC_NAME, 'individual') publish(SRC_DIR, DST_PATH, FIG, PIC_NAME, 'individual')
assert not os.path.isdir(INVISIBLE_PATH)
def test_plot_names(self): def test_plot_names(self):
""" Test if Error is raised if plot_name is not a string. """ """ Test if Error is raised if plot_name is not a string. """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment