Skip to content
Snippets Groups Projects
Commit 799a79ca authored by Jan Petermann's avatar Jan Petermann Committed by Christian Darsow Fromm
Browse files

Resolve "refactor tests"

parent 5d862a17
No related branches found
No related tags found
No related merge requests found
Showing
with 68 additions and 48 deletions
...@@ -15,7 +15,7 @@ htmlcov ...@@ -15,7 +15,7 @@ htmlcov
.venv .venv
.mypy_cache .mypy_cache
src/tests/test_io/gzip_data_files/ #src/tests/test_io/test___init__/gzip_data_files/
*.gz *.gz
......
from .servo_design import ServoDesign from openqlab.analysis import cavity, phase
from .gaussian_beam import fit_beam_data, GaussianBeam from openqlab.analysis.gaussian_beam import GaussianBeam, fit_beam_data
from ..conversion import db from openqlab.analysis.servo_design import ServoDesign
from . import phase, cavity from openqlab.conversion import db
...@@ -4,8 +4,8 @@ import numpy as np ...@@ -4,8 +4,8 @@ import numpy as np
import pandas as pd import pandas as pd
from scipy.optimize import curve_fit from scipy.optimize import curve_fit
from ..conversion.utils import human_readable from openqlab.conversion.utils import human_readable
from ..plots import beam_profile from openqlab.plots.gaussian_beam import beam_profile
class GaussianBeam: class GaussianBeam:
......
from .time_domain import zero_span, scope from openqlab.plots.frequency_domain import (
from .frequency_domain import amplitude_phase, power_spectrum, relative_input_noise amplitude_phase,
from .gaussian_beam import beam_profile power_spectrum,
relative_input_noise,
)
from openqlab.plots.gaussian_beam import beam_profile
from openqlab.plots.time_domain import scope, zero_span
import unittest
import matplotlib.pyplot as plt
from openqlab import io
from openqlab.analysis.cavity import finesse
class TestFinesse(unittest.TestCase):
def setUp(self):
self.data = io.read(
"test_analysis/test_cavity/opo_scan.csv", importer="KeysightCSV"
)
plt.figure()
def test_finesse_calculation(self):
result = finesse(self.data["opo_scan_2"])
self.assertAlmostEqual(result[0], 54.27, places=1)
self.assertAlmostEqual(result[1], 67.45, places=1)
def test_finesse_plot(self):
finesse(self.data["opo_scan_2"], plot=True)
...@@ -2,13 +2,15 @@ import unittest ...@@ -2,13 +2,15 @@ import unittest
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from openqlab import analysis, io from openqlab import io
from openqlab.analysis.cavity import finesse, modematching from openqlab.analysis.cavity import modematching
class TestModematching(unittest.TestCase): class TestModematching(unittest.TestCase):
def setUp(self): def setUp(self):
self.data = io.read("modematching/opo_scan.csv", importer="KeysightCSV") self.data = io.read(
"test_analysis/test_cavity/opo_scan.csv", importer="KeysightCSV"
)
plt.figure() plt.figure()
def test_default_inverted(self): def test_default_inverted(self):
...@@ -53,7 +55,9 @@ class TestModematching(unittest.TestCase): ...@@ -53,7 +55,9 @@ class TestModematching(unittest.TestCase):
modematching(self.data["opo_scan_2"], without_main_peaks=True) modematching(self.data["opo_scan_2"], without_main_peaks=True)
def test_cropped_main_peak(self): def test_cropped_main_peak(self):
data = io.read("modematching/opo_scan_zoom.csv", importer="KeysightCSV") data = io.read(
"test_analysis/test_cavity/opo_scan_zoom.csv", importer="KeysightCSV"
)
mm = modematching( mm = modematching(
data["opo_scan_zoom_2"].loc[0.0015:0.0155], data["opo_scan_zoom_2"].loc[0.0015:0.0155],
offset=-0.015, offset=-0.015,
...@@ -63,21 +67,3 @@ class TestModematching(unittest.TestCase): ...@@ -63,21 +67,3 @@ class TestModematching(unittest.TestCase):
without_main_peaks=True, without_main_peaks=True,
) )
self.assertAlmostEqual(mm, 0.92, places=2) self.assertAlmostEqual(mm, 0.92, places=2)
class TestFinesse(unittest.TestCase):
def setUp(self):
self.data = io.read("modematching/opo_scan.csv", importer="KeysightCSV")
plt.figure()
def test_finesse_calculation(self):
result = finesse(self.data["opo_scan_2"])
self.assertAlmostEqual(result[0], 54.27, places=1)
self.assertAlmostEqual(result[1], 67.45, places=1)
def test_finesse_plot(self):
finesse(self.data["opo_scan_2"], plot=True)
def test_finesse_raises_wrong_data(self):
with self.assertRaises(ValueError):
finesse(self.data)
...@@ -214,7 +214,7 @@ class TestServoDesign(unittest.TestCase): ...@@ -214,7 +214,7 @@ class TestServoDesign(unittest.TestCase):
self.sd.plant = 8 self.sd.plant = 8
columns = ["Gain (dB)", "Phase (deg)"] columns = ["Gain (dB)", "Phase (deg)"]
fra = io.read("servo_design/fra_3.csv") fra = io.read("test_analysis/test_servo_design/fra_3.csv")
self.sd.plant = fra self.sd.plant = fra
self.assertListEqual(self.sd.plant.columns.tolist(), columns) self.assertListEqual(self.sd.plant.columns.tolist(), columns)
...@@ -253,7 +253,7 @@ class TestServoDesign(unittest.TestCase): ...@@ -253,7 +253,7 @@ class TestServoDesign(unittest.TestCase):
def test_plot_with_plant(self): def test_plot_with_plant(self):
if self.display_available: if self.display_available:
self.sd.differentiator(390) self.sd.differentiator(390)
self.sd.plant = io.read("servo_design/fra_3.csv") self.sd.plant = io.read("test_analysis/test_servo_design/fra_3.csv")
plt = self.sd.plot() plt = self.sd.plot()
self.assertIsInstance(plt, mp.figure.Figure) self.assertIsInstance(plt, mp.figure.Figure)
ax = plt.axes[0] ax = plt.axes[0]
...@@ -267,7 +267,7 @@ class TestServoDesign(unittest.TestCase): ...@@ -267,7 +267,7 @@ class TestServoDesign(unittest.TestCase):
columns = ["Servo A", "Servo P"] columns = ["Servo A", "Servo P"]
self.assertListEqual(df.columns.tolist(), columns) self.assertListEqual(df.columns.tolist(), columns)
self.sd.plant = io.read("servo_design/fra_3.csv") self.sd.plant = io.read("test_analysis/test_servo_design/fra_3.csv")
df = self.sd.plot(plot=False) df = self.sd.plot(plot=False)
self.assertIsInstance(df, DataFrame) self.assertIsInstance(df, DataFrame)
columns = ["Servo A", "Servo P", "Servo+TF A", "Servo+TF P"] columns = ["Servo A", "Servo P", "Servo+TF A", "Servo+TF P"]
...@@ -321,7 +321,7 @@ class TestServoDesign(unittest.TestCase): ...@@ -321,7 +321,7 @@ class TestServoDesign(unittest.TestCase):
) )
def test_correct_latency(self): def test_correct_latency(self):
self.sd.plant = io.read("servo_design/fra_3.csv") self.sd.plant = io.read("test_analysis/test_servo_design/fra_3.csv")
df = self.sd.plot(plot=False, correct_latency=False) df = self.sd.plot(plot=False, correct_latency=False)
df_corrected = self.sd.plot(plot=False, correct_latency=True) df_corrected = self.sd.plot(plot=False, correct_latency=True)
columns = ["Servo A", "Servo P", "Servo+TF A", "Servo+TF P"] columns = ["Servo A", "Servo P", "Servo+TF A", "Servo+TF P"]
...@@ -388,7 +388,7 @@ class TestServoDesign(unittest.TestCase): ...@@ -388,7 +388,7 @@ class TestServoDesign(unittest.TestCase):
self.assertEqual(self.sd.__str__(), sd.__str__()) self.assertEqual(self.sd.__str__(), sd.__str__())
# Encode and decode with plant # Encode and decode with plant
fra = io.read("servo_design/fra_3.csv") fra = io.read("test_analysis/test_servo_design/fra_3.csv")
self.sd.plant = fra self.sd.plant = fra
sdjson = jsonpickle.encode(self.sd) sdjson = jsonpickle.encode(self.sd)
sd = jsonpickle.decode(sdjson) sd = jsonpickle.decode(sdjson)
......
File deleted
File deleted
File deleted
File deleted
...@@ -11,8 +11,8 @@ class TestRead(unittest.TestCase): ...@@ -11,8 +11,8 @@ class TestRead(unittest.TestCase):
Test files starting with a dot (".") will be ignored. Test files starting with a dot (".") will be ignored.
""" """
files_path = Path(r"./test_importers/data_files") files_path = Path(r"test_io/test_importers/data_files")
gzip_files_path = Path(r"./test_io/gzip_data_files") gzip_files_path = Path(r"test_io/test___init__/gzip_data_files")
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
...@@ -25,13 +25,17 @@ class TestRead(unittest.TestCase): ...@@ -25,13 +25,17 @@ class TestRead(unittest.TestCase):
cls.files = [file for file in cls.files if not file.stem.startswith(".")] cls.files = [file for file in cls.files if not file.stem.startswith(".")]
cls.binary_files = [ cls.binary_files = [
Path(r"./test_importers/data_files/KeysightBinary/keysight_binary.bin"), Path(
Path(r"./test_importers/data_files/TektronixSpectrogram/test2.mat"), r"test_io/test_importers/data_files/KeysightBinary/keysight_binary.bin"
),
Path(r"test_io/test_importers/data_files/TektronixSpectrogram/test2.mat"),
] ]
cls.ignore_text_files = [ cls.ignore_text_files = [
Path(r"./test_importers/data_files/KeysightFRA/scope_0_comma.csv"), Path(r"test_io/test_importers/data_files/KeysightFRA/scope_0_comma.csv"),
Path(r"./test_importers/data_files/KeysightFRA/scope_1_semicolon.csv"), Path(
r"test_io/test_importers/data_files/KeysightFRA/scope_1_semicolon.csv"
),
] ]
cls.text_files = [ cls.text_files = [
file file
......
...@@ -10,7 +10,7 @@ class TestReads(unittest.TestCase): ...@@ -10,7 +10,7 @@ class TestReads(unittest.TestCase):
Test files starting with a dot (".") will be ignored. Test files starting with a dot (".") will be ignored.
""" """
files_path = Path(r"./test_importers/data_files") files_path = Path(r"test_io/test_importers/data_files")
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
...@@ -21,13 +21,17 @@ class TestReads(unittest.TestCase): ...@@ -21,13 +21,17 @@ class TestReads(unittest.TestCase):
cls.files = [file for file in cls.files if not file.stem.startswith(".")] cls.files = [file for file in cls.files if not file.stem.startswith(".")]
cls.binary_files = [ cls.binary_files = [
Path(r"./test_importers/data_files/KeysightBinary/keysight_binary.bin"), Path(
Path(r"./test_importers/data_files/TektronixSpectrogram/test2.mat"), r"test_io/test_importers/data_files/KeysightBinary/keysight_binary.bin"
),
Path(r"test_io/test_importers/data_files/TektronixSpectrogram/test2.mat"),
] + list((cls.files_path / "Gwinstek_LSF").glob("*")) ] + list((cls.files_path / "Gwinstek_LSF").glob("*"))
cls.ignore_text_files = [ cls.ignore_text_files = [
Path(r"./test_importers/data_files/KeysightFRA/scope_0_comma.csv"), Path(r"test_io/test_importers/data_files/KeysightFRA/scope_0_comma.csv"),
Path(r"./test_importers/data_files/KeysightFRA/scope_1_semicolon.csv"), Path(
r"test_io/test_importers/data_files/KeysightFRA/scope_1_semicolon.csv"
),
] ]
cls.text_files = [ cls.text_files = [
file file
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment