diff --git a/.gitignore b/.gitignore index 5b4f67b..be9576b 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports +.testrepository/ .tox/ .coverage .cache diff --git a/.testr.conf b/.testr.conf new file mode 100644 index 0000000..d3026e8 --- /dev/null +++ b/.testr.conf @@ -0,0 +1,8 @@ +[DEFAULT] +test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ + OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ + OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-160} \ + ${PYTHON:-python} -m subunit.run discover -t ./ ./tests $LISTOPT $IDOPTION + +test_id_option=--load-list $IDFILE +test_list_option=--list diff --git a/git-upstream b/git-upstream index 909245d..a22d2d2 100755 --- a/git-upstream +++ b/git-upstream @@ -18,7 +18,6 @@ # from git_upstream.main import main -from sys import argv if __name__ == '__main__': - main(argv) + return(main()) diff --git a/git_upstream/commands/supersede.py b/git_upstream/commands/supersede.py index c257449..1d449aa 100644 --- a/git_upstream/commands/supersede.py +++ b/git_upstream/commands/supersede.py @@ -17,6 +17,7 @@ from git_upstream.errors import GitUpstreamError from git_upstream.log import LogDedentMixin +from git_upstream.lib import note from git_upstream.lib.utils import GitMixin from git_upstream.lib.searchers import CommitMessageSearcher from git_upstream import subcommand, log diff --git a/git_upstream/main.py b/git_upstream/main.py index a484b3a..fe607bb 100644 --- a/git_upstream/main.py +++ b/git_upstream/main.py @@ -28,6 +28,7 @@ from git_upstream.errors import GitUpstreamError import git_upstream.log as log import git_upstream.version from git_upstream.lib import utils +from git_upstream.lib import note import subcommand import argparse @@ -97,11 +98,11 @@ def help(parser, args, commands=None): parser.print_help() -def main(argv): +def main(): (cmds, parser) = get_parser() - if not argv: - help(parser, argv) + if not sys.argv: + help(parser, sys.argv) return 0 if argparse_loaded: diff --git a/tests/base.py b/tests/base.py new file mode 100644 index 0000000..60e7350 --- /dev/null +++ b/tests/base.py @@ -0,0 +1,64 @@ +# Copyright 2010-2011 OpenStack Foundation +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os + +import git +import fixtures +import testtools + + +class DiveDir(fixtures.Fixture): + """Dive into given directory and return back on cleanup. + + :ivar path: The target directory. + """ + + def __init__(self, path): + self.path = path + + def setUp(self): + super(DiveDir, self).setUp() + self.addCleanup(os.chdir, os.getcwd()) + os.chdir(self.path) + + +class GitRepo(fixtures.Fixture): + """Create a copy git repo in which to operate.""" + + def __init__(self, repo): + self.repo = repo + self.path = '' + + def setUp(self): + super(GitRepo, self).setUp() + tempdir = fixtures.TempDir() + self.addCleanup(tempdir.cleanUp) + tempdir.setUp() + self.path = os.path.join(tempdir.path, 'git') + self.repo.clone(self.path) + + +class BaseTestCase(testtools.TestCase): + """Base Test Case for all tests.""" + + def setUp(self): + super(BaseTestCase, self).setUp() + + repo_path = self.useFixture(GitRepo(git.Repo('.'))).path + self.useFixture(DiveDir(repo_path)) + repo = git.Repo('.') + repo.git.config('user.email', 'user@example.com') + repo.git.config('user.name', 'Example User') diff --git a/tests/test_drop.py b/tests/test_drop.py index 7eccff4..447c0ea 100644 --- a/tests/test_drop.py +++ b/tests/test_drop.py @@ -9,13 +9,14 @@ # """Tests the drop module""" -import testtools +from tests import base + from git_upstream.commands import drop as d from git import repo as r from git import GitCommandError -class TestDrop(testtools.TestCase): +class TestDrop(base.BaseTestCase): """Test case for Drop class""" first_commit = "bd6b9eefe961abe8c15cb5dc6905b92e14714a4e" diff --git a/tests/test_supersede.py b/tests/test_supersede.py index 25301af..8323b99 100644 --- a/tests/test_supersede.py +++ b/tests/test_supersede.py @@ -10,13 +10,14 @@ """Tests the supersede module""" -import testtools +from tests import base + from git_upstream.commands import supersede as s from git import repo as r from git import GitCommandError -class TestSupersede(testtools.TestCase): +class TestSupersede(base.BaseTestCase): """Test case for Supersede class""" first_commit = "bd6b9eefe961abe8c15cb5dc6905b92e14714a4e" @@ -26,6 +27,7 @@ class TestSupersede(testtools.TestCase): second_change_ids = ("Iebd1f5aa789dcd9574a00bb8837e4596bf55fa88", "I4ab003213c40b0375283a15e2967d11e0351feb1") invalid_change_ids = ("this_is_an_invalid_change_id",) + change_ids_branch = "master" invalid_change_ids_branch = "this_is_an_invalid_change_ids_branch" note_ref = 'refs/notes/upstream-merge'