def test_pantsd_invalidation_stale_sources(self): test_path = 'tests/python/pants_test/daemon_correctness_test_0001' test_build_file = os.path.join(test_path, 'BUILD') test_src_file = os.path.join(test_path, 'some_file.py') has_source_root_regex = r'"source_root": ".*/{}"'.format(test_path) export_cmd = ['export', test_path] try: with self.pantsd_successful_run_context() as (pantsd_run, checker, workdir, _): safe_mkdir(test_path, clean=True) pantsd_run(['help']) checker.assert_started() safe_file_dump(test_build_file, "python_library(sources=globs('some_non_existent_file.py'))") result = pantsd_run(export_cmd) checker.assert_running() self.assertNotRegexpMatches(result.stdout_data, has_source_root_regex) safe_file_dump(test_build_file, "python_library(sources=globs('*.py'))") result = pantsd_run(export_cmd) checker.assert_running() self.assertNotRegexpMatches(result.stdout_data, has_source_root_regex) safe_file_dump(test_src_file, 'import this\n') result = pantsd_run(export_cmd) checker.assert_running() self.assertRegexpMatches(result.stdout_data, has_source_root_regex) finally: rm_rf(test_path)
def test_rm_rf_permission_error_raises(self, file_name='./perm_guarded_file'): with temporary_dir() as td, pushd(td), \ mock.patch('pants.util.dirutil.shutil.rmtree') as mock_rmtree, \ self.assertRaises(OSError): mock_rmtree.side_effect = OSError(errno.EACCES, os.strerror(errno.EACCES)) touch(file_name) rm_rf(file_name)
def purge_metadata_by_name(self, name): """Purge a processes metadata directory. :raises: `ProcessManager.MetadataError` when OSError is encountered on metadata dir removal. """ meta_dir = self._get_metadata_dir_by_name(name) logger.debug('purging metadata directory: {}'.format(meta_dir)) try: rm_rf(meta_dir) except OSError as e: raise self.MetadataError('failed to purge metadata directory {}: {!r}'.format(meta_dir, e))
def purge_metadata(self, force=False): """Purge a processes metadata directory. :param bool force: If True, skip process liveness check before purging metadata. :raises: `ProcessManager.MetadataError` when OSError is encountered on metadata dir removal. """ if not force: assert not self.is_alive(), 'aborting attempt to purge metadata for a running process!' meta_dir = self.get_metadata_dir() logging.debug('purging metadata directory: {}'.format(meta_dir)) try: rm_rf(meta_dir) except OSError as e: raise self.MetadataError('failed to purge metadata directory {}: {!r}'.format(meta_dir, e))
def test_pantsd_parse_exception_success(self): # This test covers the case described in #6426, where a run that is failing fast due to an # exception can race other completing work. We expect all runs to fail due to the error # that has been introduced, but none of them should hang. test_path = 'testprojects/3rdparty/this_is_definitely_not_a_valid_directory' test_build_file = os.path.join(test_path, 'BUILD') invalid_symbol = 'this_is_definitely_not_a_valid_symbol' try: safe_mkdir(test_path, clean=True) safe_file_dump(test_build_file, "{}()".format(invalid_symbol)) for _ in range(3): with self.pantsd_run_context(success=False) as (pantsd_run, checker, _, _): result = pantsd_run(['list', 'testprojects::']) checker.assert_started() self.assertIn(invalid_symbol, result.stderr_data) finally: rm_rf(test_path)
def test_rm_rf_no_such_file_not_an_error(self, file_name='./vanishing_file'): with temporary_dir() as td, pushd(td), \ mock.patch('pants.util.dirutil.shutil.rmtree') as mock_rmtree: mock_rmtree.side_effect = OSError(errno.ENOENT, os.strerror(errno.ENOENT)) touch(file_name) rm_rf(file_name)
def test_rm_rf_nonexistent(self, file_name='./non_existent_file'): with temporary_dir() as td, pushd(td): rm_rf(file_name)
def test_rm_rf_dir(self, dir_name='./bar'): with temporary_dir() as td, pushd(td): safe_mkdir(dir_name) self.assertTrue(os.path.isdir(dir_name)) rm_rf(dir_name) self.assertFalse(os.path.exists(dir_name))
def test_rm_rf_file(self, file_name='./foo'): with temporary_dir() as td, pushd(td): touch(file_name) self.assertTrue(os.path.isfile(file_name)) rm_rf(file_name) self.assertFalse(os.path.exists(file_name))