Fix failing unit tests.

These tests began failing after a correction to another test.  The
other test had been patching the error_out function without unpatching
it and thus polluted the test environment.

Also reset to a known directory at the beginning of the common tests so
that we don't start in a directory that has since been unlinked.
This commit is contained in:
Alex Wood 2015-05-12 13:03:31 -04:00
parent f98e12e866
commit 6fedf5850e

View file

@ -16,9 +16,10 @@
from tito.common import (replace_version, find_spec_like_file, increase_version, from tito.common import (replace_version, find_spec_like_file, increase_version,
search_for, compare_version, run_command_print, find_wrote_in_rpmbuild_output, search_for, compare_version, run_command_print, find_wrote_in_rpmbuild_output,
render_cheetah, increase_zstream, reset_release, find_file_with_extension, render_cheetah, increase_zstream, reset_release, find_file_with_extension,
normalize_class_name, extract_sha1, BugzillaExtractor normalize_class_name, extract_sha1, BugzillaExtractor, DEFAULT_BUILD_DIR
) )
import os
import unittest import unittest
from mock import Mock, patch, call from mock import Mock, patch, call
@ -27,6 +28,10 @@ from unit import open_mock
class CommonTests(unittest.TestCase): class CommonTests(unittest.TestCase):
def setUp(self):
# Start in a known location to prevent problems with tests that
# end in a temp directory that is subsequently deleted.
os.chdir(DEFAULT_BUILD_DIR)
def test_normalize_class_name(self): def test_normalize_class_name(self):
""" Test old spacewalk.releng namespace is converted to tito. """ """ Test old spacewalk.releng namespace is converted to tito. """
@ -411,10 +416,10 @@ class ExtractBugzillasTest(unittest.TestCase):
self.assertEquals("Resolves: #987654 - Such amaze!", self.assertEquals("Resolves: #987654 - Such amaze!",
results[1]) results[1])
def test_required_flags_missing(self): @patch("tito.common.error_out")
def test_required_flags_missing(self, mock_error):
extractor = BugzillaExtractor("", required_flags=[ required_flags = ['myos-2.0+']
'myos-2.0+']) extractor = BugzillaExtractor("", required_flags)
bug1 = ('123456', 'Did something interesting.') bug1 = ('123456', 'Did something interesting.')
bug2 = ('444555', 'Something else.') bug2 = ('444555', 'Something else.')
bug3 = ('987654', 'Such amaze!') bug3 = ('987654', 'Such amaze!')
@ -436,6 +441,7 @@ class ExtractBugzillasTest(unittest.TestCase):
self.assertEquals(0, len(extractor.bzs)) self.assertEquals(0, len(extractor.bzs))
self.assertEquals(0, len(results)) self.assertEquals(0, len(results))
mock_error.assert_called_once_with("No bugzillas found with required flags: %s" % required_flags)
def test_required_flags_missing_with_placeholder(self): def test_required_flags_missing_with_placeholder(self):
@ -483,10 +489,10 @@ class ExtractBugzillasTest(unittest.TestCase):
self.assertEquals("Resolves: #123456 - Oops, lets try again.", self.assertEquals("Resolves: #123456 - Oops, lets try again.",
results[1]) results[1])
def test_bug_doesnt_exist(self): @patch("tito.common.error_out")
def test_bug_doesnt_exist(self, mock_error):
extractor = BugzillaExtractor("", required_flags=[ required_flags = ['myos-1.0+', 'pm_ack+']
'myos-1.0+', 'pm_ack+']) extractor = BugzillaExtractor("", required_flags)
bug1 = ('123456', 'Did something interesting.') bug1 = ('123456', 'Did something interesting.')
extractor._extract_bzs = Mock(return_value=[ extractor._extract_bzs = Mock(return_value=[
bug1]) bug1])
@ -499,6 +505,7 @@ class ExtractBugzillasTest(unittest.TestCase):
self.assertEquals(0, len(extractor.bzs)) self.assertEquals(0, len(extractor.bzs))
self.assertEquals(0, len(results)) self.assertEquals(0, len(results))
mock_error.assert_called_once_with("No bugzillas found with required flags: %s" % required_flags)
class MockBug(object): class MockBug(object):