From 657f15638d5bb9a4dbf6bd8f604fb7af8124ceb4 Mon Sep 17 00:00:00 2001 From: Christine Lytwynec Date: Thu, 14 May 2015 14:51:08 -0400 Subject: [PATCH 1/2] use mock_open for paver quality tests --- pavelib/paver_tests/test_paver_quality.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pavelib/paver_tests/test_paver_quality.py b/pavelib/paver_tests/test_paver_quality.py index a524d5a287..739d0a0f10 100644 --- a/pavelib/paver_tests/test_paver_quality.py +++ b/pavelib/paver_tests/test_paver_quality.py @@ -4,7 +4,7 @@ Tests for paver quality tasks import os import tempfile import unittest -from mock import patch, MagicMock +from mock import patch, MagicMock, mock_open from ddt import ddt, file_data import pavelib.quality @@ -71,7 +71,7 @@ class TestPaverRunQuality(unittest.TestCase): self.addCleanup(patcher.stop) self.addCleanup(self._mock_paver_needs.stop) - @unittest.skip("TODO: TE-868") + @patch('__builtin__.open', mock_open()) def test_failure_on_diffquality_pep8(self): """ If pep8 finds errors, pylint should still be run @@ -80,6 +80,7 @@ class TestPaverRunQuality(unittest.TestCase): _mock_pep8_violations = MagicMock( return_value=(1, ['lms/envs/common.py:32:2: E225 missing whitespace around operator']) ) + with patch('pavelib.quality._get_pep8_violations', _mock_pep8_violations): with self.assertRaises(SystemExit): pavelib.quality.run_quality("") @@ -90,7 +91,7 @@ class TestPaverRunQuality(unittest.TestCase): self.assertEqual(_mock_pep8_violations.call_count, 1) self.assertEqual(self._mock_paver_sh.call_count, 1) - @unittest.skip("TODO: TE-868") + @patch('__builtin__.open', mock_open()) def test_failure_on_diffquality_pylint(self): """ If diff-quality fails on pylint, the paver task should also fail @@ -109,7 +110,7 @@ class TestPaverRunQuality(unittest.TestCase): # And assert that sh was called once (for the call to "pylint") self.assertEqual(self._mock_paver_sh.call_count, 1) - @unittest.skip("TODO: Fix order dependency on test_no_diff_quality_failures") + @patch('__builtin__.open', mock_open()) def test_other_exception(self): """ If diff-quality fails for an unknown reason on the first run (pep8), then @@ -121,7 +122,7 @@ class TestPaverRunQuality(unittest.TestCase): # Test that pylint is NOT called by counting calls self.assertEqual(self._mock_paver_sh.call_count, 1) - @unittest.skip("TODO: TE-868") + @patch('__builtin__.open', mock_open()) def test_no_diff_quality_failures(self): # Assert nothing is raised _mock_pep8_violations = MagicMock(return_value=(0, [])) From 71bc1476e8eeab6c275e4ceb4c7e8f9438a22bd0 Mon Sep 17 00:00:00 2001 From: Christine Lytwynec Date: Fri, 15 May 2015 10:08:23 -0400 Subject: [PATCH 2/2] start paver quality tests with clean paver task environment --- pavelib/paver_tests/test_paver_quality.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pavelib/paver_tests/test_paver_quality.py b/pavelib/paver_tests/test_paver_quality.py index 739d0a0f10..30836c4cf7 100644 --- a/pavelib/paver_tests/test_paver_quality.py +++ b/pavelib/paver_tests/test_paver_quality.py @@ -9,6 +9,7 @@ from ddt import ddt, file_data import pavelib.quality import paver.easy +import paver.tasks from paver.easy import BuildFailure @@ -63,6 +64,19 @@ class TestPaverRunQuality(unittest.TestCase): def setUp(self): super(TestPaverRunQuality, self).setUp() + # test_no_diff_quality_failures seems to alter the way that paver + # executes these lines is subsequent tests. + # https://github.com/paver/paver/blob/master/paver/tasks.py#L175-L180 + # + # The other tests don't appear to have the same impact. This was + # causing a test order dependency. This line resets that state + # of environment._task_in_progress so that the paver commands in the + # tests will be considered top level tasks by paver, and we can predict + # which path it will chose in the above code block. + # + # TODO: Figure out why one test is altering the state to begin with. + paver.tasks.environment = paver.tasks.Environment() + # mock the @needs decorator to skip it self._mock_paver_needs = patch.object(pavelib.quality.run_quality, 'needs').start() self._mock_paver_needs.return_value = 0 @@ -80,7 +94,6 @@ class TestPaverRunQuality(unittest.TestCase): _mock_pep8_violations = MagicMock( return_value=(1, ['lms/envs/common.py:32:2: E225 missing whitespace around operator']) ) - with patch('pavelib.quality._get_pep8_violations', _mock_pep8_violations): with self.assertRaises(SystemExit): pavelib.quality.run_quality("") @@ -117,8 +130,9 @@ class TestPaverRunQuality(unittest.TestCase): pylint should not be run """ self._mock_paver_sh.side_effect = [Exception('unrecognized failure!'), 0] - with self.assertRaises(Exception): + with self.assertRaises(SystemExit): pavelib.quality.run_quality("") + self.assertRaises(Exception) # Test that pylint is NOT called by counting calls self.assertEqual(self._mock_paver_sh.call_count, 1)