1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
import os
from unittest import mock
import numpy as np
import pytest
from plotly.graph_objects import Figure
from einsteinpy.geodesic import Timelike
from einsteinpy.plotting import InteractiveGeodesicPlotter
@pytest.fixture()
def dummy_geod():
return Timelike(
metric="Kerr",
metric_params=(0.9,),
position=[2.15, np.pi / 2, 0.],
momentum=[0., 0., 1.5],
steps=50,
delta=0.5,
omega=0.01, # Close orbit
return_cartesian=True,
suppress_warnings=True,
)
def test_interactive_geod_plotter_has_figure(dummy_geod):
geod = dummy_geod
igpl = InteractiveGeodesicPlotter()
assert isinstance(igpl.fig, Figure)
def test_interactive_geod_plotter_draws_plot(dummy_geod):
geod = dummy_geod
igpl = InteractiveGeodesicPlotter()
igpl.plot(geod)
fig = igpl.show()
assert fig
def test_interactive_geod_plotter_draws_plot2D(dummy_geod):
geod = dummy_geod
igpl = InteractiveGeodesicPlotter()
igpl.plot2D(geod)
fig = igpl.show()
assert fig
def test_interactive_geod_plotter_plot2D_raises_error(dummy_geod):
geod = dummy_geod
igpl = InteractiveGeodesicPlotter()
try:
igpl.plot2D(geod, coordinates=(0, 2))
assert False
except IndexError:
assert True
def test_interactive_geod_plotter_draws_parametric_plot(dummy_geod):
geod = dummy_geod
igpl = InteractiveGeodesicPlotter()
igpl.parametric_plot(geod)
fig = igpl.show()
assert fig
def test_interactive_geod_plotter_parameters(dummy_geod):
geod = dummy_geod
igpl = InteractiveGeodesicPlotter(bh_colors=("#0F0", "#FAF"), draw_ergosphere=False)
assert igpl.bh_colors == ("#0F0", "#FAF")
assert igpl.draw_ergosphere is False
fig = igpl.show()
assert fig
def test_interactive_geod_plotter_show_clear(dummy_geod):
geod = dummy_geod
igpl = InteractiveGeodesicPlotter(draw_ergosphere=False)
igpl.plot(geod)
assert isinstance(igpl.show(), Figure)
igpl.clear()
assert igpl.fig.data == ()
@mock.patch("einsteinpy.plotting.geodesic.interactive.saveplot")
def test_interactive_geod_plotter_saves_plot(mock_save, dummy_geod):
geod = dummy_geod
igpl = InteractiveGeodesicPlotter()
igpl.plot(geod)
name = "test_plot.png"
igpl.save(name)
basename, ext = os.path.splitext(name)
mock_save.assert_called_with(
igpl.fig, image=ext[1:], image_filename=basename, show_link=False
)
|