annotate tests/test_web.py @ 3:49aae0c0293b

improved test coverage
author Jeff Hammel <k0scist@gmail.com>
date Sat, 24 Jun 2017 14:48:31 -0700
parents 1b94f3bf97e5
children 94af113e498a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 test web functionality
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 """
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 import os
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import unittest
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 from common import datafile
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 from globalneighbors.read import read_city_list
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 from globalneighbors.web import autocomplete
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 class WebFunctionalityTest(unittest.TestCase):
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 def test_autcomplete(self):
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 """test autocomplete underlying functionality"""
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 # read base data
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 cityfile = datafile('cities1000.txt')
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 assert os.path.exists(cityfile)
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 cities = read_city_list(cityfile)
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24 # Let's look for Chicago
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 q = u'Ch'
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 results = autocomplete(cities, q)
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 assert all([result.startswith(q)
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28 for result in results])
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29 assert sorted(results) == results
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 assert 'Chicago' in results
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
33 if __name__ == '__main__':
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
34 unittest.main()