From 34c29fee135803154c6bb494d908b98067f028e2 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Tue, 24 Apr 2012 01:43:03 +0200 Subject: Added -o parameter for output to the specified file. --- test/test_json_diff.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test') diff --git a/test/test_json_diff.py b/test/test_json_diff.py index cb2e878..d7c16e3 100644 --- a/test/test_json_diff.py +++ b/test/test_json_diff.py @@ -2,8 +2,10 @@ """ PyUnit unit tests """ +from __future__ import print_function import unittest import sys +import tempfile import locale try: import json @@ -215,6 +217,27 @@ class TestMainArgsMgmt(unittest.TestCase): "\n\nexpected = %d\n\nobserved = %d" % (1, res)) + def test_args_run_output(self): + save_stdout = tempfile.NamedTemporaryFile(prefix="json_diff_") + cur_loc = locale.getlocale() + locale.setlocale(locale.LC_ALL, "cs_CZ.utf8") + + res = json_diff.main(["./test_json_diff.py", + "-o", save_stdout.name, + "test/old.json", "test/new.json"]) + + expected_file = open("test/diff.json") + expected = expected_file.read() + + save_stdout.seek(0) + observed = save_stdout.read() + save_stdout.close() + + locale.setlocale(locale.LC_ALL, cur_loc) + self.assertEqual(expected, observed, "non-stdout output file" + + "\n\nexpected = %s\n\nobserved = %s" % + (expected, observed)) + add_tests_from_class = unittest.TestLoader().loadTestsFromTestCase suite = unittest.TestSuite() -- cgit