Skip to content

Commit

Permalink
Tests: break out tests into smaller chunks
Browse files Browse the repository at this point in the history
Although this adds three tests, it doesn't really improve on how much is tested.
It simply breaks the existing ones up into more manageable and readable tests.
  • Loading branch information
guyfawcus committed Nov 11, 2017
1 parent b6b1cce commit d4903da
Showing 1 changed file with 57 additions and 4 deletions.
61 changes: 57 additions & 4 deletions tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import logging
import pickle
import unittest

import archmap
Expand All @@ -8,16 +9,68 @@
archmap.log.setLevel(logging.CRITICAL)


class WikiParserTestCase(unittest.TestCase):
"""These tests test the wiki parser in the get_users() function
"""

# 'ArchMap_List-stripped.html' is a stripped down page of HTML
# including the tags needed for parsing and some test data
wiki_html = 'tests/ArchMap_List-stripped.html'

# 'raw_users.txt' contains the extracted list from 'ArchMap_List-stripped.html'
# The trailing newline needs to be stripped to match the output from 'get_users'
with open('tests/raw_users.txt', 'r') as raw_users:
raw_users = raw_users.read().rstrip('\n')

def setUp(self):
# Set 'maxDiff' to 'None' to be able to see long diffs when something goes wrong.
self.maxDiff = None

def test_wiki_parser(self):
output_get_users = archmap.get_users(local=self.wiki_html)
self.assertEqual(self.raw_users, output_get_users)


class ListParserTestCase(unittest.TestCase):
"""These tests test that the list parser is working correctly
"""

# 'raw_users.txt' contains an unformatted 'raw' sample list
with open('tests/raw_users.txt', 'r') as raw_users_file:
raw_users = raw_users_file.read()

# 'sample_users.txt' contains a formatted sample list equivilent to the raw version above
with open('tests/sample-archmap_users.txt', 'r') as sample_users_file:
sample_users = sample_users_file.read()

# 'sample_parsed_users.pickle' is a pickled list that was generated with a known good list
# ('get_users' was run on 'sample_users.txt' and the output was pickled)
with open('tests/sample_parsed_users.pickle', 'rb') as pickled_input:
sample_parsed_users = pickle.load(pickled_input)

def setUp(self):
# Set 'maxDiff' to 'None' to be able to see long diffs when something goes wrong.
self.maxDiff = None

def test_list_parser_raw(self):
parsed_raw_users = archmap.parse_users(self.raw_users)
self.assertEqual(parsed_raw_users, self.sample_parsed_users)

def test_list_parser_cleaned(self):
parsed_cleaned_users = archmap.parse_users(self.sample_users)
self.assertEqual(parsed_cleaned_users, self.sample_parsed_users)


class OutputTestCase(unittest.TestCase):
"""These tests compare the output of ``make_geojson()``, ``make_kml()`` and ``make csv()``
with pre-generated versions that have been checked manually, these *sample* files were
generated by runing ``archmap.py`` on the stripped-down/handmade ``ArchMap_List-stripped.html'``.
"""
# with open('tests/raw_users.txt', 'r') as raw_users:
# parsed_users = archmap.parse_users(raw_users.read())

users = archmap.get_users(local='tests/ArchMap_List-stripped.html')
parsed_users = archmap.parse_users(users)
# 'sample_parsed_users.pickle' is a pickled list that was generated with a known good list
# ('get_users' was run on 'sample_users.txt' and the output was pickled)
with open('tests/sample_parsed_users.pickle', 'rb') as pickled_input:
parsed_users = pickle.load(pickled_input)

def setUp(self):
self.sample_users = 'tests/sample-archmap_users.txt'
Expand Down

0 comments on commit d4903da

Please sign in to comment.