Skip to content

Commit 17cefbb

Browse files
committed
Coverage back up to 100%
1 parent 9d29608 commit 17cefbb

File tree

1 file changed

+62
-3
lines changed

1 file changed

+62
-3
lines changed

solar_angles/test/test_solar.py

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def test_construction(self):
2828
with self.assertRaises(ValueError):
2929
Angular(degrees=180, radians=2 * 3.14)
3030

31+
def test_string(self):
32+
a = Angular(degrees=1)
33+
self.assertIsInstance(str(a), str)
34+
3135

3236
class TestDayOfYear(TestCase):
3337

@@ -107,6 +111,10 @@ def test_example_5_6_1(self):
107111
standard_meridian = Angular(degrees=90)
108112
self.assertAlmostEqual(local_civil_time(dt, dst_on, longitude, standard_meridian), 9.67, delta=0.01)
109113

114+
def test_bad_arguments(self):
115+
with self.assertRaises(ValueError):
116+
local_civil_time(datetime.now(), True, Angular(), Angular())
117+
110118

111119
class TestLocalSolarTime(TestCase):
112120

@@ -118,6 +126,10 @@ def test_example_5_6_1(self):
118126
standard_meridian = Angular(degrees=90)
119127
self.assertAlmostEqual(local_solar_time(dt, dst_on, longitude, standard_meridian), 9.43, delta=0.01)
120128

129+
def test_bad_arguments(self):
130+
with self.assertRaises(ValueError):
131+
local_solar_time(datetime.now(), True, Angular(), Angular())
132+
121133

122134
class TestHourAngle(TestCase):
123135

@@ -142,6 +154,10 @@ def test_solar_noon(self):
142154
standard_meridian = Angular(degrees=90)
143155
self.assertAlmostEqual(hour_angle(dt, dst_on, longitude, standard_meridian).degrees, 0, delta=0.1)
144156

157+
def test_bad_arguments(self):
158+
with self.assertRaises(ValueError):
159+
hour_angle(datetime.now(), True, Angular(), Angular())
160+
145161

146162
class TestAltitudeAngle(TestCase):
147163

@@ -152,8 +168,13 @@ def test_example_5_6_2(self):
152168
longitude = Angular(degrees=85)
153169
standard_meridian = Angular(degrees=90)
154170
latitude = Angular(degrees=40)
155-
self.assertAlmostEqual(altitude_angle(dt, dst_on, longitude, standard_meridian, latitude).degrees, 49.7,
156-
delta=0.1)
171+
self.assertAlmostEqual(
172+
altitude_angle(dt, dst_on, longitude, standard_meridian, latitude).degrees, 49.7, delta=0.1
173+
)
174+
175+
def test_bad_arguments(self):
176+
with self.assertRaises(ValueError):
177+
altitude_angle(datetime.now(), True, Angular(), Angular(), Angular())
157178

158179

159180
class TestAzimuthAngle(TestCase):
@@ -170,6 +191,16 @@ def test_example_5_6_2(self):
170191
self.assertAlmostEqual(azimuth_angle(dt, dst_on, longitude, standard_meridian, latitude).degrees,
171192
expected_azimuth_from_north, delta=0.1)
172193

194+
# how about an afternoon one?
195+
def test_afternoon(self):
196+
dt = datetime(2001, 7, 21, 16, 00, 00)
197+
dst_on = True
198+
longitude = Angular(degrees=85)
199+
standard_meridian = Angular(degrees=90)
200+
latitude = Angular(degrees=40)
201+
# I just made up this example to ensure the code path works, so I'm not validating it against a value
202+
self.assertTrue(azimuth_angle(dt, dst_on, longitude, standard_meridian, latitude).valued)
203+
173204
# test one with the sun down to get a null-ish response
174205
def test_sun_is_down(self):
175206
dt = datetime(2001, 3, 21, 22, 00, 00)
@@ -179,10 +210,14 @@ def test_sun_is_down(self):
179210
latitude = Angular(degrees=40)
180211
self.assertFalse(azimuth_angle(dt, dst_on, longitude, standard_meridian, latitude).valued)
181212

213+
def test_bad_arguments(self):
214+
with self.assertRaises(ValueError):
215+
azimuth_angle(datetime.now(), True, Angular(), Angular(), Angular())
216+
182217

183218
class TestWallAzimuthAngle(TestCase):
184219

185-
# test east facing wall where the solar_angles azimuth is known from a prior unit test
220+
# test south? facing wall where the solar_angles azimuth is known from a prior unit test
186221
def test_gamma_south_facing(self):
187222
dt = datetime(2001, 7, 21, 10, 00, 00)
188223
dst_on = True
@@ -198,6 +233,16 @@ def test_gamma_south_facing(self):
198233
delta=0.1
199234
)
200235

236+
# test north facing wall where the azimuth should be behind the wall
237+
def test_gamma_north_facing(self):
238+
dt = datetime(2001, 7, 21, 10, 00, 00)
239+
dst_on = True
240+
longitude = Angular(degrees=85)
241+
standard_meridian = Angular(degrees=90)
242+
latitude = Angular(degrees=40)
243+
wall_normal = Angular(degrees=270)
244+
self.assertFalse(wall_azimuth_angle(dt, dst_on, longitude, standard_meridian, latitude, wall_normal).valued)
245+
201246
# test one with the sun down to get a null-ish response
202247
def test_sun_is_down(self):
203248
dt = datetime(2001, 3, 21, 22, 00, 00)
@@ -208,6 +253,10 @@ def test_sun_is_down(self):
208253
wall_normal = Angular(degrees=90)
209254
self.assertFalse(wall_azimuth_angle(dt, dst_on, longitude, standard_meridian, latitude, wall_normal).valued)
210255

256+
def test_bad_arguments(self):
257+
with self.assertRaises(ValueError):
258+
wall_azimuth_angle(datetime.now(), True, Angular(), Angular(), Angular(), Angular())
259+
211260

212261
class TestSolarAngleOfIncidence(TestCase):
213262

@@ -252,6 +301,10 @@ def test_sun_is_down(self):
252301
solar_angle_of_incidence(dt, dst_on, longitude, standard_meridian, latitude, wall_normal).valued
253302
)
254303

304+
def test_bad_arguments(self):
305+
with self.assertRaises(ValueError):
306+
solar_angle_of_incidence(datetime.now(), True, Angular(), Angular(), Angular(), Angular())
307+
255308

256309
class TestRadiationOnSurface(TestCase):
257310

@@ -267,3 +320,9 @@ def test_direct_radiation_on_surface_south_facing(self):
267320
self.assertAlmostEqual(
268321
direct_radiation_on_surface(dt, dst_on, longitude, standard_meridian, latitude, wall_normal, insolation),
269322
insolation * cos(theta), delta=0.1)
323+
324+
def test_bad_arguments(self):
325+
with self.assertRaises(ValueError):
326+
direct_radiation_on_surface(
327+
datetime.now(), True, Angular(), Angular(), Angular(), Angular(), 1000
328+
)

0 commit comments

Comments
 (0)