From 0b80b898c84b8747fe8b8ac7b485b06f7cd1e22e Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sun, 13 Nov 2016 16:42:54 +0000 Subject: Add `read_config_file` function. * gd_diff.py (read_config_file): New function. * tests/test_gd_diff.py (test_read_config_file_fail) (test_read_config_file_success): Tests for read_config_file. --- tests/test_gd_diff.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/test_gd_diff.py') diff --git a/tests/test_gd_diff.py b/tests/test_gd_diff.py index cc7fc4a..67d9b8d 100644 --- a/tests/test_gd_diff.py +++ b/tests/test_gd_diff.py @@ -6,6 +6,7 @@ # gns-deb-diff is under the Public Domain. See # +import json import os import subprocess import sys @@ -247,6 +248,28 @@ class TestGdDiff(object): 'gns-deb-diff', 'config')) + def test_read_config_file_fail(self): + config = read_config_file() + assert_equal(config, False) + + + def test_read_config_file_success(self): + def env(e): + return self.test_home + + with mock.patch('os.getenv', new=env): + c_file = config_file() + + # first write sample config file. + json.dump({'user': 'usrnm', 'pass': 'weasaspeciesrfckd'}, + open(c_file, 'w')) + + # now on to the test. + config = read_config_file() + assert_equal(config['user'], 'usrnm') + assert_equal(config['pass'], 'weasaspeciesrfckd') + + def test_pkgs_dir(self): def env(e): return self.test_home -- cgit v1.2.3