From 192dc5448ceedbc9f62015bf5fcffb4c0d041b42 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Bayle <j2b.bayle@gmail.com>
Date: Thu, 1 Sep 2022 16:09:08 +0200
Subject: [PATCH] Add writing measurement files to tests

---
 tests/test_fplan.py      | 27 +++++++++++++++++++++++++--
 tests/test_glitch.py     |  3 +++
 tests/test_gws.py        |  6 ++++++
 tests/test_hexagon.py    |  4 ++--
 tests/test_instrument.py | 15 +++++++++++++--
 tests/test_ranging.py    |  4 ++++
 6 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/tests/test_fplan.py b/tests/test_fplan.py
index 5ecd6ae..d4c11e6 100755
--- a/tests/test_fplan.py
+++ b/tests/test_fplan.py
@@ -92,12 +92,15 @@ def test_static_fplan():
     # Check locking beatnotes
     instru = Instrument(size=100, lock='N1-12', fplan='static')
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru, static)
     instru = Instrument(size=100, lock='N1-21', fplan='static')
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru, static)
     instru = Instrument(size=100, lock='N4-12', fplan='static')
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru, static)
 
 def test_static_fplan_valid_with_all_lock_configs():
@@ -112,6 +115,7 @@ def test_static_fplan_valid_with_all_lock_configs():
             instru = Instrument(size=100, lock=f'{topology}-{primary}', fplan='static')
             instru.disable_all_noises()
             instru.simulate()
+            instru.write(mode='w')
 
             for mosa in instru.MOSAS:
                 assert np.all(5E6 <= np.abs(instru.isi_carriers[mosa]))
@@ -146,12 +150,15 @@ def test_constant_unequal_fplan():
     # Check locking beatnotes
     instru = Instrument(size=100, lock='N1-12', fplan=fplan)
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru, fplan)
     instru = Instrument(size=100, lock='N1-21', fplan=fplan)
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru, fplan)
     instru = Instrument(size=100, lock='N4-12', fplan=fplan)
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru, fplan)
 
 def test_varying_equal_fplan():
@@ -167,12 +174,15 @@ def test_varying_equal_fplan():
     fplan = {mosa: fplan for mosa in Instrument.MOSAS}
     instru = Instrument(size=100, lock='N1-12', fplan=fplan)
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru, fplan)
     instru = Instrument(size=100, lock='N1-21', fplan=fplan)
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru, fplan)
     instru = Instrument(size=100, lock='N4-12', fplan=fplan)
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru, fplan)
 
 def test_varying_unequal_fplan():
@@ -190,12 +200,15 @@ def test_varying_unequal_fplan():
     # Check locking beatnotes
     instru = Instrument(size=100, lock='N1-12', fplan=fplan)
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru, fplan)
     instru = Instrument(size=100, lock='N1-21', fplan=fplan)
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru, fplan)
     instru = Instrument(size=100, lock='N4-12', fplan=fplan)
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru, fplan)
 
 def test_keplerian_fplan_1_1():
@@ -216,12 +229,15 @@ def test_keplerian_fplan_1_1():
     # Check locking beatnotes
     instru = Instrument(size=100, lock='N1-12', fplan='tests/keplerian-fplan-1-1.h5')
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru)
     instru = Instrument(size=100, lock='N1-21', fplan='tests/keplerian-fplan-1-1.h5')
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru)
     instru = Instrument(size=100, lock='N4-12', fplan='tests/keplerian-fplan-1-1.h5')
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru)
 
 def test_esa_trailing_fplan_1_1():
@@ -242,12 +258,15 @@ def test_esa_trailing_fplan_1_1():
     # Check locking beatnotes
     instru = Instrument(size=100, lock='N1-12', fplan='tests/esa-trailing-fplan-1-1.h5')
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru)
     instru = Instrument(size=100, lock='N1-21', fplan='tests/esa-trailing-fplan-1-1.h5')
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru)
     instru = Instrument(size=100, lock='N4-12', fplan='tests/esa-trailing-fplan-1-1.h5')
     instru.simulate()
+    instru.write(mode='w')
     assert _consistent_locking_beatnotes(instru)
 
 def test_offset_freqs():
@@ -257,6 +276,7 @@ def test_offset_freqs():
     instru = Instrument(size=100, lock='six', offset_freqs='default')
     instru.disable_all_noises()
     instru.simulate()
+    instru.write(mode='w')
     for mosa in instru.MOSAS:
         assert np.all(5E6 <= np.abs(instru.isi_carriers[mosa]))
         assert np.all(5E6 <= np.abs(instru.isi_usbs[mosa]))
