From 74a1fdab60962079a03ef945e081ef5381d63868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= Date: Sun, 26 May 2013 10:32:05 +0200 Subject: [PATCH] Fixing coding style with the help of pep8 (wip) --- .pep8 | 3 +++ setup.py | 12 ++++++------ test/test_blob.py | 10 +++++----- test/test_diff.py | 13 +++++++------ test/test_index.py | 2 +- test/test_refs.py | 11 ++++++----- test/test_remote.py | 4 ++-- test/test_status.py | 28 ---------------------------- 8 files changed, 30 insertions(+), 53 deletions(-) create mode 100644 .pep8 diff --git a/.pep8 b/.pep8 new file mode 100644 index 0000000..92c073b --- /dev/null +++ b/.pep8 @@ -0,0 +1,3 @@ +[pep8] +exclude = .git,build,docs +ignore = diff --git a/setup.py b/setup.py index e38ebec..0aad84d 100644 --- a/setup.py +++ b/setup.py @@ -31,13 +31,15 @@ from __future__ import print_function import codecs -import os -from subprocess import Popen, PIPE -import sys from distutils.core import setup, Extension, Command from distutils.command.build import build from distutils.command.sdist import sdist from distutils import log +import os +import shlex +from subprocess import Popen, PIPE +import sys +import unittest # Read version from local pygit2/version.py without pulling in # pygit2/__init__.py @@ -85,11 +87,9 @@ class TestCommand(Command): def run(self): self.run_command('build') bld = self.distribution.get_command_obj('build') - #Add build_lib in to sys.path so that unittest can found DLLs and libs + # Add build_lib in to sys.path so that unittest can found DLLs and libs sys.path = [os.path.abspath(bld.build_lib)] + sys.path - import shlex - import unittest test_argv0 = [sys.argv[0] + ' test --args='] # For transfering args to unittest, we have to split args by ourself, # so that command like: diff --git a/test/test_blob.py b/test/test_blob.py index a5659a2..8105455 100644 --- a/test/test_blob.py +++ b/test/test_blob.py @@ -29,7 +29,7 @@ from __future__ import absolute_import from __future__ import unicode_literals -import os +from os.path import dirname, join import unittest import pygit2 @@ -91,14 +91,14 @@ class BlobTest(utils.RepoTestCase): self.assertEqual(len(BLOB_FILE_CONTENT), blob.size) self.assertEqual(BLOB_FILE_CONTENT, blob.read_raw()) - def test_create_blob_outside_workdir(self): - path = os.path.join(os.path.dirname(__file__), 'data', self.repo_dir + '.tar') + def test_create_blob_outside_workdir(self): + path = join(dirname(__file__), 'data', self.repo_dir + '.tar') self.assertRaises(KeyError, self.repo.create_blob_fromworkdir, path) - def test_create_blob_fromdisk(self): - path = os.path.join(os.path.dirname(__file__), 'data', self.repo_dir + '.tar') + def test_create_blob_fromdisk(self): + path = join(dirname(__file__), 'data', self.repo_dir + '.tar') blob_oid = self.repo.create_blob_fromdisk(path) blob = self.repo[blob_oid] diff --git a/test/test_diff.py b/test/test_diff.py index 7ff9946..09ce99a 100644 --- a/test/test_diff.py +++ b/test/test_diff.py @@ -32,6 +32,7 @@ from __future__ import unicode_literals import unittest import pygit2 from pygit2 import GIT_DIFF_INCLUDE_UNMODIFIED +from pygit2 import GIT_DIFF_IGNORE_WHITESPACE, GIT_DIFF_IGNORE_WHITESPACE_EOL from . import utils from itertools import chain @@ -183,9 +184,9 @@ class DiffTest(utils.BareRepoTestCase): diff = commit_a.tree.diff_to_tree() def get_context_for_lines(diff): - hunks = chain(*map(lambda x: x.hunks, [p for p in diff])) - lines = chain(*map(lambda x: x.lines, hunks)) - return map(lambda x: x[0], lines) + hunks = chain(*map(lambda x: x.hunks, [p for p in diff])) + lines = chain(*map(lambda x: x.lines, hunks)) + return map(lambda x: x[0], lines) entries = [p.new_file_path for p in diff] self.assertAll(lambda x: commit_a.tree[x], entries) @@ -204,8 +205,8 @@ class DiffTest(utils.BareRepoTestCase): commit_c = self.repo[COMMIT_SHA1_3] commit_d = self.repo[COMMIT_SHA1_4] - for flag in [pygit2.GIT_DIFF_IGNORE_WHITESPACE, - pygit2.GIT_DIFF_IGNORE_WHITESPACE_EOL]: + for flag in [GIT_DIFF_IGNORE_WHITESPACE, + GIT_DIFF_IGNORE_WHITESPACE_EOL]: diff = commit_c.tree.diff_to_tree(commit_d.tree, flag) self.assertTrue(diff is not None) self.assertEqual(0, len(diff[0].hunks)) @@ -277,7 +278,7 @@ class DiffTest(utils.BareRepoTestCase): #~ Must pass GIT_DIFF_INCLUDE_UNMODIFIED if you expect to emulate #~ --find-copies-harder during rename transformion... diff = commit_a.tree.diff_to_tree(commit_b.tree, - GIT_DIFF_INCLUDE_UNMODIFIED) + GIT_DIFF_INCLUDE_UNMODIFIED) self.assertAll(lambda x: x.status != 'R', diff) diff.find_similar() self.assertAny(lambda x: x.status == 'R', diff) diff --git a/test/test_index.py b/test/test_index.py index 39f41b8..8613020 100644 --- a/test/test_index.py +++ b/test/test_index.py @@ -129,7 +129,7 @@ class IndexTest(utils.RepoTestCase): def test_bare_index(self): index = pygit2.Index(os.path.join(self.repo.path, 'index')) self.assertEqual([x.hex for x in index], - [x.hex for x in self.repo.index]) + [x.hex for x in self.repo.index]) self.assertRaises(pygit2.GitError, lambda: index.add('bye.txt')) diff --git a/test/test_refs.py b/test/test_refs.py index 3c2af0c..ecad5f6 100644 --- a/test/test_refs.py +++ b/test/test_refs.py @@ -180,26 +180,27 @@ class ReferencesTest(utils.RepoTestCase): # try to create existing reference with force reference = self.repo.create_reference('refs/tags/version1', - LAST_COMMIT, force=True) + LAST_COMMIT, force=True) self.assertEqual(reference.target.hex, LAST_COMMIT) def test_create_symbolic_reference(self): + repo = self.repo # We add a tag as a new symbolic reference that always points to # "refs/heads/master" - reference = self.repo.create_reference('refs/tags/beta', + reference = repo.create_reference('refs/tags/beta', 'refs/heads/master') self.assertEqual(reference.type, GIT_REF_SYMBOLIC) self.assertEqual(reference.target, 'refs/heads/master') # try to create existing symbolic reference - self.assertRaises(ValueError, self.repo.create_reference, + self.assertRaises(ValueError, repo.create_reference, 'refs/tags/beta', 'refs/heads/master') # try to create existing symbolic reference with force - reference = self.repo.create_reference('refs/tags/beta', - 'refs/heads/master', force=True) + reference = repo.create_reference('refs/tags/beta', + 'refs/heads/master', force=True) self.assertEqual(reference.type, GIT_REF_SYMBOLIC) self.assertEqual(reference.target, 'refs/heads/master') diff --git a/test/test_remote.py b/test/test_remote.py index 6e5a150..279c811 100644 --- a/test/test_remote.py +++ b/test/test_remote.py @@ -44,7 +44,7 @@ class RepositoryTest(utils.RepoTestCase): name = 'upstream' url = 'git://github.com/libgit2/pygit2.git' - remote = self.repo.create_remote(name, url); + remote = self.repo.create_remote(name, url) self.assertEqual(type(remote), pygit2.Remote) self.assertEqual(name, remote.name) @@ -94,7 +94,7 @@ class RepositoryTest(utils.RepoTestCase): name = 'upstream' url = 'git://github.com/libgit2/pygit2.git' - remote = self.repo.create_remote(name, url); + remote = self.repo.create_remote(name, url) self.assertTrue(remote.name in [x.name for x in self.repo.remotes]) diff --git a/test/test_status.py b/test/test_status.py index c1b350f..98a7a70 100644 --- a/test/test_status.py +++ b/test/test_status.py @@ -35,34 +35,6 @@ import pygit2 from . import utils -EXPECTED = { - "current_file": pygit2.GIT_STATUS_CURRENT, - "file_deleted": pygit2.GIT_STATUS_WT_DELETED, - "modified_file": pygit2.GIT_STATUS_WT_MODIFIED, - "new_file": pygit2.GIT_STATUS_WT_NEW, - - "staged_changes": pygit2.GIT_STATUS_INDEX_MODIFIED, - "staged_changes_file_deleted": pygit2.GIT_STATUS_INDEX_MODIFIED | - pygit2.GIT_STATUS_WT_DELETED, - "staged_changes_file_modified": pygit2.GIT_STATUS_INDEX_MODIFIED | - pygit2.GIT_STATUS_WT_MODIFIED, - - "staged_delete": pygit2.GIT_STATUS_INDEX_DELETED, - "staged_delete_file_modified": pygit2.GIT_STATUS_INDEX_DELETED | - pygit2.GIT_STATUS_WT_NEW, - "staged_new": pygit2.GIT_STATUS_INDEX_NEW, - - "staged_new_file_deleted": pygit2.GIT_STATUS_INDEX_NEW | - pygit2.GIT_STATUS_WT_DELETED, - "staged_new_file_modified": pygit2.GIT_STATUS_INDEX_NEW | - pygit2.GIT_STATUS_WT_MODIFIED, - - "subdir/current_file": pygit2.GIT_STATUS_CURRENT, - "subdir/deleted_file": pygit2.GIT_STATUS_WT_DELETED, - "subdir/modified_file": pygit2.GIT_STATUS_WT_MODIFIED, - "subdir/new_file": pygit2.GIT_STATUS_WT_NEW, -} - class StatusTest(utils.DirtyRepoTestCase): def test_status(self):