Files
git-upstream/git_upstream/tests/strategies/test_strategies.py
Darragh Bailey 8d5fbf9388 Ensure logging is checked by most tests
Make sure to test that log messages are being emitted and captured
correctly across a larger number of tests to catch issues in tests
incorrectly polluting the setup of the logging capturing across other
test cases exposed by a recent patch.

Where tests are executed in separate threads it is possible for a
mistake in one thread, thrashing the logging capture to go unnoticed
unless other tests being executed in the same thread are checking for
correct log output. This can result in random failures as the test
execution order is dependent on PYTHONHASHSEED.

This change ensures that most tests being executed perform a positive
assertion for content to appear in the logged output, at one of the
standard log levels (as opposed to the custom one) to ensure that
logging is being captured correctly by the test framework.

Change-Id: I903478d6f3cb3f25dd7e2410c78155eca6a7d780
Related-Patch: https://review.openstack.org/387426
2016-10-20 10:54:16 +01:00

64 lines
2.2 KiB
Python

#
# Copyright (c) 2014-2016 Hewlett-Packard Enterprise 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
from pprint import pformat
from testscenarios import TestWithScenarios
from testtools.content import text_content
from testtools import matchers
from git_upstream.tests.base import BaseTestCase
from git_upstream.tests.base import get_scenarios
import_command = __import__("git_upstream.commands.import", globals(),
locals(), ['LocateChangesWalk'])
LocateChangesWalk = import_command.LocateChangesWalk
class TestStrategies(TestWithScenarios, BaseTestCase):
scenarios = get_scenarios(os.path.join(os.path.dirname(__file__),
"scenarios"))
def setUp(self):
# add description in case parent setup fails.
self.addDetail('description', text_content(self.desc))
# builds the tree to be tested
super(TestStrategies, self).setUp()
# need the tree built at this point
self.addDetail('expected-changes',
text_content(pformat(
list((c, self.gittree.graph[c].hexsha)
for c in self.expected_changes))))
def test_search_changes(self):
strategy = LocateChangesWalk(
branch=self.branches['head'][0],
search_refs=[self.branches['upstream'][0]])
self.assertEqual(
self.gittree._commits_from_nodes(self.expected_changes),
[c for c in strategy.filtered_iter()])
self.assertThat(self.logger.output,
matchers.Contains("Searching for most recent merge "
"base with upstream branches"))