@@ -274,15 +294,18 @@ def test_offset_freqs():
     }
     instru = Instrument(size=100, lock='six', offset_freqs=offset_freqs)
     instru.simulate()
+    instru.write(mode='w')
     for mosa in instru.MOSAS:
         assert instru.local_carrier_offsets[mosa] == offset_freqs[mosa]
 
     # Check that frequency offsets are only set on unlocked lasers
     instru = Instrument(size=100, lock='N1-12', offset_freqs=offset_freqs)
-    instru.simulate()
     instru.disable_all_noises()
+    instru.simulate()
+    instru.write(mode='w')
     assert instru.local_carrier_offsets['12'] == offset_freqs['12']
     instru = Instrument(size=100, lock='N1-23', offset_freqs=offset_freqs)
-    instru.simulate()
     instru.disable_all_noises()
+    instru.simulate()
+    instru.write(mode='w')
     assert instru.local_carrier_offsets['23'] == offset_freqs['23']
diff --git a/tests/test_glitch.py b/tests/test_glitch.py
index 762744a..30df75e 100644
--- a/tests/test_glitch.py
+++ b/tests/test_glitch.py
@@ -21,6 +21,7 @@ def test_no_glitches():
         assert instru.glitch_lasers[mosa] == 0
 
     instru.simulate()
+    instru.write(mode='w')
 
     for mosa in instru.MOSAS:
         assert instru.local_carrier_fluctuations[mosa] == approx(0)
@@ -72,6 +73,7 @@ def test_glitch_file_1_0():
             assert instru.glitch_lasers[mosa] == 0
 
     instru.simulate()
+    instru.write(mode='w')
 
     for mosa in instru.MOSAS:
 
@@ -147,6 +149,7 @@ def test_glitch_file_1_1():
             assert instru.glitch_lasers[mosa] == 0
 
     instru.simulate()
+    instru.write(mode='w')
 
     for mosa in instru.MOSAS:
 
diff --git a/tests/test_gws.py b/tests/test_gws.py
index 9691aea..b18c87e 100644
--- a/tests/test_gws.py
+++ b/tests/test_gws.py
@@ -19,6 +19,7 @@ def test_no_gws():
         assert instru.gws[mosa] == 0
 
     instru.simulate()
+    instru.write(mode='w')
 
     for mosa in instru.MOSAS:
         assert instru.distant_carrier_fluctuations[mosa] == approx(0)
@@ -44,6 +45,7 @@ def test_dict_of_gws():
         assert np.all(instru.gws[mosa] == responses[mosa])
 
     instru.simulate()
+    instru.write(mode='w')
 
     for mosa in instru.MOSAS:
         assert approx(instru.distant_carrier_fluctuations[mosa]) == \
@@ -99,6 +101,7 @@ def test_gw_file_1_1():
         assert instru.gws[mosa] == approx(gwf[f'tcb/l_{mosa}'][:])
 
     instru.simulate()
+    instru.write(mode='w')
 
     for mosa in instru.MOSAS:
         assert approx(instru.distant_carrier_fluctuations[mosa]) == \
@@ -127,6 +130,7 @@ def test_gw_file_1_1():
         assert instru.gws[mosa] == approx(gwf[f'tcb/l_{mosa}'][:])
 
     instru.simulate()
+    instru.write(mode='w')
 
     for mosa in instru.MOSAS:
         assert approx(instru.distant_carrier_fluctuations[mosa]) == \
@@ -182,6 +186,7 @@ def test_gw_file_2_0_dev():
         assert instru.gws[mosa] == approx(gwf['tcb/y'][:, imosa])
 
     instru.simulate()
+    instru.write(mode='w')
 
     for imosa, mosa in enumerate(instru.MOSAS):
         assert approx(instru.distant_carrier_fluctuations[mosa]) == \
@@ -210,6 +215,7 @@ def test_gw_file_2_0_dev():
         assert instru.gws[mosa] == approx(gwf['tcb/y'][:, imosa])
 
     instru.simulate()
+    instru.write(mode='w')
 
     for imosa, mosa in enumerate(instru.MOSAS):
         assert approx(instru.distant_carrier_fluctuations[mosa]) == \
diff --git a/tests/test_hexagon.py b/tests/test_hexagon.py
index 6c7fbe5..850d327 100755
--- a/tests/test_hexagon.py
+++ b/tests/test_hexagon.py
@@ -15,6 +15,6 @@ def test_write():
     """Test that simulations can run and be written."""
     hexagon = Hexagon()
     hexagon.simulate()
