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 5428e3ac379727e1a4d1c279b940403e5d7898b0
parent f0a75c4b3a5bf21146e28be6391786fe4478450a
Author: rsiddharth <s@ricketyspace.net>
Date:   Sun, 13 Nov 2016 20:46:16 +0000

Update all gns readme functions.

The functions, now, does not take `local_dir` as an argument.

* gd_diff.py (save_gns_readme, slurp_gns_readme, slurp_all_gns_readmes)
(read_gns_readme): Update functions.
* tests/test_gd_diff.py (test_save_gns_readme,
  test_save_gns_readme_double, test_slurp_gns_readme_success,
  test_slurp_gns_readme_error, test_slurp_all_gns_readmes,
  test_read_gns_readme): Update tests.
(test_save_gns_readme_error): Remove test.
(test_read_gns_readme_none): Add test.

Diffstat:
gd_diff.py | 26++++++++++++--------------
tests/test_gd_diff.py | 121+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
2 files changed, 84 insertions(+), 63 deletions(-)

diff --git a/gd_diff.py b/gd_diff.py @@ -114,7 +114,7 @@ def get_packages(release): return pkgs -def save_gns_readme(content, release, pkg, local_dir): +def save_gns_readme(content, release, pkg): """Save README.gNewsense locally. :param str content: @@ -123,11 +123,9 @@ def save_gns_readme(content, release, pkg, local_dir): Release name. :param str pkg: Package name. - :param str local_dir: - Root directory under which readme of all packages get stored. """ # create gns_readme dir. for pkg. - gns_readme_dir = path.join(local_dir, release, pkg, 'debian') + gns_readme_dir = path.join(readmes_dir(release), pkg, 'debian') try: os.makedirs(gns_readme_dir, exist_ok=True) @@ -141,17 +139,16 @@ def save_gns_readme(content, release, pkg, local_dir): print('Saved {}'.format(gns_readme)) -def slurp_gns_readme(release, pkg, local_dir): +def slurp_gns_readme(release, pkg): """Read and save the README.gNewSense for `pkg` in `release`. - The README.gNewSense file gets save at `local_dir`/`release`/`pkg`/debian/ """ readme_url = readme_url_fmt.format(release, pkg) cmd = 'bzr cat {}'.format(readme_url) cp = execute(cmd, out=PIPE, err=PIPE) if(cp.returncode == 0): - save_gns_readme(cp.stdout.decode(), release, pkg, local_dir) + save_gns_readme(cp.stdout.decode(), release, pkg) return True else: print("README.gNewSense not found for package {}".format(pkg), @@ -159,16 +156,14 @@ def slurp_gns_readme(release, pkg, local_dir): return False -def slurp_all_gns_readmes(release, pkgs, local_dir): +def slurp_all_gns_readmes(release, pkgs): """Read and save all README.gNewSense for `pkgs` in `release`. - The README.gNewSense files gets saved under `local_dir`/`release` - Returns list of packages in `pkgs` that does not have README.gNewSense. """ pkgs_noreadmes = [] for pkg in pkgs: - slurped = slurp_gns_readme(release, pkg, local_dir) + slurped = slurp_gns_readme(release, pkg) if(not slurped): pkgs_noreadmes.append(pkg) @@ -176,16 +171,19 @@ def slurp_all_gns_readmes(release, pkgs, local_dir): return pkgs_noreadmes -def read_gns_readme(release, pkg, local_dir): +def read_gns_readme(release, pkg): """Returns content of README.gNewSense for `pkg`. If `README.gNewSense` does not exists for `pkg`, None is returned. """ - readme_path = path.join(local_dir, release, pkg, 'debian', + readme_path = path.join(readmes_dir(release), pkg, 'debian', 'README.gNewSense') - readme_content = read_file(readme_path) + if not path.isfile(readme_path): + return None + + readme_content = read_file(readme_path) return readme_content diff --git a/tests/test_gd_diff.py b/tests/test_gd_diff.py @@ -104,86 +104,109 @@ class TestGdDiff(object): def test_save_gns_readme(self): - cmd = 'bzr cat bzr://bzr.sv.gnu.org/gnewsense/packages-parkes/antlr/debian/README.gNewSense' - cp = execute(cmd, out=subprocess.PIPE) - readme_content = cp.stdout.decode() # convert to str + def env(e): + return self.test_home - # save it - save_gns_readme(readme_content, 'parkes', 'antlr', self.gns_pkgs_dir) + with mock.patch('os.getenv', new=env): + cmd = 'bzr cat bzr://bzr.sv.gnu.org/gnewsense/packages-parkes/antlr/debian/README.gNewSense' + cp = execute(cmd, out=subprocess.PIPE) + readme_content = cp.stdout.decode() # convert to str - gns_readme_file = path.join(self.gns_pkgs_dir, 'parkes', 'antlr', 'debian', 'README.gNewSense') - with open(gns_readme_file, 'rb') as f: - assert f.read() == b'Changed-From-Debian: Removed example with non-free files.\nChange-Type: Modified\n\nFor gNewSense, the non-free unicode.IDENTs files are *actually* removed (see\nalso README.source). See gNewSense bug #34218 for details.\n' + # save it + save_gns_readme(readme_content, 'parkes', 'antlr') + gns_readme_file = path.join(self.test_home, '.config', + 'gns-deb-diff', 'readmes', + 'parkes', 'antlr', 'debian', + 'README.gNewSense') + with open(gns_readme_file, 'rb') as f: + assert f.read() == b'Changed-From-Debian: Removed example with non-free files.\nChange-Type: Modified\n\nFor gNewSense, the non-free unicode.IDENTs files are *actually* removed (see\nalso README.source). See gNewSense bug #34218 for details.\n' - def test_save_gns_readme_double(self): - cmd = 'bzr cat bzr://bzr.sv.gnu.org/gnewsense/packages-parkes/antlr/debian/README.gNewSense' - cp = execute(cmd, out=subprocess.PIPE) - readme_content = cp.stdout.decode() # convert to str - # save it twice - save_gns_readme(readme_content, 'parkes', 'antlr', self.gns_pkgs_dir) - save_gns_readme(readme_content, 'parkes', 'antlr', self.gns_pkgs_dir) + def test_save_gns_readme_double(self): + def env(e): + return self.test_home - gns_readme_file = path.join(self.gns_pkgs_dir, 'parkes', 'antlr', 'debian', 'README.gNewSense') - with open(gns_readme_file, 'rb') as f: - assert f.read() == b'Changed-From-Debian: Removed example with non-free files.\nChange-Type: Modified\n\nFor gNewSense, the non-free unicode.IDENTs files are *actually* removed (see\nalso README.source). See gNewSense bug #34218 for details.\n' + with mock.patch('os.getenv', new=env): + cmd = 'bzr cat bzr://bzr.sv.gnu.org/gnewsense/packages-parkes/antlr/debian/README.gNewSense' + cp = execute(cmd, out=subprocess.PIPE) + readme_content = cp.stdout.decode() # convert to str - @raises(SystemExit) - def test_save_gns_readme_error(self): - os.mkdir(self.gns_pkgs_dir, mode=0o500) + # save it twice + save_gns_readme(readme_content, 'parkes', 'antlr') + save_gns_readme(readme_content, 'parkes', 'antlr') - # must error out - readme_content = 'lorem ipsum' - with open(os.devnull, 'w') as sys.stderr: - save_gns_readme(readme_content, 'parkes', 'antlr', self.gns_pkgs_dir) + gns_readme_file = path.join(self.test_home, '.config', + 'gns-deb-diff', 'readmes', + 'parkes', 'antlr', 'debian', + 'README.gNewSense') + with open(gns_readme_file, 'rb') as f: + assert f.read() == b'Changed-From-Debian: Removed example with non-free files.\nChange-Type: Modified\n\nFor gNewSense, the non-free unicode.IDENTs files are *actually* removed (see\nalso README.source). See gNewSense bug #34218 for details.\n' def test_slurp_gns_readme_success(self): - saved = slurp_gns_readme('parkes', 'antlr', self.gns_pkgs_dir) - assert saved == True + def env(e): + return self.test_home - gns_readme_file = path.join(self.gns_pkgs_dir, 'parkes', - 'antlr', 'debian', - 'README.gNewSense') - with open(gns_readme_file, 'rb') as f: - assert f.read() == b'Changed-From-Debian: Removed example with non-free files.\nChange-Type: Modified\n\nFor gNewSense, the non-free unicode.IDENTs files are *actually* removed (see\nalso README.source). See gNewSense bug #34218 for details.\n' + with mock.patch('os.getenv', new=env): + saved = slurp_gns_readme('parkes', 'antlr') + assert saved == True + + gns_readme_file = path.join(self.test_home, '.config', + 'gns-deb-diff', 'readmes', + 'parkes', 'antlr', 'debian', + 'README.gNewSense') + with open(gns_readme_file, 'rb') as f: + assert f.read() == b'Changed-From-Debian: Removed example with non-free files.\nChange-Type: Modified\n\nFor gNewSense, the non-free unicode.IDENTs files are *actually* removed (see\nalso README.source). See gNewSense bug #34218 for details.\n' def test_slurp_gns_readme_error(self): - saved = slurp_gns_readme('parkes', 'non-existent-pkg', self.gns_pkgs_dir) - assert saved == False + def env(e): + return self.test_home - gns_readme_file = path.join(self.gns_pkgs_dir, 'parkes', - 'non-existent-pkg', 'debian', - 'README.gNewSense') - assert not path.exists(gns_readme_file) + with mock.patch('os.getenv', new=env): + saved = slurp_gns_readme('parkes', 'non-existent-pkg') + assert saved == False + + gns_readme_file = path.join(self.test_home, '.config', + 'gns-deb-diff', 'readmes', + 'parkes', 'non-existent-pkg', + 'debian', 'README.gNewSense') + assert not path.exists(gns_readme_file) def test_slurp_all_gns_readmes(self): - pkgs = read_packages(self.small_pkgs_file) + def env(e): + return self.test_home + + with mock.patch('os.getenv', new=env): + pkgs = read_packages(self.small_pkgs_file) - # expected packages with no readmes - expected_pkgs_noreadmes = [ - 'pkg-with-no-readme', - 'another-pkgs-no-readme', - ] + # expected packages with no readmes + expected_pkgs_noreadmes = [ + 'pkg-with-no-readme', + 'another-pkgs-no-readme', + ] - pkgs_noreadmes = slurp_all_gns_readmes('parkes', pkgs, self.gns_pkgs_dir) - assert_equal(pkgs_noreadmes, expected_pkgs_noreadmes) + pkgs_noreadmes = slurp_all_gns_readmes('parkes', pkgs) + assert_equal(pkgs_noreadmes, expected_pkgs_noreadmes) def test_read_gns_readme(self): # first download the antlr readme - saved = slurp_gns_readme('parkes', 'antlr', self.gns_pkgs_dir) + saved = slurp_gns_readme('parkes', 'antlr') assert saved - antlr_readme_content = read_gns_readme('parkes', 'antlr', self.gns_pkgs_dir) + antlr_readme_content = read_gns_readme('parkes', 'antlr') expected_antlr_readme_content = 'Changed-From-Debian: Removed example with non-free files.\nChange-Type: Modified\n\nFor gNewSense, the non-free unicode.IDENTs files are *actually* removed (see\nalso README.source). See gNewSense bug #34218 for details.\n' - assert_equal(antlr_readme_content, expected_antlr_readme_content) + def test_read_gns_readme_none(self): + readme_content = read_gns_readme('parkes', 'non-existent-pkg') + assert_equal(readme_content, None) + + def test_slurp_fields_from_readme(self): readme_content = '' field_values = slurp_fields_from_readme(readme_content)