Skip to content

Commit

Permalink
Merge pull request #425 from sidmttl/master
Browse files Browse the repository at this point in the history
Updated: test_coord_transform and test_velocity_transform with unittests
  • Loading branch information
ritzvik committed Feb 14, 2020
2 parents 090b195 + 2f7f285 commit 20c61ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
18 changes: 6 additions & 12 deletions src/einsteinpy/tests/test_coordinates/test_coord_transform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from io import StringIO
from unittest import mock

import astropy.units as u
import numpy as np
Expand Down Expand Up @@ -137,23 +138,16 @@ def test_cartesian_dot():
# Tests for object.__repr__ and object.__str__


def test_print_core_objects(cartesian, spherical, boyerlindquist):
old_stdout = sys.stdout
# change stdout
result = StringIO()
sys.stdout = result

@mock.patch("sys.stdout", new_callable=StringIO)
def test_print_core_objects(mock_stdout, cartesian, spherical, boyerlindquist):
print(str(cartesian))
assert "object at 0x" not in result.getvalue()
assert "object at 0x" not in mock_stdout.getvalue()

print(str(spherical))
assert "object at 0x" not in result.getvalue()
assert "object at 0x" not in mock_stdout.getvalue()

print(str(boyerlindquist))
assert "object at 0x" not in result.getvalue()

# again switch to old stdout
sys.stdout = old_stdout
assert "object at 0x" not in mock_stdout.getvalue()


def test_coordinate_subscripting(cartesian, spherical, boyerlindquist):
Expand Down
18 changes: 6 additions & 12 deletions src/einsteinpy/tests/test_coordinates/test_velocity_transform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from io import StringIO
from unittest import mock

import astropy.units as u
import numpy as np
Expand Down Expand Up @@ -134,25 +135,18 @@ def test_cycle_BLCartesianDifferential(bl_differential2):
# Tests for object.__repr__ and object.__str__


@mock.patch("sys.stdout", new_callable=StringIO)
def test_print_core_objects(
cartesian_differential, spherical_differential, bl_differential
mock_stdout, cartesian_differential, spherical_differential, bl_differential
):
old_stdout = sys.stdout
# change stdout
result = StringIO()
sys.stdout = result

print(str(cartesian_differential))
assert "object at 0x" not in result.getvalue()
assert "object at 0x" not in mock_stdout.getvalue()

print(str(spherical_differential))
assert "object at 0x" not in result.getvalue()
assert "object at 0x" not in mock_stdout.getvalue()

print(str(bl_differential))
assert "object at 0x" not in result.getvalue()

# again switch to old stdout
sys.stdout = old_stdout
assert "object at 0x" not in mock_stdout.getvalue()


# Tests for object.velocities()
Expand Down

0 comments on commit 20c61ca

Please sign in to comment.