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

Merge branch '70-publish-destination-directory' into 'main'

Resolve "Publish destination directory"

Closes #70

See merge request !28
parents 91914435 e2b779f6
No related branches found
No related tags found
1 merge request!28Resolve "Publish destination directory"
Pipeline #824223 passed with warnings
......@@ -46,6 +46,6 @@ FIGS_AND_IDS = tagplot(FIGS_AS_LIST, 'matplotlib', location='west',
# %% Publish
publish(FIGS_AND_IDS, ['../README.md', '../docs', '../LICENSE'],
'./data', 'my_plot')
'data', 'my_plot')
# Required arguments: publish(output of tagplot(), list of files,
# path to destination folder, name(s) for the resulting images)
......@@ -42,18 +42,11 @@ class PublishOptions:
self.figure = figs_and_ids.figs
self.figure_ids = figs_and_ids.figure_ids
self.src_datapaths = src_datapaths
self.dst_path = dst_path
self.dst_path = os.path.abspath(dst_path)
self.plot_names = plot_names
self.data_storage = kwargs.get('data_storage', 'individual')
self.dst_path_head, self.dst_dirname = os.path.split(self.dst_path)
# If the second string after os.path.split is empty,
# a trailing slash was given.
# To get the dir name correctly, split the first string again.
if not self.dst_dirname:
self.dst_path_head, self.dst_dirname = os.path.split(
self.dst_path_head)
def __str__(self):
"""Representation if an object of this class is printed."""
return str(self.__class__) + ": " + str(self.__dict__)
......@@ -109,7 +102,7 @@ class PublishOptions:
# Check if destination directory is allowed path
if not os.path.exists(self.dst_path_head):
raise FileNotFoundError('The specified destination directory '
'does not exist.')
f'{self.dst_path_head} does not exist.')
# Check if plot_name is a string or a list of strings
if isinstance(self.plot_names, str):
......
......@@ -110,9 +110,13 @@ class TestPublish(unittest.TestCase):
publish(FIGS_AND_IDS, 4, DST_PATH, PIC_NAME)
def test_dst_directory(self):
""" Test if Error is raised when destination dir does not exist."""
"""
Test if Error is raised when the directory above the
destination dir does not exist.
"""
with self.assertRaises(FileNotFoundError):
publish(FIGS_AND_IDS, SRC_DIR, 'not_existing_folder', PIC_NAME)
publish(FIGS_AND_IDS, SRC_DIR, 'not_existing_folder/data',
PIC_NAME)
def test_script_exists(self):
"""
......@@ -251,16 +255,13 @@ class TestPublish(unittest.TestCase):
"""
self.maxDiff = None
publish_obj = PublishOptions(FIGS_AND_IDS, SRC_DIR, DST_PATH, PIC_NAME)
self.assertEqual(str(publish_obj),
self.assertIn(
"<class 'plotid.publish.PublishOptions'>: {'figure': "
"[<Figure size 640x480 with 0 Axes>, <Figure size"
" 640x480 with 0 Axes>], 'figure_ids': "
"['MR05_0x63203c6f', 'MR05_0x63203c70'], "
"'src_datapaths': 'test_src_folder', 'dst_path': "
"'test_parent/test_dst_folder', 'plot_names': "
"'test_picture', 'data_storage': 'individual', "
"'dst_path_head': 'test_parent', 'dst_dirname': "
"'test_dst_folder'}")
"'src_datapaths': 'test_src_folder'",
str(publish_obj))
def tearDown(self):
""" Delete all files created in setUp. """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment