Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_ephem_has_given_plane(epochs, coordinates, plane):
ephem = Ephem(epochs, coordinates, plane)
assert ephem.plane is plane
def test_ephem_sample_same_epochs_returns_same_input(epochs, coordinates, method):
unused_plane = Planes.EARTH_EQUATOR
ephem = Ephem(coordinates, epochs, unused_plane)
result_coordinates = ephem.sample(epochs, method=method)
# TODO: Should it return exactly the same?
assert_coordinates_allclose(result_coordinates, coordinates, atol_scale=1e-17)
def test_ephem_sample_scalar_epoch_returns_1_dimensional_coordinates(
epochs, coordinates, method
):
unused_plane = Planes.EARTH_EQUATOR
ephem = Ephem(coordinates, epochs, unused_plane)
result_coordinates = ephem.sample(epochs[0], method=method)
# Exactly the same
assert result_coordinates.ndim == 1
def test_from_ephem_has_expected_properties():
epoch = J2000_TDB
ephem = Ephem.from_body(Earth, epoch, attractor=Sun)
expected_r, expected_v = ephem.rv(epoch)
ss = Orbit.from_ephem(Sun, ephem, epoch)
assert ss.plane is ephem.plane
assert ss.epoch == epoch
assert_quantity_allclose(ss.r, expected_r)
assert_quantity_allclose(ss.v, expected_v)
def test_ephem_fails_if_dimensions_are_not_correct(epochs, coordinates):
unused_plane = Planes.EARTH_EQUATOR
with pytest.raises(ValueError) as excinfo:
Ephem(epochs[0], coordinates, unused_plane)
assert (
"Coordinates and epochs must have dimension 1, got 0 and 1" in excinfo.exconly()
)
def test_ephem_sample_no_arguments_returns_exactly_same_input(
epochs, coordinates, method
):
unused_plane = Planes.EARTH_EQUATOR
ephem = Ephem(coordinates, epochs, unused_plane)
result_coordinates = ephem.sample(method=method)
# Exactly the same
assert result_coordinates == coordinates
def test_rv_scalar_epoch_returns_scalar_vectors(coordinates, epochs):
unused_plane = Planes.EARTH_EQUATOR
ephem = Ephem(coordinates, epochs, unused_plane)
expected_r = coordinates.get_xyz(xyz_axis=1)[0]
expected_v = coordinates.differentials["s"].get_d_xyz(xyz_axis=1)[0]
r, v = ephem.rv(epochs[0])
assert_quantity_allclose(r, expected_r)
assert_quantity_allclose(v, expected_v)
def test_plot_ephem_different_plane_raises_error():
unused_epochs = Time.now().reshape(-1)
unused_coordinates = CartesianRepresentation(
[(1, 0, 0)] * u.au,
xyz_axis=1,
differentials=CartesianDifferential([(0, 1, 0)] * (u.au / u.day), xyz_axis=1),
)
op = StaticOrbitPlotter(plane=Planes.EARTH_ECLIPTIC)
op.set_attractor(Sun)
op.set_body_frame(Earth)
with pytest.raises(ValueError) as excinfo:
op.plot_ephem(Ephem(unused_epochs, unused_coordinates, Planes.EARTH_EQUATOR))
assert (
"sample the ephemerides using a different plane or create a new plotter"
in excinfo.exconly()
)
def test_ephem_str_matches_expected_representation(epochs, coordinates):
plane = Planes.EARTH_EQUATOR
ephem = Ephem(coordinates, epochs, plane)
expected_str = (
"Ephemerides at 4 epochs "
"from 2020-03-01 12:00:00.000 (TDB) to 2020-03-04 12:00:00.000 (TDB)"
)
assert repr(ephem) == str(ephem) == expected_str
def test_ephem_sample_existing_epochs_returns_corresponding_input(
epochs, coordinates, method
):
unused_plane = Planes.EARTH_EQUATOR
ephem = Ephem(coordinates, epochs, unused_plane)
result_coordinates = ephem.sample(epochs[::2], method=method)
# Exactly the same
assert_coordinates_allclose(result_coordinates, coordinates[::2], atol_scale=1e-17)