def test_when_invalid_coursier_cache_should_trigger_resolve(self): jar_lib = self._make_junit_target() with self._temp_workdir(): context = self.context(target_roots=[jar_lib]) task = self.execute(context) compile_classpath = context.products.get_data('compile_classpath') jar_cp = compile_classpath.get_for_target(jar_lib) # └─ junit:junit:4.12 # └─ org.hamcrest:hamcrest-core:1.3 self.assertEquals(2, len(jar_cp)) # Take a sample jar path, remove it, then call the task again, it should invoke coursier again conf, path = jar_cp[0] self.assertTrue(os.path.islink(path)) safe_remove(os.path.realpath(path)) task.runjava = MagicMock() # Ignore any error because runjava may fail due to undefined behavior try: task.execute() except TaskError: pass task.runjava.assert_called()
def test_connections(self): def create_socket(family, type): sock = socket.socket(family, type) sock.bind(('', 0)) if type == socket.SOCK_STREAM: sock.listen(1) return sock socks = [] socks.append(create_socket(socket.AF_INET, socket.SOCK_STREAM)) socks.append(create_socket(socket.AF_INET, socket.SOCK_DGRAM)) if supports_ipv6(): socks.append(create_socket(socket.AF_INET6, socket.SOCK_STREAM)) socks.append(create_socket(socket.AF_INET6, socket.SOCK_DGRAM)) if hasattr(socket, 'AF_UNIX'): safe_remove(TESTFN) s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.bind(TESTFN) s.listen(1) socks.append(s) kind = 'all' # TODO: UNIX sockets are temporarily implemented by parsing # 'pfiles' cmd output; we don't want that part of the code to # be executed. if SUNOS: kind = 'inet' try: self.execute('connections', kind=kind) finally: for s in socks: s.close()
def test_open_files_mode(self): def get_test_file(): p = psutil.Process() giveup_at = time.time() + 2 while True: for file in p.open_files(): if file.path == os.path.abspath(TESTFN): return file elif time.time() > giveup_at: break raise RuntimeError("timeout looking for test file") # with open(TESTFN, "w"): self.assertEqual(get_test_file().mode, "w") with open(TESTFN, "r"): self.assertEqual(get_test_file().mode, "r") with open(TESTFN, "a"): self.assertEqual(get_test_file().mode, "a") # with open(TESTFN, "r+"): self.assertEqual(get_test_file().mode, "r+") with open(TESTFN, "w+"): self.assertEqual(get_test_file().mode, "r+") with open(TESTFN, "a+"): self.assertEqual(get_test_file().mode, "a+") # note: "x" bit is not supported if PY3: safe_remove(TESTFN) with open(TESTFN, "x"): self.assertEqual(get_test_file().mode, "w") safe_remove(TESTFN) with open(TESTFN, "x+"): self.assertEqual(get_test_file().mode, "r+")
def test_when_invalid_hardlink_and_coursier_cache_should_trigger_resolve(self): jar_lib = self._make_junit_target() with self._temp_workdir(): with temporary_dir() as couriser_cache_dir: self.set_options_for_scope('coursier', cache_dir=couriser_cache_dir) context = self.context(target_roots=[jar_lib]) task = self.execute(context) compile_classpath = context.products.get_data('compile_classpath') jar_cp = compile_classpath.get_for_target(jar_lib) # └─ junit:junit:4.12 # └─ org.hamcrest:hamcrest-core:1.3 self.assertEquals(2, len(jar_cp)) # Take a sample jar path, remove it, then call the task again, it should invoke coursier again conf, path = jar_cp[0] # Remove the hard link under .pants.d/ safe_remove(path) # Remove coursier's cache safe_rmtree(couriser_cache_dir) task.runjava = MagicMock() # Ignore any error because runjava may fail due to undefined behavior try: task.execute() except TaskError: pass task.runjava.assert_called()
def test_open_files(self): safe_remove(TESTFN) # needed after UNIX socket test has run with open(TESTFN, 'w'): self.execute('open_files')
def setUp(self): safe_remove(TESTFN)