Skip to content
Snippets Groups Projects
Commit 04c851a7 authored by nugget's avatar nugget
Browse files

Fix tests and coverage for new project structure.

parent 5a5bf77b
No related branches found
No related tags found
4 merge requests!12v.0.1 for alpha release,!11Draft: Merge version0.1 changes into dev,!10Version0.1,!9Packaging
This commit is part of merge request !11. Comments created here will be created in the context of that merge request.
.coveragerc 0 → 100644
[run]
omit =
*example.py
*/usr/*
......@@ -56,7 +56,7 @@ test:
- docker
script:
# - python -m unittest discover -s ./tests/ -p "test*" # deprecated unittest command
- python runner_tests.py
- python tests/runner_tests.py
# - pip install tox flake8 # you can also use tox
# - tox -e py36,flake8
......
......@@ -57,5 +57,5 @@ for i, figure in enumerate(figs):
figure.savefig(name)
# %% Publish
publish('tests', '/home/chief/Dokumente/fst/plotid_python/data',
publish('../../tests', '/home/chief/Dokumente/fst/plotid_python/data',
fig1, 'Bild', 'individual')
......@@ -8,16 +8,19 @@ Includes starting all tests and measuring the code coverage.
import sys
import unittest
import coverage
from sys import exit
import os
path = os.path.abspath('src/plotid')
sys.path.append(path)
cov = coverage.Coverage()
cov.start()
loader = unittest.TestLoader()
tests = loader.discover('tests')
tests = loader.discover('.')
testRunner = unittest.runner.TextTestRunner(verbosity=2)
result = testRunner.run(tests)
cov.stop()
cov.save()
cov.report(show_missing=True)
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Unittests for TagPlot_matplotlib
'''
import unittest
from src.plotid.TagPlot_matplotlib import TagPlot_matplotlib
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
# %% Create data
x = np.linspace(0, 10, 100)
y = np.random.rand(100) + 2
y_2 = np.sin(x) + 2
# %% Create figure
color1 = 'black'
color2 = 'yellow'
# 1.Figure
fig1 = plt.figure()
plt.plot(x, y, color=color1)
plt.plot(x, y_2, color=color2)
plt.clf # Close figure
# 2.Figure
fig2 = plt.figure()
plt.plot(x, y, color=color2)
plt.plot(x, y_2, color=color1)
plt.clf # Close figure
fig = [fig1, fig2]
# Constants for tests
ProjectID = "MR01"
method = 1
rotation = 90
position = (0.975, 0.35)
class TestTagPlot_matplotlib(unittest.TestCase):
def test_mplfigures(self):
[figs, ID] = TagPlot_matplotlib(
fig, ProjectID, method, rotation, position)
self.assertIsInstance(figs[0], Figure)
self.assertIsInstance(figs[1], Figure)
with self.assertRaises(TypeError):
TagPlot_matplotlib(3, ProjectID, method, rotation, position)
if __name__ == '__main__':
unittest.main()
......@@ -5,7 +5,7 @@ Unittests for CreateID
"""
import unittest
from create_id import create_id
import src.plotid.create_id as cid
class TestCreateID(unittest.TestCase):
......@@ -15,20 +15,20 @@ class TestCreateID(unittest.TestCase):
def test_existence(self):
"""Test if create_id returns a string."""
self.assertIsInstance(create_id(1), str)
self.assertIsInstance(create_id(2), str)
self.assertIsInstance(cid.create_id(1), str)
self.assertIsInstance(cid.create_id(2), str)
def test_errors(self):
""" Test if Errors are raised when id_method is wrong. """
with self.assertRaises(ValueError):
create_id(3)
cid.create_id(3)
with self.assertRaises(ValueError):
create_id('h')
cid.create_id('h')
def test_length(self):
""" Test if figure_id has the correct length. """
self.assertEqual(len(create_id(1)), 10)
self.assertEqual(len(create_id(2)), 8)
self.assertEqual(len(cid.create_id(1)), 10)
self.assertEqual(len(cid.create_id(2)), 8)
if __name__ == '__main__':
......
......@@ -10,7 +10,8 @@ import sys
import shutil
from unittest.mock import patch
import matplotlib.pyplot as plt
from publish import publish
from src.plotid.publish import publish
SRC_DIR = 'test_src_folder'
PIC_NAME = 'test_picture'
......
......@@ -7,7 +7,7 @@ Unittests for save_plot
import os
import unittest
import matplotlib.pyplot as plt
from save_plot import save_plot
from src.plotid.save_plot import save_plot
FIGURE = plt.figure()
PLOT_NAME = 'PLOT_NAME'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment