def test_calls(self): """This function does the final cleanup so its just os.unlink""" test_args = Namespace() setattr(test_args, 'dir', os.path.join(os.path.sep, 'dev', 'null')) setattr(test_args, 'force_clean', True) cleanerInst = Cleaner() cleanerInst.args = test_args with mock.patch('os.unlink') as m_unlink: cleanerInst.force_clean_space() m_unlink.assert_called_once_with(test_args.dir)
def test_no_call_without_dir(self): """This function does the final cleanup so its just os.unlink""" test_args = Namespace() setattr(test_args, 'dir', os.path.join(os.path.sep, 'dev', 'null')) setattr(test_args, 'force_clean', True) cleanerInst = Cleaner() cleanerInst.args = test_args with mock.patch('shutil.rmtree') as m_unlink, \ mock.patch('os.path.isdir', return_value=False): cleanerInst.force_clean_space() m_unlink.assert_not_called()
def test_calls(self): """This function does the final cleanup so its just module loads and a subprocess call""" test_args = Namespace() setattr(test_args, 'dir', os.path.join(os.path.sep, 'dev', 'null')) setattr(test_args, 'force_clean', True) cleanerInst = Cleaner() cleanerInst.args = test_args with mock.patch('clean_workspace.module') as mod, \ mock.patch('os.chdir') as m_chdir, \ mock.patch('clean_workspace.subprocess.check_call') as check_call: cleanerInst.force_clean_space() mod.assert_has_calls([mock.call('load', 'atdm-env'), mock.call('load', 'atdm-ninja_fortran/1.7.2')]) m_chdir.assert_called_once_with(test_args.dir) check_call.assert_called_once_with(['make', 'clean'])
def test_older_date_does_clean(self): """The default dates should result in no clean action""" testDate = datetime(2019, 2, 4, hour=10, minute=0) test_args = Namespace() setattr(test_args, "dir", os.path.join(os.path.sep, "dev", "null", "will_clean")) with mock.patch('clean_workspace.last_clean_date', return_value=testDate): cleanerInst = Cleaner() cleanerInst.args = test_args with mock.patch('clean_workspace.Cleaner.force_clean_space') as force_clean, \ mock.patch('clean_workspace.update_last_clean_date') as update, \ mock.patch('clean_workspace.print') as m_print: cleanerInst.clean_space_by_date() force_clean.assert_called_once() update.assert_called_once() m_print.assert_called_once_with("Cleaning directory /dev/null/will_clean " "due to newer reference date")
def test_older_date_does_clean(self): """The default dates should result in no clean action""" testDate = datetime(2019, 2, 4, hour=10, minute=0) test_args = Namespace() setattr(test_args, "dir", os.path.join(os.path.sep, "dev", "null", "will_clean")) with mock.patch('clean_workspace.last_clean_date', return_value=testDate): cleanerInst = Cleaner() cleanerInst.args = test_args with mock.patch('clean_workspace.Cleaner.force_clean_space') as force_clean, \ mock.patch('clean_workspace.update_last_clean_date') as update, \ mock.patch('clean_workspace.print') as m_print, \ mock.patch("clean_sentinel.open", side_effect=IOError): cleanerInst.clean_space_by_date() force_clean.assert_called_once_with() update.assert_called_once_with() m_print.assert_called_once_with("Cleaning directory /dev/null/will_clean " "due to newer reference date")
def test_calls(self): """This function does the final cleanup so its just module loads and a subprocess call""" test_args = Namespace() setattr(test_args, 'dir', os.path.join(os.path.sep, 'dev', 'null')) setattr(test_args, 'force_clean', True) cleanerInst = Cleaner() cleanerInst.args = test_args with mock.patch('clean_workspace.module') as mod, \ mock.patch('os.chdir') as m_chdir, \ mock.patch('clean_workspace.subprocess.check_call') as check_call: cleanerInst.force_clean_space() mod.assert_has_calls([ mock.call('load', 'sems-env'), mock.call('load', 'sems-ninja_fortran/1.8.2') ]) m_chdir.assert_called_once_with(test_args.dir) check_call.assert_called_once_with(['make', 'clean'])
def test_newer_reference_does_clean(self): """The default dates should result in no clean action""" testDate = datetime(2019, 2, 4, hour=10, minute=48) test_args = Namespace() setattr(test_args, "dir", os.path.join(os.path.sep, "dev", "null", "fake_directory")) with mock.patch('clean_workspace.clean_reference_date', return_value=testDate): cleanerInst = Cleaner() cleanerInst.args = test_args with mock.patch.dict('os.environ', {'WORKSPACE': '/scratch/Trilinos/foo/bar'}): with mock.patch('clean_workspace.Cleaner.force_clean_space') as force_clean, \ mock.patch('clean_workspace.update_last_clean_date') as update, \ mock.patch('clean_workspace.print') as m_print: cleanerInst.clean_space_by_date() force_clean.assert_called_once_with() update.assert_called_once_with() m_print.assert_called_once_with("Cleaning directory /dev/null/fake_directory " "due to newer reference date")
def test_newer_reference_does_clean(self): """The default dates should result in no clean action""" testDate = datetime(2019, 2, 4, hour=10, minute=48) test_args = Namespace() setattr(test_args, "dir", os.path.join(os.path.sep, "dev", "null", "fake_directory")) with mock.patch('clean_workspace.clean_reference_date', return_value=testDate): cleanerInst = Cleaner() cleanerInst.args = test_args with mock.patch.dict('os.environ', {'WORKSPACE': '/scratch/Trilinos/foo/bar'}): with mock.patch('clean_workspace.Cleaner.force_clean_space') as force_clean, \ mock.patch('clean_workspace.update_last_clean_date') as update, \ mock.patch('clean_workspace.print') as m_print: cleanerInst.clean_space_by_date() force_clean.assert_called_once() update.assert_called_once() m_print.assert_called_once_with("Cleaning directory /dev/null/fake_directory " "due to newer reference date")