summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2013-06-15 13:42:10 +0200
committerMarkus Holtermann <info@markusholtermann.eu>2013-06-15 13:42:10 +0200
commit16f07cbd74a5499e14250c9b081a8e7fcf54eb34 (patch)
treea8b734bbde52947e6a179840a7121f3c6ffb8264
parent1f2dc7b9e92a866e88255476aae228d4522bc21c (diff)
downloadbvg-grabber-16f07cbd74a5499e14250c9b081a8e7fcf54eb34.tar.gz
bvg-grabber-16f07cbd74a5499e14250c9b081a8e7fcf54eb34.tar.bz2
bvg-grabber-16f07cbd74a5499e14250c9b081a8e7fcf54eb34.zip
Some more tests
-rw-r--r--.coveragerc4
-rw-r--r--tests/test_api.py87
-rw-r--r--tests/test_format.py1
3 files changed, 59 insertions, 33 deletions
diff --git a/.coveragerc b/.coveragerc
index dc4fd82..52623dc 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -1,2 +1,4 @@
[run]
-source=bvggrabber
+branch = True
+source = bvggrabber/
+omit = bvggrabber/__init__.py
diff --git a/tests/test_api.py b/tests/test_api.py
index b96d6b8..6db8e0d 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -44,6 +44,21 @@ class TestFunctions(unittest.TestCase):
class TestResponse(unittest.TestCase):
+ def test_init_ambiguous(self):
+ response = Response(False, ['s1', 's2'])
+ self.assertFalse(response.state)
+ self.assertEqual(str(response.error), "Station is ambiguous: s1, s2")
+
+ def test_init_not_found(self):
+ response = Response(False)
+ self.assertFalse(response.state)
+ self.assertEqual(str(response.error), "Station does not exist")
+
+ def test_init_error_string(self):
+ response = Response(False, error="An error occurred")
+ self.assertFalse(response.state)
+ self.assertEqual(str(response.error), "An error occurred")
+
def test_merge(self):
departures = [Departure("ERP", "HBF",
datetime.datetime(2013, 1, 2, 3, 4, 1), "U2"),
@@ -64,6 +79,37 @@ class TestResponse(unittest.TestCase):
r1.merge(r2)
self.assertEqual(r1.departures, allDepartures)
+ def test_json_success(self):
+ since = datetime.datetime(2013, 1, 2, 3, 0, 0)
+ departures = [Departure("ZOO", "HBF",
+ datetime.datetime(2013, 1, 2, 3, 4, 0), "S5",
+ since=since),
+ Departure("ZOO", "ERP",
+ datetime.datetime(2013, 1, 2, 3, 5, 0), "U2",
+ since=since)]
+ json1 = [['ZOO', [{
+ 'start': 'ZOO',
+ 'line': 'S5',
+ 'end': 'HBF',
+ 'remaining': 240,
+ }, {
+ 'start': 'ZOO',
+ 'line': 'U2',
+ 'end': 'ERP',
+ 'remaining': 300,
+ },
+ ]]]
+ response = Response(True, "ZOO", departures)
+ self.assertEqual(json.loads(response.json), json1)
+
+ def test_json_failure(self):
+ response = Response(False, ['ERP', 'ZOO'])
+ self.assertEqual(response.json, json.dumps("Station is ambiguous: ERP, ZOO"))
+
+ def test_departures_failure(self):
+ response = Response(False, ['ERP', 'ZOO'])
+ self.assertEqual(response.departures, "Station is ambiguous: ERP, ZOO")
+
class TestQueryApi(unittest.TestCase):
@@ -199,38 +245,6 @@ class TestDeparture(BaseTestDeparture):
self.assertIsInstance(Departure("from", "to", "16:15\n \t*", "line"),
Departure)
- @unittest.skip("removed json from object")
- def test_json(self):
- json1 = {'start': "From My Station",
- 'end': "To Your Station",
- 'line': "A Line",
- 'now_full': "2013-01-02 03:04:00",
- 'now_hour': "03:04",
- 'when_full': "2013-01-02 03:04:45",
- 'when_hour': "03:04",
- 'remaining': 0}
- dep1 = Departure("From My Station", "To Your Station",
- self.since + self.delta1, "A Line", since=self.since)
- self.assertEqual(json1, json.loads(dep1.to_json))
- str1 = "Start: From My Station, End: To Your Station, when: 03:04, " \
- "now: 03:04, line: A Line"
- self.assertEqual(str1, str(dep1))
-
- json2 = {'start': "From My Station",
- 'end': "To Your Station",
- 'line': "A Line",
- 'now_full': "2013-01-02 03:04:00",
- 'now_hour': "03:04",
- 'when_full': "2013-01-02 03:05:20",
- 'when_hour': "03:05",
- 'remaining': 60}
- dep2 = Departure("From My Station", "To Your Station",
- self.since + self.delta2, "A Line", since=self.since)
- self.assertEqual(json2, json.loads(dep2.to_json))
- str2 = "Start: From My Station, End: To Your Station, when: 03:05, " \
- "now: 03:04, line: A Line"
- self.assertEqual(str2, str(dep2))
-
def test_regression_new_day(self):
now = datetime.datetime(2013, 1, 2, 23, 59, 0)
@@ -259,6 +273,15 @@ class TestDeparture(BaseTestDeparture):
no_add_day=True)
self.assertEqual(departure.remaining, -43260)
+ def test_str(self):
+ now = datetime.datetime(2013, 1, 2, 12, 13, 0)
+ dep = datetime.datetime(2013, 1, 2, 12, 15, 0)
+ departure = Departure("From My Station", "To Your Station", dep,
+ "A Line", since=now)
+ string = 'Start: From My Station, End: To Your Station, when: 12:15, now: 12:13, line: A Line'
+ self.assertEqual(str(departure), string)
+ self.assertEqual(repr(departure), string)
+
class TestDepartureTotalOrder(unittest.TestCase):
diff --git a/tests/test_format.py b/tests/test_format.py
index 53966e1..7d936c5 100644
--- a/tests/test_format.py
+++ b/tests/test_format.py
@@ -17,6 +17,7 @@ class TestFormats(unittest.TestCase):
(0b1100011, 7, '1100011')]
for b, l, s in nums:
self.assertEqual(int2bin(b, l), s)
+ self.assertRaises(ValueError, int2bin, 12, 'abc')
def test_datetime_formats(self):
f = [(datetime.datetime(2013, 1, 2, 3, 4, 0),