Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @patch("caching.worker.os")
- @patch("caching.worker.Worker._delete_directory")
- @patch("caching.worker.Worker.__init__")
- def test__generate_directory(self, mock_init, mock_delete_directory, mock_os):
- # setup return values for function to pass
- mock_init.return_value = None
- mock_os.path.isdir.return_value = False
- # initiate the worker and run the function
- test = Worker()
- test.base_dir = "test dir"
- test._generate_directory()
- # check that the checking of path has been done once with the base dir
- mock_os.path.isdir.assert_called_once_with(test.base_dir)
- # check that the mkdir function is called once with the base dir
- mock_os.mkdir.assert_called_once_with(test.base_dir)
- # setup return values for the directory to already exist
- mock_os.path.isdir.return_value = True
- # check that it raises an exception because of this
- with self.assertRaises(Exception):
- test._generate_directory()
- # check that the mkdir has still only been called once
- mock_os.mkdir.assert_called_once_with(test.base_dir)
- # check that the isdir function has been called twice
- self.assertEqual(2, len(mock_os.path.isdir.call_args_list))
- del test
- mock_delete_directory.assert_called_once_with()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement