Make unittests work with testr

This commit is contained in:
Monty Taylor 2014-03-15 10:45:34 -07:00 committed by Darragh Bailey
parent 99caa52b01
commit 8617ea36bf
8 changed files with 86 additions and 9 deletions

1
.gitignore vendored
View File

@ -25,6 +25,7 @@ pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
.testrepository/
.tox/
.coverage
.cache

8
.testr.conf Normal file
View File

@ -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

View File

@ -18,7 +18,6 @@
#
from git_upstream.main import main
from sys import argv
if __name__ == '__main__':
main(argv)
return(main())

View File

@ -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

View File

@ -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:

64
tests/base.py Normal file
View File

@ -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')

View File

@ -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"

View File

@ -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'