-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
83 lines (56 loc) · 2.32 KB
/
tests.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import datetime
import unittest
from tmgpm import Tmgpm
class TestTmgpmDefaultConstructor(unittest.TestCase):
def setUp(self):
self.tide = Tmgpm()
def test_default_station(self):
# check default station name is BREST
self.assertEqual(self.tide.station_name, 'BREST')
def test_default_date(self):
# check default date is today
today = datetime.date.today()
self.assertEqual(datetime.date(self.tide.year, self.tide.month, self.tide.day), today)
class TestTmgpmConstructor(unittest.TestCase):
def setUp(self):
self.tide = Tmgpm('CONCARNEAU', 2014, 1, 1)
def test_default_station(self):
# check station name is properly set
self.assertEqual(self.tide.station_name, 'CONCARNEAU')
def test_default_date(self):
# check date is properly set
self.assertEqual(self.tide.year, 2014)
self.assertEqual(self.tide.month, 1)
self.assertEqual(self.tide.day, 1)
class TestTmgpmSetDate(unittest.TestCase):
def setUp(self):
self.tide = Tmgpm()
def test_date_before_1900(self):
# check that a date before 1/1/1900 before is refused
self.assertRaises(ValueError, self.tide.set_date, 1899, 12, 31)
def test_date_after_2100(self):
# check default date is today
self.assertRaises(ValueError, self.tide.set_date, 2100, 3, 1)
class TestTmgpmGetStationList(unittest.TestCase):
def test_returns_a_list(self):
# check we get a list
station_list = Tmgpm.get_station_list()
self.assertTrue(isinstance(station_list, list))
def test_list_is_not_empty(self):
# check the list is not empty
station_list = Tmgpm.get_station_list()
self.assertTrue(len(station_list) > 0)
def test_list_contains_brest(self):
# check the list contains at least BREST station
station_list = Tmgpm.get_station_list()
self.assertTrue('BREST' in station_list)
class TestTmgpmHarmonicConstituents(unittest.TestCase):
def test_concarneau_1982(self):
# Check that tide heigh in CONCARNEAU on the 1st January 1982
# at 00:00 is 2302 mm
tide = Tmgpm('CONCARNEAU', 1982, 1, 1)
self.assertEqual(int(tide.height(0)), 2302)
if __name__ == '__main__':
unittest.main()