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

Resolve "Publish destination directory"

parent f8f75816
No related branches found
No related tags found
1 merge request!28Resolve "Publish destination directory"
...@@ -46,6 +46,6 @@ FIGS_AND_IDS = tagplot(FIGS_AS_LIST, 'matplotlib', location='west', ...@@ -46,6 +46,6 @@ FIGS_AND_IDS = tagplot(FIGS_AS_LIST, 'matplotlib', location='west',
# %% Publish # %% Publish
publish(FIGS_AND_IDS, ['../README.md', '../docs', '../LICENSE'], publish(FIGS_AND_IDS, ['../README.md', '../docs', '../LICENSE'],
'./data', 'my_plot') 'data', 'my_plot')
# Required arguments: publish(output of tagplot(), list of files, # Required arguments: publish(output of tagplot(), list of files,
# path to destination folder, name(s) for the resulting images) # path to destination folder, name(s) for the resulting images)
...@@ -42,18 +42,11 @@ class PublishOptions: ...@@ -42,18 +42,11 @@ class PublishOptions:
self.figure = figs_and_ids.figs self.figure = figs_and_ids.figs
self.figure_ids = figs_and_ids.figure_ids self.figure_ids = figs_and_ids.figure_ids
self.src_datapaths = src_datapaths self.src_datapaths = src_datapaths
self.dst_path = dst_path self.dst_path = os.path.abspath(dst_path)
self.plot_names = plot_names self.plot_names = plot_names
self.data_storage = kwargs.get('data_storage', 'individual') self.data_storage = kwargs.get('data_storage', 'individual')
self.dst_path_head, self.dst_dirname = os.path.split(self.dst_path) 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): def __str__(self):
"""Representation if an object of this class is printed.""" """Representation if an object of this class is printed."""
return str(self.__class__) + ": " + str(self.__dict__) return str(self.__class__) + ": " + str(self.__dict__)
...@@ -109,7 +102,7 @@ class PublishOptions: ...@@ -109,7 +102,7 @@ class PublishOptions:
# Check if destination directory is allowed path # Check if destination directory is allowed path
if not os.path.exists(self.dst_path_head): if not os.path.exists(self.dst_path_head):
raise FileNotFoundError('The specified destination directory ' 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 # Check if plot_name is a string or a list of strings
if isinstance(self.plot_names, str): if isinstance(self.plot_names, str):
......
...@@ -110,9 +110,13 @@ class TestPublish(unittest.TestCase): ...@@ -110,9 +110,13 @@ class TestPublish(unittest.TestCase):
publish(FIGS_AND_IDS, 4, DST_PATH, PIC_NAME) publish(FIGS_AND_IDS, 4, DST_PATH, PIC_NAME)
def test_dst_directory(self): 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): 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): def test_script_exists(self):
""" """
...@@ -251,16 +255,13 @@ class TestPublish(unittest.TestCase): ...@@ -251,16 +255,13 @@ class TestPublish(unittest.TestCase):
""" """
self.maxDiff = None self.maxDiff = None
publish_obj = PublishOptions(FIGS_AND_IDS, SRC_DIR, DST_PATH, PIC_NAME) publish_obj = PublishOptions(FIGS_AND_IDS, SRC_DIR, DST_PATH, PIC_NAME)
self.assertEqual(str(publish_obj), self.assertIn(
"<class 'plotid.publish.PublishOptions'>: {'figure': " "<class 'plotid.publish.PublishOptions'>: {'figure': "
"[<Figure size 640x480 with 0 Axes>, <Figure size" "[<Figure size 640x480 with 0 Axes>, <Figure size"
" 640x480 with 0 Axes>], 'figure_ids': " " 640x480 with 0 Axes>], 'figure_ids': "
"['MR05_0x63203c6f', 'MR05_0x63203c70'], " "['MR05_0x63203c6f', 'MR05_0x63203c70'], "
"'src_datapaths': 'test_src_folder', 'dst_path': " "'src_datapaths': 'test_src_folder'",
"'test_parent/test_dst_folder', 'plot_names': " str(publish_obj))
"'test_picture', 'data_storage': 'individual', "
"'dst_path_head': 'test_parent', 'dst_dirname': "
"'test_dst_folder'}")
def tearDown(self): def tearDown(self):
""" Delete all files created in setUp. """ """ 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