From c904cc629c13565ce17183a96e21bab7184c55b9 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Bayle <j2b.bayle@gmail.com>
Date: Wed, 30 Mar 2022 12:19:18 +0200
Subject: [PATCH] Add unit tests for various orbit file versions

---
 .gitattributes                                |  2 +-
 tests/esa-orbits-1-0-5.h5                     |  3 +++
 tests/esa-trailing-orbits-2-0-dev.h5          |  3 +++
 tests/keplerian-orbits-1-0-2.h5               |  3 +++
 ...-orbits.h5 => keplerian-orbits-2-0-dev.h5} |  0
 tests/test_instrument.py                      | 27 +++++++++++++++++++
 6 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 tests/esa-orbits-1-0-5.h5
 create mode 100644 tests/esa-trailing-orbits-2-0-dev.h5
 create mode 100644 tests/keplerian-orbits-1-0-2.h5
 rename tests/{keplerian-orbits.h5 => keplerian-orbits-2-0-dev.h5} (100%)

diff --git a/.gitattributes b/.gitattributes
index b2f061e..132ac38 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1 @@
-tests/keplerian-orbits.h5 filter=lfs diff=lfs merge=lfs -text
+tests/*.h5 filter=lfs diff=lfs merge=lfs -text
diff --git a/tests/esa-orbits-1-0-5.h5 b/tests/esa-orbits-1-0-5.h5
new file mode 100644
index 0000000..c32b92e
--- /dev/null
+++ b/tests/esa-orbits-1-0-5.h5
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:61398e1cd210a15adac3fdab6fd2e3227eff562a2bbc53387379d0fb1d118943
+size 9518728
diff --git a/tests/esa-trailing-orbits-2-0-dev.h5 b/tests/esa-trailing-orbits-2-0-dev.h5
new file mode 100644
index 0000000..9f27636
--- /dev/null
+++ b/tests/esa-trailing-orbits-2-0-dev.h5
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:75456add2be5eeede5ad4461e2ae3030f52a829018fb5e07a77188c7e121b310
+size 1212152
diff --git a/tests/keplerian-orbits-1-0-2.h5 b/tests/keplerian-orbits-1-0-2.h5
new file mode 100644
index 0000000..4cdd2f8
--- /dev/null
+++ b/tests/keplerian-orbits-1-0-2.h5
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:880c96961c2bae1e41e0d58488e2295d2e0458664ff3ad66e5f025d3e4fa3a88
+size 2516632
diff --git a/tests/keplerian-orbits.h5 b/tests/keplerian-orbits-2-0-dev.h5
similarity index 100%
rename from tests/keplerian-orbits.h5
rename to tests/keplerian-orbits-2-0-dev.h5
diff --git a/tests/test_instrument.py b/tests/test_instrument.py
index ab0af1e..fe2d3d5 100644
--- a/tests/test_instrument.py
+++ b/tests/test_instrument.py
@@ -22,6 +22,33 @@ def test_run_no_upsampling():
     instru = Instrument(size=100, physics_upsampling=1, aafilter=None)
     instru.simulate()
 
+def test_no_orbit_file():
+    """Test that simulations fail with an invalid orbit file."""
+    with pytest.raises(FileNotFoundError):
+        Instrument(size=100, orbits='tests/nonexistent-orbits.h5')
+    with pytest.raises(FileNotFoundError):
+        Instrument(size=100, t0=0, orbits='tests/nonexistent-orbits.h5')
+
+def test_keplerian_orbits_1_0_5():
+    """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()
+
+def test_esa_orbits_1_0_5():
+    """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()
+
+def test_keplerian_orbits_2_0_dev():
+    """Test that simulations can run with Keplerian orbit files v2.0.dev."""
+    instru = Instrument(size=100, orbits='tests/keplerian-orbits-2-0-dev.h5')
+    instru.simulate()
+
+def test_esa_trailing_orbits_2_0_dev():
+    """Test that simulations can run with ESA trailing orbit files v2.0.dev."""
+    instru = Instrument(size=100, orbits='tests/esa-trailing-orbits-2-0-dev.h5')
+    instru.simulate()
+
 def test_locking():
     """Test that simulations can run with various lock configurations."""
     # Test six free-running lasers
-- 
GitLab