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 e2e157cfc3286a291e64121bf1422faf85094880
parent fac05f29bbd7a7bbddb9de828b502c40e40e2a4e
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat, 24 Sep 2016 20:05:14 +0000

add gd_diff.py + tests for functions in it.

* gd_diff.py (read_file, get_packages): add functions.
* tests/__init__.py: add file.
* tests/files/pkgs.list: add file.
* tests/test_gd_diff.py: add file.

Diffstat:
gd_diff.py | 39+++++++++++++++++++++++++++++++++++++++
tests/__init__.py | 0
tests/files/pkgs.list | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/test_gd_diff.py | 48++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 170 insertions(+), 0 deletions(-)

diff --git a/gd_diff.py b/gd_diff.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# This file is part of gns-deb-diff. +# +# gns-deb-diff is under the Public Domain. See +# <https://creativecommons.org/publicdomain/zero/1.0> + +import sys + +# list of recognized fields. +field_list = [ + "Change-Type", + "Changed-From-Debian", +] + +def read_file(fpath): + """Read file `f` and return its content. + + """ + try: + f = open(fpath, 'r') + except FileNotFoundError as e: + print("Error opening '%s' \n Error Info:\n %r" % (fpath, e), + file=sys.stderr) + sys.exit(1) + + return f.read() + + +def get_packages(pkgs_file): + """Return an iterator contaning of package names from `pkgs_file`. + + """ + pkgs = read_file(pkgs_file).split('\n') + # sanitize + pkgs_iter = map(lambda x: x.strip(), pkgs) + + return pkgs_iter diff --git a/tests/__init__.py b/tests/__init__.py diff --git a/tests/files/pkgs.list b/tests/files/pkgs.list @@ -0,0 +1,82 @@ +antlr +apt +apt-setup +autoconf +autoconf2.59 +autoconf2.64 +bacula +base-files +base-installer +batik +cairomm +cdebootstrap +cfitsio3 +choose-mirror +claws-mail +db4.6 +db4.7 +db4.8 + debian-cd +debian-edu +debian-installer +debian-installer-launcher +debootstrap +desktop-base +doc-linux +doc-linux-hr +doc-linux-it +doc-linux-ja +doc-linux-pl +enscript +epiphany-browser +fop +freetype +galaxia +gdm3 +glibmm2.4 +gnewsense-archive-keyring +gnome-desktop +gtkmm2.4 +icedove +iceweasel +kde4libs +kdebase +kdebase-workspace +kdenetwork +kernel-wedge +lensfun +liferea +lintian +linux-2.6 +linux-kernel-di-amd64-2.6 +linux-kernel-di-i386-2.6 +linux-latest-2.6 +live-build +live-config +meta-gnome2 +mplayer +net-retriever +objcryst-fox +openoffice.org +pangomm +perl-tk +pkgsel +popularity-contest +psutils +python-apt +screenlets +sip4-qt3 +software-center +tcl8.4 +tcl8.5 +texlive-extra +tk8.4 +tk8.5 +update-manager +vim +wmaker +xchat +xdm +xorg-server +xserver-xorg-video-siliconmotion +yeeloong-base+ \ No newline at end of file diff --git a/tests/test_gd_diff.py b/tests/test_gd_diff.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# This file is part of gns-deb-diff. +# +# gns-deb-diff is under the Public Domain. See +# <https://creativecommons.org/publicdomain/zero/1.0> + +import os +import sys + +from nose.tools import * + +from gd_diff import * + +class TestGdDiff(object): + + def setup(self): + """Setup method for this class.""" + self.pkgs_file = "tests/files/pkgs.list" + self.pkgs_file_ne = 'tests/nonexistent-file.list' + + def test_read_file_success(self): + f_content = read_file(self.pkgs_file) + + assert isinstance(f_content, str) + assert_equal(len(f_content.split('\n')), 82) + + @raises(SystemExit) + def test_read_file_error(self): + with open(os.devnull, 'w') as sys.stderr: + f_content = read_file(self.pkgs_file_ne) + + + def test_get_packages(self): + pkgs_iter = get_packages(self.pkgs_file) + assert len(list(pkgs_iter)) == 82 + + def test_get_packages_sanity(self): + pkgs_iter = get_packages(self.pkgs_file) + + for pkg in pkgs_iter: + assert not ' ' in pkg + + def teardown(self): + """Teardown method for this class.""" + pass +