Skip to content
Snippets Groups Projects
Commit d8678b6e authored by Christian Darsow Fromm's avatar Christian Darsow Fromm
Browse files

Merge branch '68-refactor-tests' into 'develop'

Resolve "refactor tests"

Closes #68

See merge request las-nq/openqlab!33
parents 5d862a17 799a79ca
Branches
Tags
No related merge requests found
Showing
with 68 additions and 48 deletions
......@@ -15,7 +15,7 @@ htmlcov
.venv
.mypy_cache
src/tests/test_io/gzip_data_files/
#src/tests/test_io/test___init__/gzip_data_files/
*.gz
......
from .servo_design import ServoDesign
from .gaussian_beam import fit_beam_data, GaussianBeam
from ..conversion import db
from . import phase, cavity
from openqlab.analysis import cavity, phase
from openqlab.analysis.gaussian_beam import GaussianBeam, fit_beam_data
from openqlab.analysis.servo_design import ServoDesign
from openqlab.conversion import db
......@@ -4,8 +4,8 @@ import numpy as np
import pandas as pd
from scipy.optimize import curve_fit
from ..conversion.utils import human_readable
from ..plots import beam_profile
from openqlab.conversion.utils import human_readable
from openqlab.plots.gaussian_beam import beam_profile
class GaussianBeam:
......
from .time_domain import zero_span, scope
from .frequency_domain import amplitude_phase, power_spectrum, relative_input_noise
from .gaussian_beam import beam_profile
from openqlab.plots.frequency_domain import (
amplitude_phase,
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
import matplotlib.pyplot as plt
from openqlab import analysis, io
from openqlab.analysis.cavity import finesse, modematching
from openqlab import io
from openqlab.analysis.cavity import modematching
class TestModematching(unittest.TestCase):
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()
def test_default_inverted(self):
......@@ -53,7 +55,9 @@ class TestModematching(unittest.TestCase):
modematching(self.data["opo_scan_2"], without_main_peaks=True)
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(
data["opo_scan_zoom_2"].loc[0.0015:0.0155],
offset=-0.015,
......@@ -63,21 +67,3 @@ class TestModematching(unittest.TestCase):
without_main_peaks=True,
)
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):
self.sd.plant = 8
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.assertListEqual(self.sd.plant.columns.tolist(), columns)
......@@ -253,7 +253,7 @@ class TestServoDesign(unittest.TestCase):
def test_plot_with_plant(self):
if self.display_available:
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()
self.assertIsInstance(plt, mp.figure.Figure)
ax = plt.axes[0]
......@@ -267,7 +267,7 @@ class TestServoDesign(unittest.TestCase):
columns = ["Servo A", "Servo P"]
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)
self.assertIsInstance(df, DataFrame)
columns = ["Servo A", "Servo P", "Servo+TF A", "Servo+TF P"]
......@@ -321,7 +321,7 @@ class TestServoDesign(unittest.TestCase):
)
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_corrected = self.sd.plot(plot=False, correct_latency=True)
columns = ["Servo A", "Servo P", "Servo+TF A", "Servo+TF P"]
......@@ -388,7 +388,7 @@ class TestServoDesign(unittest.TestCase):
self.assertEqual(self.sd.__str__(), sd.__str__())
# 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
sdjson = jsonpickle.encode(self.sd)
sd = jsonpickle.decode(sdjson)
......
File deleted
File deleted
File deleted
File deleted
......@@ -11,8 +11,8 @@ class TestRead(unittest.TestCase):
Test files starting with a dot (".") will be ignored.
"""
files_path = Path(r"./test_importers/data_files")
gzip_files_path = Path(r"./test_io/gzip_data_files")
files_path = Path(r"test_io/test_importers/data_files")
gzip_files_path = Path(r"test_io/test___init__/gzip_data_files")
@classmethod
def setUpClass(cls):
......@@ -25,13 +25,17 @@ class TestRead(unittest.TestCase):
cls.files = [file for file in cls.files if not file.stem.startswith(".")]
cls.binary_files = [
Path(r"./test_importers/data_files/KeysightBinary/keysight_binary.bin"),
Path(r"./test_importers/data_files/TektronixSpectrogram/test2.mat"),
Path(
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 = [
Path(r"./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_0_comma.csv"),
Path(
r"test_io/test_importers/data_files/KeysightFRA/scope_1_semicolon.csv"
),
]
cls.text_files = [
file
......
......@@ -10,7 +10,7 @@ class TestReads(unittest.TestCase):
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
def setUpClass(cls):
......@@ -21,13 +21,17 @@ class TestReads(unittest.TestCase):
cls.files = [file for file in cls.files if not file.stem.startswith(".")]
cls.binary_files = [
Path(r"./test_importers/data_files/KeysightBinary/keysight_binary.bin"),
Path(r"./test_importers/data_files/TektronixSpectrogram/test2.mat"),
Path(
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("*"))
cls.ignore_text_files = [
Path(r"./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_0_comma.csv"),
Path(
r"test_io/test_importers/data_files/KeysightFRA/scope_1_semicolon.csv"
),
]
cls.text_files = [
file
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment