def test_main_suite_runs_for_multiple_suite(self, mockOpen, mockYamlLoad): mockYamlLoad.return_value = { 'suites': { 'test': { 'report': 'test.txt', 'constraints': [{ 'type': 'bob' }] }, 'otherTest': { 'report': 'yay.txt', 'constraints': [{ 'type': 'other' }] }, 'lastTest': { 'report': 'last.txt', 'constraints': [{ 'type': 'last' }] } } } self.suite.QualitySuite.available_suites.return_value = [ 'test', 'otherTest', 'lastTest' ] mockFileContents = { 'test.txt': 'testTxt', 'yay.txt': 'otherTxt', 'last.txt': 'lastTxt' } def mockFileOpen(filename, *_): openMock = mock.MagicMock() openMock.__enter__.return_value = StringIO( mockFileContents[filename]) return openMock mockOpen.side_effect = mockFileOpen main('file') self.assertEqual( self.suite.QualitySuite.get_suite.return_value.run.call_count, 3) self.suite.QualitySuite.get_suite.return_value.run.assert_any_call( [{ 'type': 'bob' }], 'testTxt') self.suite.QualitySuite.get_suite.return_value.run.assert_any_call( [{ 'type': 'other' }], 'otherTxt') self.suite.QualitySuite.get_suite.return_value.run.assert_any_call( [{ 'type': 'last' }], 'lastTxt')
def test_main_raises_UnknownSuite_when_not_in_availble_suites( self, mockOpen, mockYamlLoad): mockYamlLoad.return_value = { 'suites': { 'test': { 'report': 'test.txt', 'constraints': [{ 'type': 'bob' }] } } } self.suite.available_suites.return_value = ['otherNonTest'] with self.assertRaises(UnknownSuite): main('file')
def test_main_raises_ReportParsingError_on_IOError(self, mockOpen, mockYamlLoad): mockYamlLoad.return_value = { 'suites': { 'test': { 'report': 'test.txt', 'constraints': [{ 'type': 'bob' }] } } } self.suite.QualitySuite.available_suites.return_value = ['test'] self.suite.QualitySuite.get_suite.return_value = {} mockOpen.side_effect = IOError('boom') with self.assertRaises(ReportParsingError): main('file')
def test_main_suite_runs_for_1_suite(self, mockOpen, mockYamlLoad): mockYamlLoad.return_value = { 'suites': { 'test': { 'report': 'test.txt', 'constraints': [{ 'type': 'bob' }] } } } self.suite.QualitySuite.available_suites.return_value = ['test'] mockOpen.return_value.__enter__.return_value = StringIO('reportTxt') main('file') self.suite.QualitySuite.get_suite.return_value.run.assert_called_once_with( [{ 'type': 'bob' }], 'reportTxt')
def test_main_raises_ConfigurationParsingError_on_load_Invalid( self, mockOpen, mockYamlLoad): mockYamlLoad.side_effect = Invalid('boom') with self.assertRaises(ConfigurationParsingError): main('file')