def test_cleanup_sub_folders_with_directories(self, mock_path, mock_os): mock_os.listdir.return_value = ['1', '2', '3', '4', '5', '6', '7', '8'] mock_path.isfile.return_value = True backup = Backup(config) backup.cleanup_sub_folders() self.assertTrue(mock_os.listdir.called) self.assertTrue(mock_os.remove.called)
def run(args): param, clone_id = args[0], args[1] param["transportation_cost"] = np.random.choice(param["range_transportation_cost"]) param["customer_alpha"] = np.random.uniform(*param["range_customer_alpha"]) param["customer_temp"] = np.random.uniform(*param["range_customer_temp"]) param["firm_alpha"] = np.random.uniform(*param["range_firm_alpha"]) param["firm_temp"] = np.random.uniform(*param["range_firm_temp"]) # param["utility_consumption"] = np.random.uniform(*param["range_utility_consumption"]) param["firm_positions"] = np.random.randint(1, param["n_positions"] + 1, size=param["n_firms"]) param["firm_prices"] = np.random.randint(1, param["n_prices"] + 1, size=param["n_firms"]) param["seed"] = np.random.randint(2 ** 32) job_id = param["job_id"] label = "J{}C{}".format(job_id, clone_id) env = Environment(**param) results = env.run() Backup(data=results, name="results", root_folder=cl_parameters["working_folder"], label=label) Backup(data=param, name="parameters", root_folder=cl_parameters["working_folder"], label=label)
def test_cleanup_sub_folders_with_directories_less_than_required(self, mock_path, mock_os): mock_os.listdir.return_value = ['123123123', '234234234'] mock_path.isfile.return_value = True backup = Backup(config) backup.cleanup_sub_folders() self.assertTrue(mock_os.listdir.called) self.assertFalse(mock_os.remove.called)
def test_archive_with_directories(self, mock_path, mock_rmtree, mock_os, mock_call): mock_os.listdir.return_value = ['123123123', '234234234'] mock_path.isdir.return_value = True backup = Backup(config) backup.archive() self.assertTrue(mock_os.listdir.called) self.assertTrue(mock_call.called) self.assertTrue(mock_rmtree.called)
def test_set_tmp_folder_absolute(self, mock_os, mock_path): mock_path.isdir.return_value = False tmp_folder = '/some/path/to/nowhere' backup = Backup(config) backup.set_tmp_folder(tmp_folder) self.assertEqual(backup.tmpFolder, tmp_folder) mock_path.isdir.assert_called_with(tmp_folder) # Temporary folder has been created mock_os.makedirs.assert_called_with(tmp_folder)
def test_archive_without_directories(self, mock_path, mock_rmtree, mock_os, mock_call): backup = Backup(config) backup.archive() self.assertTrue(mock_os.listdir.called) self.assertFalse(mock_call.called) self.assertFalse(mock_rmtree.called)
def test_create_current_folder_by_time(self, mock_os): backup = Backup(config) current_time = (2015, 12, 20, 23, 26, 30, 6, 354, 0) folder_name = backup.create_current_folder_by_time(current_time) self.assertTrue(mock_os.mkdir.called) self.assertEqual(folder_name, ''.join(str(x) for x in current_time[:6]))