-    hexagon.write('test.h5', mode='w')
+    hexagon.write('measurements.h5', mode='w')
 
-    assert os.path.isfile('test.h5')
+    assert os.path.isfile('measurements.h5')
diff --git a/tests/test_instrument.py b/tests/test_instrument.py
index fc0e89e..148506f 100755
--- a/tests/test_instrument.py
+++ b/tests/test_instrument.py
@@ -10,16 +10,19 @@ def test_run():
     """Test that simulations can run."""
     instru = Instrument(size=100)
     instru.simulate()
+    instru.write(mode='w')
 
 def test_run_no_aafilter():
     """Test that simulations can run with no filter."""
     instru = Instrument(size=100, aafilter=None)
     instru.simulate()
+    instru.write(mode='w')
 
 def test_run_no_upsampling():
     """Test that simulations can run with no filter."""
     instru = Instrument(size=100, physics_upsampling=1, aafilter=None)
     instru.simulate()
+    instru.write(mode='w')
 
 def test_no_orbit_file():
     """Test that simulations fail with an invalid orbit file."""
@@ -32,30 +35,38 @@ def test_keplerian_orbits_1_0_2():
     """Test that simulations can run with Keplerian orbit files v1.0.2."""
     instru = Instrument(size=100, orbits='tests/keplerian-orbits-1-0-2.h5')
     instru.simulate()
+    instru.write(mode='w')
 
 def test_esa_orbits_1_0_2():
     """Test that simulations can run with ESA orbit files v1.0.2."""
     instru = Instrument(size=100, orbits='tests/esa-orbits-1-0-2.h5')
     instru.simulate()
+    instru.write(mode='w')
 
 def test_keplerian_orbits_2_0():
     """Test that simulations can run with Keplerian orbit files v2.0."""
     instru = Instrument(size=100, orbits='tests/keplerian-orbits-2-0.h5')
     instru.simulate()
+    instru.write(mode='w')
 
 def test_esa_trailing_orbits_2_0():
     """Test that simulations can run with ESA trailing orbit files v2.0."""
     instru = Instrument(size=100, orbits='tests/esa-trailing-orbits-2-0.h5')
     instru.simulate()
+    instru.write(mode='w')
 
 def test_locking():
     """Test that simulations can run with various lock configurations."""
     # Test six free-running lasers
-    Instrument(size=100, lock='six').simulate()
+    instru = Instrument(size=100, lock='six')
+    instru.simulate()
+    instru.write(mode='w')
     # Test non-swap configurations
     for i in range(1, 6):
         for primary in ['12', '23', '31', '13', '32', '21']:
-            Instrument(size=100, lock=f'N{i}-{primary}').simulate()
+            instru = Instrument(size=100, lock=f'N{i}-{primary}')
+            instru.simulate()
+            instru.write(mode='w')
     # Test that any other raises an error
     with pytest.raises(ValueError):
         Instrument(size=100, lock='whatever')
diff --git a/tests/test_ranging.py b/tests/test_ranging.py
index 4fe6a10..c7f27bf 100755
--- a/tests/test_ranging.py
+++ b/tests/test_ranging.py
@@ -21,6 +21,7 @@ def test_no_prn_ambiguity():
     instru.disable_clock_noises()
     instru.disable_ranging_noises()
     instru.simulate()
+    instru.write(mode='w')
     for mosa in instru.MOSAS:
         assert instru.mprs[mosa][50:] == approx(pprs[mosa])
 
@@ -41,6 +42,7 @@ def test_prn_ambiguity_with_static_orbits():
     instru.disable_clock_noises()
     instru.disable_ranging_noises()
     instru.simulate()
+    instru.write(mode='w')
     for mosa in instru.MOSAS:
         assert instru.mprs[mosa][50:] == approx(pprs[mosa] % (300E3 / c))
 
@@ -49,6 +51,7 @@ def test_prn_ambiguity_with_static_orbits():
     instru.disable_clock_noises()
     instru.disable_ranging_noises()
     instru.simulate()
+    instru.write(mode='w')
     for mosa in instru.MOSAS:
         assert instru.mprs[mosa][50:] == approx(pprs[mosa] % (100E3 / c))
 
@@ -64,6 +67,7 @@ def test_prn_ambiguity_with_esa_orbits():
     instru.disable_clock_noises()
     instru.disable_ranging_noises()
     instru.simulate()
+    instru.write(mode='w')
 
     for mosa in instru.MOSAS:
         assert np.all(instru.mprs[mosa][50:] <= 300E3 / c)
-- 
GitLab