From 0032ccbd60f202ec76d9b738cddc8bdbf9f54133 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Tue, 31 Jul 2012 12:52:12 +0000 Subject: python scripts: pep8ize codebase This was done with the aid of the pep8 script, available by running `easy_install pep8`. It may be worth making this part of ./check, but that will require putting pep8 into the development tools stratum. This should be easy, given pep8 has no external dependencies. --- morphlib/bins_tests.py | 51 ++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'morphlib/bins_tests.py') diff --git a/morphlib/bins_tests.py b/morphlib/bins_tests.py index df020e0c..3288207b 100644 --- a/morphlib/bins_tests.py +++ b/morphlib/bins_tests.py @@ -1,14 +1,14 @@ # Copyright (C) 2011-2012 Codethink Limited -# +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. @@ -29,22 +29,22 @@ class BinsTest(unittest.TestCase): def recursive_lstat(self, root): '''Return a list of (pathname, stat) pairs for everything in root. - + Pathnames are relative to root. Directories are recursed into. The stat result is selective, not all fields are used. - + ''' - + def remove_root(pathname): self.assertTrue(pathname.startswith(root)) if pathname == root: return '.' else: - return pathname[len(root)+1:] - + return pathname[(len(root) + 1):] + def lstat(filename): st = os.lstat(filename) - + # For directories, the size is dependent on the contents, and # possibly on things that have been deleted already. An unpacked # directory can be identical even if the size field is different. @@ -59,16 +59,16 @@ class BinsTest(unittest.TestCase): return (st.st_mode, 0, 0) else: return (st.st_mode, st.st_size, 0) - + result = [] - + for dirname, subdirs, basenames in os.walk(root): result.append((remove_root(dirname), lstat(dirname))) for basename in sorted(basenames): filename = os.path.join(dirname, basename) result.append((remove_root(filename), lstat(filename))) subdirs.sort() - + return result @@ -80,7 +80,7 @@ class ChunkTests(BinsTest): self.chunk_file = os.path.join(self.tempdir, 'chunk') self.chunk_f = open(self.chunk_file, 'wb') self.unpacked = os.path.join(self.tempdir, 'unpacked') - + def tearDown(self): self.chunk_f.close() shutil.rmtree(self.tempdir) @@ -89,7 +89,7 @@ class ChunkTests(BinsTest): timestamp = 12765 os.mkdir(self.instdir) - + bindir = os.path.join(self.instdir, 'bin') os.mkdir(bindir) filename = os.path.join(bindir, 'foo') @@ -114,26 +114,27 @@ class ChunkTests(BinsTest): def unpack_chunk(self): os.mkdir(self.unpacked) morphlib.bins.unpack_binary(self.chunk_file, self.unpacked) - + def test_empties_everything(self): self.create_chunk(['.']) - self.assertEqual([x for x,y in self.recursive_lstat(self.instdir)], + self.assertEqual([x for x, y in self.recursive_lstat(self.instdir)], ['.']) def test_creates_and_unpacks_chunk_exactly(self): self.create_chunk(['.']) self.unpack_chunk() - self.assertEqual(self.instdir_orig_files, + self.assertEqual(self.instdir_orig_files, self.recursive_lstat(self.unpacked)) def test_uses_only_matching_names(self): self.create_chunk(['bin']) self.unpack_chunk() - self.assertEqual([x for x,y in self.recursive_lstat(self.unpacked)], + self.assertEqual([x for x, y in self.recursive_lstat(self.unpacked)], ['.', 'bin', 'bin/foo']) - self.assertEqual([x for x,y in self.recursive_lstat(self.instdir)], + self.assertEqual([x for x, y in self.recursive_lstat(self.instdir)], ['.', 'lib', 'lib/libfoo.so']) + class ExtractTests(unittest.TestCase): def setUp(self): @@ -156,13 +157,15 @@ class ExtractTests(unittest.TestCase): def test_extracted_files_replace_links(self): def make_linkfile(basedir): - with open(os.path.join(basedir, 'babar'), 'w') as f: pass + with open(os.path.join(basedir, 'babar'), 'w') as f: + pass os.symlink('babar', os.path.join(basedir, 'bar')) return ['.'] linktar = self.create_chunk(make_linkfile) def make_file(basedir): - with open(os.path.join(basedir, 'bar'), 'w') as f: pass + with open(os.path.join(basedir, 'bar'), 'w') as f: + pass return ['.'] filetar = self.create_chunk(make_file) @@ -177,7 +180,7 @@ class ExtractTests(unittest.TestCase): os.symlink('.', os.path.join(basedir, 'usr')) return ['.'] linktar = self.create_chunk(make_usrlink) - + def make_usrdir(basedir): os.mkdir(os.path.join(basedir, 'usr')) return ['.'] @@ -196,7 +199,8 @@ class ExtractTests(unittest.TestCase): def make_usrdir(basedir): os.mkdir(os.path.join(basedir, 'usr')) - with open(os.path.join(basedir, 'usr', 'foo'), 'w') as f: pass + with open(os.path.join(basedir, 'usr', 'foo'), 'w') as f: + pass return ['.'] dirtar = self.create_chunk(make_usrdir) @@ -204,4 +208,3 @@ class ExtractTests(unittest.TestCase): morphlib.bins.unpack_binary_from_file(dirtar, self.unpacked) mode = os.lstat(os.path.join(self.unpacked, 'foo')).st_mode self.assertTrue(stat.S_ISREG(mode)) - -- cgit v1.2.1