def test_follow_file_uses_filename_by_default(self): fake_test = Mock() with NamedTemporaryFile() as f: follow_file(f.name, fake_test) fake_test.addCleanup.call_args[0][0]() actual = fake_test.addDetail.call_args[0][0] self.assertEqual(f.name, actual)
def test_follow_file_adds_addDetail_cleanup(self): fake_test = Mock() with NamedTemporaryFile() as f: follow_file(f.name, fake_test) self.assertTrue(fake_test.addCleanup.called) fake_test.addCleanup.call_args[0][0]() self.assertTrue(fake_test.addDetail.called)
def test_follow_file_uses_content_name(self): fake_test = Mock() content_name = self.getUniqueString() with NamedTemporaryFile() as f: follow_file(f.name, fake_test, content_name) fake_test.addCleanup.call_args[0][0]() actual = fake_test.addDetail.call_args[0][0] self.assertEqual(content_name, actual)
def test_follow_file_content_object_contains_new_file_data(self): fake_test = Mock() with NamedTemporaryFile() as f: follow_file(f.name, fake_test) f.write(b"Hello") f.flush() fake_test.addCleanup.call_args[0][0]() actual = fake_test.addDetail.call_args[0][1].as_text() self.assertEqual("Hello", actual)
def test_follow_file_logs_error_on_IOError(self): fake_test = Mock() content_name = self.getUniqueString() with NamedTemporaryFile() as f: os.chmod(f.name, 0) with patch('autopilot.content._logger') as fake_logger: follow_file(f.name, fake_test, content_name) fake_logger.error.assert_called_once_with( "Could not add content object '%s' due to IO Error: %s", content_name, "[Errno 13] Permission denied: '%s'" % f.name )
def test_follow_file_returns_empty_content_object_on_error(self): fake_test = Mock() content_name = self.getUniqueString() with NamedTemporaryFile() as f: os.chmod(f.name, 0) content_obj = follow_file(f.name, fake_test, content_name) self.assertThat(content_obj.as_text(), Equals(''))
def test_follow_file_does_not_raise_on_IOError(self): fake_test = Mock() content_name = self.getUniqueString() with NamedTemporaryFile() as f: os.chmod(f.name, 0) self.assertThat( lambda: follow_file(f.name, fake_test, content_name), Not(Raises()) )
def setUp(self): super(LogFileDebugObject, self).setUp() follow_file(self.log_path, CaseAddDetailToNormalAddDetailDecorator(self))
def test_foo(self): follow_file(f.name, self) f.write(b"Hello") f.flush()