gns-deb-diff

automate the documentation of the differences between gNewSense and Debian.
git clone git://git.ricketyspace.net/gns-deb-diff.git
Log | Files | Refs

commit 0b80b898c84b8747fe8b8ac7b485b06f7cd1e22e
parent 92b8a39ca5d48dad73c646439529e9f84a76fc78
Author: rsiddharth <s@ricketyspace.net>
Date:   Sun, 13 Nov 2016 16:42:54 +0000

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.

Diffstat:
gd_diff.py | 14++++++++++++++
tests/test_gd_diff.py | 23+++++++++++++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/gd_diff.py b/gd_diff.py @@ -6,6 +6,7 @@ # gns-deb-diff is under the Public Domain. See # <https://creativecommons.org/publicdomain/zero/1.0> +import json import os import re import shlex @@ -229,6 +230,19 @@ def config_file(): return os.path.join(config_dir(), 'config') +def read_config_file(): + """Return config as a Python Object; False when config does not \ + exist. + + """ + cf = config_file() + + if not os.path.isfile(cf): + return False + + return json.load(open(cf, 'r')) + + def pkgs_dir(): """Return the `pkgs` directory. diff --git 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 # <https://creativecommons.org/publicdomain/zero/1.0> +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