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 01bf5b615a69474a9957eabeff0b96132635f0d9
parent ba67ddb69f46b3bc2c22ca54c264a9330387efed
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat,  3 Dec 2016 21:59:53 +0000

Add `generate_wiki_table` function.

* gd_diff.py (generate_wiki_table): New function.
* tests/test_gd_diff.py (test_generate_wiki_table): Test for
`generate_wiki_table` function.
(tiny_pkgs_file): New Variable.

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

diff --git a/gd_diff.py b/gd_diff.py @@ -365,3 +365,17 @@ def construct_table_row(pkg, change, reason): return '||{}||{}||{}||[[{}|more_info]]'.format(pkg, change, reason, more_info_link) + + +def generate_wiki_table(release): + """Generate and return the gNewSense Debian Diff table as a string. + """ + pkgs_noreadmes, table_data = get_wiki_page_data(release) + + wiki_table = '' + for pkg, fields in table_data.items(): + change = fields['Change-Type'] + reason = fields['Changed-From-Debian'] + wiki_table += construct_table_row(pkg, change, reason) + '\n' + + return pkgs_noreadmes, wiki_table diff --git a/tests/test_gd_diff.py b/tests/test_gd_diff.py @@ -30,6 +30,7 @@ class TestGdDiff(object): """Setup method for this class.""" self.pkgs_file = 'tests/files/parkes-pkgs.list' self.small_pkgs_file = 'tests/files/small-parkes-pkgs.list' + self.tiny_pkgs_file = 'tests/files/tiny-parkes-pkgs.list' self.pkgs_file_ne = 'tests/nonexistent-file.list' self.gns_pkgs_dir = 'tests/gns-pkgs' self.test_home = 'tests/HOME' @@ -409,6 +410,39 @@ class TestGdDiff(object): assert_equal(columns[3] , '[[http://bzr.savannah.gnu.org/lh/gnewsense/packages-parkes/antlr/annotate/head:/debian/README.gNewSense|more_info]]') + def test_generate_wiki_table(self): + def mock_mk_pkgs_list(r): + return self.tiny_pkgs_file + + pkgs = [p.strip() + for p in open(self.tiny_pkgs_file, 'r').read() \ + .split('\n')] + + expected_pkgs_noreadmes = ['pkg-with-no-readme', + 'another-pkg-no-readme'] + + with mock.patch('os.getenv', new=self.env_func), \ + mock.patch('gd_diff.mk_pkgs_list', new=mock_mk_pkgs_list): + pkgs_noreadmes, wiki_page = generate_wiki_table('parkes') + + for pkg in pkgs_noreadmes: + assert pkg in expected_pkgs_noreadmes + + pkgs = set(pkgs) - set(expected_pkgs_noreadmes) + + for row in wiki_page.split('\n')[:-1]: + cols = row.split('||')[1:] + pkg = cols[0] + + assert pkg in pkgs + assert cols[3] == '[[{}|more_info]]'.format( + bzr_pkg_readme_fmt.format(pkg)) + + pkgs.remove(pkg) + + assert len(pkgs) == 0 + + def teardown(self): """Teardown method for this class.""" if(path.exists(self.gns_pkgs_dir)):