Пример #1
0
    def test_rm(self, mock_os, mock_path):
        """Make sure rm() calls os.remove() as expected."""

        # Set up the mock return for isfile()
        mock_path.isfile.return_value = True

        # Do the test
        rm("any path")

        # And make sure it had the desired interactions with
        # the system calls.

        # test that rm called os.remove with the right parameters
        mock_os.remove.assert_called_with("any path")
Пример #2
0
    def test_no_rm(self, mock_os, mock_path):
        """Make sure we don't try to remove nonexistent files"""

        # Set up the mock return for isfile()
        mock_path.isfile.return_value = False

        # Do the test
        rm("any path")

        # And make sure it had the desired interactions with
        # the system calls.

        # os.remove() should not have been called
        self.assertFalse(mock_os.remove.called,
                         "Failed to not remove the file if not present.")