From d53e415153aa3b4ced16e247269004ab10da44dd Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 13 Feb 2016 12:20:07 -0500 Subject: Introduced JSON utils. json_read and json_write --- tests/test_lps_gen.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'tests') diff --git a/tests/test_lps_gen.py b/tests/test_lps_gen.py index ad66aa9..00b21ef 100644 --- a/tests/test_lps_gen.py +++ b/tests/test_lps_gen.py @@ -19,11 +19,13 @@ # . import json +import os import pprint import mistune import mock +from collections import OrderedDict from os import path from StringIO import StringIO @@ -31,6 +33,83 @@ from nose.tools import * from lps_gen import * + +class TestJSONUtils(object): + """Class that tests json utils in `lps_gen` module. + """ + @classmethod + def setup_class(self): + """Runs before running any tests in this class.""" + self.speakers_ids = OrderedDict({ + unicode('Daniel Kahn Gillmor'): 'gillmor', + unicode('Edward Snowden'): 'snowden', + unicode('Richard Stallman'): 'stallman', + unicode('Clara Snowden'): 'clara_snowden', + unicode('Ludovic Courtès'): 'courtes', + unicode('Jonas Öberg'): 'aberg', + }) + self.ids_filename = 'speakers.ids' + + self.speakers_noids = [ + unicode('Daniel Kahn Gillmor'), + unicode('Richard Stallman'), + unicode('Ludovic Courtès'), + unicode('Jonas Öberg'), + ] + self.noids_filename = 'speakers.noids' + + # Change current working directory to the tests directory. + self.old_cwd = os.getcwd() + os.chdir('tests') + + + def setup(self): + """Runs before each test in this class.""" + pass + + + def test_json_write(self): + """Testing json_write function.""" + json_write(self.ids_filename, self.speakers_ids) + assert_equal(json.loads(read_file(self.ids_filename), + object_pairs_hook=OrderedDict), + self.speakers_ids) + + json_write(self.noids_filename, self.speakers_noids) + assert_equal(json.loads(read_file(self.noids_filename), + object_pairs_hook=OrderedDict), + self.speakers_noids) + + + def test_json_read(self): + """Testing json_read function.""" + write_file(self.ids_filename, json.dumps(self.speakers_ids, + indent=4)) + assert_equal(json_read(self.ids_filename), self.speakers_ids) + + write_file(self.noids_filename, json.dumps(self.speakers_noids, + indent=4)) + assert_equal(json_read(self.noids_filename), self.speakers_noids) + + + def teardown(self): + """Cleans up things after each test in this class.""" + # Remove `speaker.ids` file if it exists. + if path.isfile(self.ids_filename): + os.remove(self.ids_filename) + + # Remove `speaker.noids` file if it exists. + if path.isfile(self.noids_filename): + os.remove(self.noids_filename) + + + @classmethod + def teardown_class(self): + """Purge the mess created by this test.""" + # Change back to the old cwd + os.chdir(self.old_cwd) + + class TestLPS(object): """ Class that tests everything related LP Schedule. -- cgit v1.2.3