Skip to content
Snippets Groups Projects
Commit 1ec032c1 authored by nugget's avatar nugget
Browse files

Unit test for CreateID and TagPlot(unfinished), cleanup repo.

parent c27fdccf
Branches
Tags
2 merge requests!12v.0.1 for alpha release,!1Implement basic function to switch between plot engines.
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 23 10:09:46 2021
@author: Richter
"""
#%% Test
a = 1
b = 2
print(a+b)
print(a-b)
\ No newline at end of file
......@@ -23,7 +23,7 @@ def CreateID(method):
ID = str(uuid.uuid4()) # creates a random UUID
ID = ID[0:8] # only use first 8 numbers
else:
raise RuntimeWarning(
raise ValueError(
f'Your chosen ID method "{method}" is not supported.\n'
'At the moment these methods are available:\n'
'"1": Unix time converted to hexadecimal\n'
......
# plot_ID_python
This is the python PlotID project. To run the program python version 3.10 is required.
\ No newline at end of file
This is the python PlotID project.
To run the program python version 3.10 is required.
\ No newline at end of file
......@@ -37,21 +37,21 @@ def TagPlot(figs, prefix, engine, method=1):
if prefix:
pass
else:
raise RuntimeWarning("No prefix set")
raise RuntimeWarning("No prefix set.")
if figs:
pass
else:
raise RuntimeWarning("No figures set")
raise RuntimeWarning("No figures set.")
try:
method = int(method)
except ValueError:
raise RuntimeWarning('The chosen ID method is not an integer.')
raise TypeError('The chosen ID method is not an integer.')
match engine:
case 'matplotlib' | 'pyplot':
return TagPlot_matplotlib(figs, prefix, method)
case _:
raise RuntimeWarning(f'The plot engine "{engine}"'
raise ValueError(f'The plot engine "{engine}"'
' is not supported.')
......@@ -4,9 +4,7 @@ import warnings
import CreateID
from fcn_help.FST_colors import Colors
import matplotlib.pyplot as plt
plt.style.use('fcn_help/FST.mplstyle')
# %matplotlib qt
# %matplotlib inline
#plt.style.use('./fcn_help/FST.mplstyle')
def TagPlot_matplotlib(figs, prefix, method):
......@@ -17,10 +15,11 @@ def TagPlot_matplotlib(figs, prefix, method):
as Tag (Property of figure).
TagPlot can tag multiple figures at once
"""
# isinstance(figs, t)
# isinstance(figs, t) # Check if figure input is valid
location = 'nothing'
# TODO: Implement backwards combatibility with if-clauses
match location:
case 'north':
rotation = 0
......
Image diff could not be displayed: it is too large. Options to address this: view the blob.
Image diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -37,7 +37,7 @@ y = random.rand(100) + 2
y_2 = np.sin(x) + 2
# %% Daten speichern
dataset1 = "test_data.npy"
dataset1 = "sample_data.npy"
np.save(dataset1, x, y, y_2)
# %% figure erstellen
......@@ -53,17 +53,17 @@ plt.plot(x, y, color=color1)
plt.plot(x, y_2, color=color2)
# plt.draw()
# 2.Figure
plt.clf # Figure schließen
plt.clf # Close figure
fig2 = plt.figure()
plt.plot(x, y, color=color2)
plt.plot(x, y_2, color=color1)
# plt.draw()
plt.clf # Figure schließen
plt.clf # Close figure
fig = [fig1, fig2]
# %% TagPlot
[figs, ID] = TagPlot(fig, ProjectID, plot_engine)
[figs, ID] = TagPlot(fig, ProjectID, plot_engine, method='1')
# %% Figure als tiff-Datei abspeichern
for i in range(len(figs)):
......
File moved
File moved
File moved
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 23 10:09:46 2021
@author: Richter
"""
#%% Test
a = 1
b = 2
print(a+b)
print(a-b)
\ No newline at end of file
File added
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Unittests for CreateID
'''
import unittest
import CreateID
class TestCreateID(unittest.TestCase):
def test_existence(self):
self.assertIsNotNone(CreateID.CreateID(1))
self.assertIsNotNone(CreateID.CreateID(2))
def test_errors(self):
with self.assertRaises(ValueError):
CreateID.CreateID(3)
with self.assertRaises(ValueError):
CreateID.CreateID('h')
def test_length(self):
self.assertEqual(len(CreateID.CreateID(1)), 10)
self.assertEqual(len(CreateID.CreateID(2)), 8)
if __name__ == '__main__':
unittest.main()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Unittests for TagPlot
'''
import unittest
from TagPlot import TagPlot
from fcn_help.FST_colors import Colors
import sys
import numpy as np
from numpy import random
import matplotlib.pyplot as plt
plt.style.use('../fcn_help/FST.mplstyle')
sys.path.append("fcn_core")
sys.path.append("fcn_help")
ProjectID = "MR01"
# %% Plot engine
plot_engine = "matplotlib"
# %% Daten erzeugen
x = np.linspace(0, 10, 100)
y = random.rand(100) + 2
y_2 = np.sin(x) + 2
# %% figure erstellen
colors = Colors() # create instance from class
color_list = colors.get_color_names()
# Plot erstellen
color1 = colors.get_rgb('black')
color2 = colors.get_rgb('yellow')
# 1.Figure
fig1 = plt.figure()
plt.plot(x, y, color=color1)
plt.plot(x, y_2, color=color2)
# 2.Figure
plt.clf # Close figure
fig2 = plt.figure()
plt.plot(x, y, color=color2)
plt.plot(x, y_2, color=color1)
plt.clf # Close figure
fig = [fig1, fig2]
# %% TagPlot
[figs, ID] = TagPlot(fig, ProjectID, plot_engine, method=1)
class TestTagPlot(unittest.TestCase):
def test_idmethod(self):
with self.assertRaises(TypeError):
TagPlot(fig, ProjectID, plot_engine, method='(0,1)')
TagPlot(fig, ProjectID, plot_engine, method='h')
TagPlot(fig, ProjectID, plot_engine, method='[0,1]')
if __name__ == '__main__':
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment