コード例 #1
0
 def test_nonexistent_source(self):
     with mock.patch.object(os.path, "exists",
                            return_value=False) as mock_exists:
         with mock.patch.object(shutil, "move") as mock_move:
             with mock.patch.object(os, "remove") as mock_remove:
                 output_cacher.move_if_different("source.txt", "dest.txt")
     mock_exists.assert_called()
     mock_move.assert_not_called()
     mock_remove.assert_not_called()
コード例 #2
0
 def test_nonexistent_source(self):
     with mock.patch.object(os.path, "exists",
                            return_value=False) as mock_exists:
         with mock.patch.object(shutil, "move") as mock_move:
             with mock.patch.object(os, "remove") as mock_remove:
                 with mock.patch.object(time, "sleep") as mock_sleep:
                     with self.assertRaises(FileNotFoundError):
                         output_cacher.move_if_different(
                             "source.txt", "dest.txt")
     mock_exists.assert_called()
     mock_move.assert_not_called()
     mock_remove.assert_not_called()
コード例 #3
0
 def test_cached_output(self):
     with mock.patch.object(os.path, "exists",
                            return_value=True) as mock_exists:
         with mock.patch.object(output_cacher, "files_match",
                                return_value=True) as mock_diff:
             with mock.patch.object(shutil, "move") as mock_move:
                 with mock.patch.object(os, "remove") as mock_remove:
                     output_cacher.move_if_different(
                         "source.txt", "dest.txt")
     mock_exists.assert_called()
     mock_diff.assert_called()
     mock_move.assert_not_called()
     mock_remove.assert_called_with("source.txt")
コード例 #4
0
    def test_new_output(self):

        def fake_exists(path):
            if path == "source.txt":
                return True
            elif path == "dest.txt":
                return False

        with mock.patch.object(os.path, "exists",
                               wraps=fake_exists) as mock_exists:
            with mock.patch.object(output_cacher, "files_match") as mock_diff:
                with mock.patch.object(shutil, "move") as mock_move:
                    with mock.patch.object(os, "remove") as mock_remove:
                        output_cacher.move_if_different(
                            "source.txt", "dest.txt")
        mock_exists.assert_called()
        mock_diff.assert_not_called()
        mock_move.assert_called_with("source.txt", "dest.txt")
        mock_remove.assert_not_called()