def test_logs_file_to_debug_log(self): random_file = "/some/path/to/a/file/%s" % random.randint(100, 200) with create_mock_open() as o: o.side_effect = IOError with mock.patch.object(utils, "stderrlog") as log: utils.can_open(random_file) log.info.assert_called_with("Unable to open %s\n" % random_file)
def test_closes_file_handler_if_successful(self): with create_mock_open() as o: utils.can_open("/some/file") o.assert_has_calls([ mock.call("/some/file", "ab"), mock.call().close(), ])
def test_logs_file_to_debug_log(self): random_file = "/some/path/to/a/file/%s" % random.randint(100, 200) with create_mock_open() as o: o.side_effect = IOError with mock.patch.object(utils, "log") as log: utils.can_open(random_file) log.debug.assert_called_with("Unable to open %s" % random_file)
def test_returns_false_if_unable_to_open(self): with create_mock_open() as o: o.side_effect = IOError self.assertFalse(utils.can_open("/some/path/some/file"))
def test_returns_true_if_can_open(self): with create_mock_open(): self.assertTrue(utils.can_open("/some/path/some/file"))