Commit 657f1563 by Christine Lytwynec

use mock_open for paver quality tests

parent b328a2e8
...@@ -4,7 +4,7 @@ Tests for paver quality tasks ...@@ -4,7 +4,7 @@ Tests for paver quality tasks
import os import os
import tempfile import tempfile
import unittest import unittest
from mock import patch, MagicMock from mock import patch, MagicMock, mock_open
from ddt import ddt, file_data from ddt import ddt, file_data
import pavelib.quality import pavelib.quality
...@@ -71,7 +71,7 @@ class TestPaverRunQuality(unittest.TestCase): ...@@ -71,7 +71,7 @@ class TestPaverRunQuality(unittest.TestCase):
self.addCleanup(patcher.stop) self.addCleanup(patcher.stop)
self.addCleanup(self._mock_paver_needs.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): def test_failure_on_diffquality_pep8(self):
""" """
If pep8 finds errors, pylint should still be run If pep8 finds errors, pylint should still be run
...@@ -80,6 +80,7 @@ class TestPaverRunQuality(unittest.TestCase): ...@@ -80,6 +80,7 @@ class TestPaverRunQuality(unittest.TestCase):
_mock_pep8_violations = MagicMock( _mock_pep8_violations = MagicMock(
return_value=(1, ['lms/envs/common.py:32:2: E225 missing whitespace around operator']) 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 patch('pavelib.quality._get_pep8_violations', _mock_pep8_violations):
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
pavelib.quality.run_quality("") pavelib.quality.run_quality("")
...@@ -90,7 +91,7 @@ class TestPaverRunQuality(unittest.TestCase): ...@@ -90,7 +91,7 @@ class TestPaverRunQuality(unittest.TestCase):
self.assertEqual(_mock_pep8_violations.call_count, 1) self.assertEqual(_mock_pep8_violations.call_count, 1)
self.assertEqual(self._mock_paver_sh.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): def test_failure_on_diffquality_pylint(self):
""" """
If diff-quality fails on pylint, the paver task should also fail If diff-quality fails on pylint, the paver task should also fail
...@@ -109,7 +110,7 @@ class TestPaverRunQuality(unittest.TestCase): ...@@ -109,7 +110,7 @@ class TestPaverRunQuality(unittest.TestCase):
# And assert that sh was called once (for the call to "pylint") # And assert that sh was called once (for the call to "pylint")
self.assertEqual(self._mock_paver_sh.call_count, 1) 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): def test_other_exception(self):
""" """
If diff-quality fails for an unknown reason on the first run (pep8), then If diff-quality fails for an unknown reason on the first run (pep8), then
...@@ -121,7 +122,7 @@ class TestPaverRunQuality(unittest.TestCase): ...@@ -121,7 +122,7 @@ class TestPaverRunQuality(unittest.TestCase):
# Test that pylint is NOT called by counting calls # Test that pylint is NOT called by counting calls
self.assertEqual(self._mock_paver_sh.call_count, 1) 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): def test_no_diff_quality_failures(self):
# Assert nothing is raised # Assert nothing is raised
_mock_pep8_violations = MagicMock(return_value=(0, [])) _mock_pep8_violations = MagicMock(return_value=(0, []))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment