Skip to content

Commit 501aee1

Browse files
committed
Use bib.show() not .to_text() which requires ads; reformat code
1 parent 1fab495 commit 501aee1

2 files changed

Lines changed: 161 additions & 136 deletions

File tree

sbpy/data/tests/test_obs_remote.py

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,91 +17,109 @@ class TestObsfromMPC:
1717

1818
def test_simple(self):
1919
# asteroid
20-
data = Obs.from_mpc('12893')
20+
data = Obs.from_mpc("12893")
2121
assert len(data) >= 1605
2222

2323
# comet
24-
data = Obs.from_mpc('235P')
24+
data = Obs.from_mpc("235P")
2525
assert len(data) >= 274
2626

2727
def test_manual_idtypes(self):
28-
data = Obs.from_mpc('12893', id_type='asteroid number')
28+
data = Obs.from_mpc("12893", id_type="asteroid number")
2929
assert len(data) >= 1605
3030

31-
data = Obs.from_mpc('1998 QS55', id_type='asteroid designation')
31+
data = Obs.from_mpc("1998 QS55", id_type="asteroid designation")
3232
assert len(data) >= 46
3333

34-
data = Obs.from_mpc('2019 AA', id_type='asteroid designation')
34+
data = Obs.from_mpc("2019 AA", id_type="asteroid designation")
3535
assert len(data) >= 33
3636

3737
# comet
38-
data = Obs.from_mpc('235P', id_type='comet number')
38+
data = Obs.from_mpc("235P", id_type="comet number")
3939
assert len(data) >= 274
4040

41-
data = Obs.from_mpc('P/2010 F2', id_type='comet designation')
41+
data = Obs.from_mpc("P/2010 F2", id_type="comet designation")
4242
assert len(data) >= 35
4343

4444
def test_break(self):
4545
with pytest.raises(QueryError):
46-
Obs.from_mpc('2019 AA345', id_type='asteroid designation')
46+
Obs.from_mpc("2019 AA345", id_type="asteroid designation")
4747

4848
def test_bib(self):
4949
bib.track()
50-
Obs.from_mpc('235P')
51-
assert 'sbpy.data.obs.Obs.from_mpc' in bib.to_text()
50+
Obs.from_mpc("235P")
51+
assert "sbpy.data.obs.Obs.from_mpc" in bib.show()
5252

5353

5454
@pytest.mark.remote_data
5555
class TestSupplement:
5656

5757
def test_jplhorizons(self):
5858
bib.track()
59-
obs = Obs.from_dict({'epoch': Time([2451200, 2451201], format='jd'),
60-
'mag': [12, 13]*u.mag,
61-
'targetname': ['3552', '3552']})
62-
data = obs.supplement(service='jplhorizons', modify_fieldnames='obs')
59+
obs = Obs.from_dict(
60+
{
61+
"epoch": Time([2451200, 2451201], format="jd"),
62+
"mag": [12, 13] * u.mag,
63+
"targetname": ["3552", "3552"],
64+
}
65+
)
66+
data = obs.supplement(service="jplhorizons", modify_fieldnames="obs")
6367
assert len(data.field_names) > len(obs.field_names)
64-
assert 'targetname_obs' in data.field_names
68+
assert "targetname_obs" in data.field_names
6569

66-
data = obs.supplement(service='jplhorizons', modify_fieldnames='eph')
70+
data = obs.supplement(service="jplhorizons", modify_fieldnames="eph")
6771
assert len(data.field_names) > len(obs.field_names)
68-
assert 'targetname_eph' in data.field_names
72+
assert "targetname_eph" in data.field_names
6973

70-
assert 'sbpy.data.ephem.core.Ephem.from_horizons' in bib.to_text()
74+
assert "sbpy.data.ephem.core.Ephem.from_horizons" in bib.show()
7175

7276
def test_mpc(self):
7377
bib.track()
74-
obs = Obs.from_dict({'epoch': Time([2451200, 2451201], format='jd'),
75-
'mag': [12, 13]*u.mag,
76-
'targetname': ['3552', '3552']})
77-
data = obs.supplement(service='mpc')
78+
obs = Obs.from_dict(
79+
{
80+
"epoch": Time([2451200, 2451201], format="jd"),
81+
"mag": [12, 13] * u.mag,
82+
"targetname": ["3552", "3552"],
83+
}
84+
)
85+
data = obs.supplement(service="mpc")
7886
assert len(data.field_names) > len(obs.field_names)
7987

80-
assert 'sbpy.data.ephem.core.Ephem.from_mpc' in bib.to_text()
88+
assert "sbpy.data.ephem.core.Ephem.from_mpc" in bib.show()
8189

8290
def test_miriade(self):
8391
bib.track()
84-
obs = Obs.from_dict({'epoch': Time([2451200, 2451201], format='jd'),
85-
'mag': [12, 13]*u.mag,
86-
'targetname': ['3552', '3552']})
87-
data = obs.supplement(service='miriade')
92+
obs = Obs.from_dict(
93+
{
94+
"epoch": Time([2451200, 2451201], format="jd"),
95+
"mag": [12, 13] * u.mag,
96+
"targetname": ["3552", "3552"],
97+
}
98+
)
99+
data = obs.supplement(service="miriade")
88100
assert len(data.field_names) > len(obs.field_names)
89101

90-
assert 'sbpy.data.ephem.core.Ephem.from_miriade' in bib.to_text()
102+
assert "sbpy.data.ephem.core.Ephem.from_miriade" in bib.show()
91103

92104
def test_breaks(self):
93-
obs = Obs.from_dict({'epoch': Time([2451200, 2451201], format='jd'),
94-
'mag': [12, 13]*u.mag,
95-
'targetname': ['3552', '3552']})
105+
obs = Obs.from_dict(
106+
{
107+
"epoch": Time([2451200, 2451201], format="jd"),
108+
"mag": [12, 13] * u.mag,
109+
"targetname": ["3552", "3552"],
110+
}
111+
)
96112

97113
with pytest.raises(QueryError):
98-
obs.supplement(service='this will not work')
114+
obs.supplement(service="this will not work")
99115

100116
def test_multiple_jplhorizons(self):
101-
obs = Obs.from_dict({'epoch': Time([2451200, 2451201,
102-
2451200, 2451201], format='jd'),
103-
'mag': [12, 13, 16, 17]*u.mag,
104-
'targetname': ['3552', '3552',
105-
'12893', '12893']})
106-
data = obs.supplement(service='jplhorizons', modify_fieldnames='obs')
107-
assert len(set(data['targetname'])) == 2
117+
obs = Obs.from_dict(
118+
{
119+
"epoch": Time([2451200, 2451201, 2451200, 2451201], format="jd"),
120+
"mag": [12, 13, 16, 17] * u.mag,
121+
"targetname": ["3552", "3552", "12893", "12893"],
122+
}
123+
)
124+
data = obs.supplement(service="jplhorizons", modify_fieldnames="obs")
125+
assert len(set(data["targetname"])) == 2

0 commit comments

Comments
 (0)