def getSharedInstance(): global tls if hasattr(tls, 'instance'): return tls.instance if os.environ.get('TESTING_VIA_BUCK', '0') == '1': # Ensure that the temporary dir is configured TempDir.get_temp_dir().get_dir() tls.instance = Instance() tls.instance.start() return tls.instance
def getSharedInstance(): global tls if hasattr(tls, "instance"): return tls.instance if os.environ.get("TESTING_VIA_BUCK", "0") == "1": # Ensure that the temporary dir is configured TempDir.get_temp_dir().get_dir() tls.instance = Instance() tls.instance.start() return tls.instance
def getSharedInstance(): global tls if hasattr(tls, "instance"): return tls.instance # Ensure that the temporary dir is configured TempDir.get_temp_dir().get_dir() inst = Instance() inst.start() setSharedInstance(inst) return tls.instance
def runTest(self): env = os.environ.copy() env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance( ).getSockPath() dotted = os.path.normpath(self.id()).replace(os.sep, '.').replace( 'tests.integration.', '').replace('.php', '') env['TMPDIR'] = os.path.join(TempDir.get_temp_dir().get_dir(), dotted) os.mkdir(env['TMPDIR']) # build the node module with npm node_dir = os.path.join(env['TMPDIR'], 'fb-watchman') shutil.copytree(os.path.join(WATCHMAN_SRC_DIR, 'node'), node_dir) subprocess.check_call(['npm', 'install'], cwd=node_dir) env['TMP'] = env['TMPDIR'] env['TEMP'] = env['TMPDIR'] env['IN_PYTHON_HARNESS'] = '1' env['NODE_PATH'] = '%s:%s' % (env['TMPDIR'], env.get('NODE_PATH', '')) proc = subprocess.Popen(self.getCommandArgs(), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = proc.communicate() status = proc.poll() if status == -signal.SIGINT: Interrupt.setInterrupted() self.fail('Interrupted by SIGINT') return if status != 0: self.fail("Exit status %d\n%s\n%s\n" % (status, stdout.decode('utf-8'), stderr.decode('utf-8'))) return self.assertTrue(True, self.getCommandArgs())
def run(self, result): if result is None: raise Exception("MUST be a runtests.py:Result instance") # Arrange for any temporary stuff we create to go under # our global tempdir and put it in a dir named for the test id = "%s.%s.%s" % (self.id(), self.transport, self.encoding) try: self.tempdir = os.path.join(TempDir.get_temp_dir().get_dir(), id) if self.attempt > 0: self.tempdir += "-%d" % self.attempt os.mkdir(self.tempdir) self.__logTestInfo(id, "BEGIN") super(WatchmanTestCase, self).run(result) finally: try: self.watchmanCommand("log-level", "off") self.getClient().getLog(remove=True) except Exception: pass self.__logTestInfo(id, "END") self.__clearWatches() self.__clearClient() return result
def runTest(self): env = os.environ.copy() env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance().getSockPath() dotted = os.path.normpath(self.id()).replace(os.sep, '.').replace( 'tests.integration.', '').replace('.php', '') env['TMPDIR'] = os.path.join(TempDir.get_temp_dir().get_dir(), dotted) os.mkdir(env['TMPDIR']) # build the node module with npm node_dir = os.path.join(env['TMPDIR'], 'fb-watchman') shutil.copytree(os.path.join(WATCHMAN_SRC_DIR, 'node'), node_dir) subprocess.check_call(['npm', 'install'], cwd=node_dir) env['TMP'] = env['TMPDIR'] env['TEMP'] = env['TMPDIR'] env['IN_PYTHON_HARNESS'] = '1' env['NODE_PATH'] = '%s:%s' % (env['TMPDIR'], env.get('NODE_PATH', '')) proc = subprocess.Popen( self.getCommandArgs(), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = proc.communicate() status = proc.poll() if status == -signal.SIGINT: Interrupt.setInterrupted() self.fail('Interrupted by SIGINT') return if status != 0: self.fail("Exit status %d\n%s\n%s\n" % (status, stdout.decode('utf-8'), stderr.decode('utf-8'))) return self.assertTrue(True, self.getCommandArgs())
def run(self, result): if result is None: raise Exception('MUST be a runtests.py:Result instance') # Arrange for any temporary stuff we create to go under # our global tempdir and put it in a dir named for the test id = '%s.%s.%s' % (self.id(), self.transport, self.encoding) try: self.tempdir = os.path.join(TempDir.get_temp_dir().get_dir(), id) os.mkdir(self.tempdir) self.__logTestInfo(id, 'BEGIN') super(WatchmanTestCase, self).run(result) finally: try: self.watchmanCommand('log-level', 'off') self.getClient().getLog(remove=True) except: pass self.__logTestInfo(id, 'END') self.__clearWatches() if hasattr(self, 'client'): self.client.close() delattr(self, 'client') return result
def mkdtemp(suffix='', prefix='tmp', dir=None): if dir is None: dir = '' # TODO: Make suffix actually follow the rest of the filename. path, err = TempDir(dir, prefix + '-' + suffix) if err: raise OSError(err.Error()) return path
def getCommandArgs(self): return [ php_bin, '-d variables_order=EGPCS', '-d register_argc_argv=1', '-d sys_temp_dir=%s' % TempDir.get_temp_dir().get_dir(), phprunner, phpfile, ]
def setUp(self): super(TempDirPerTestMixin, self).setUp() id = self._getTempDirName() # Arrange for any temporary stuff we create to go under # our global tempdir and put it in a dir named for the test self.tempdir = os.path.join(TempDir.get_temp_dir().get_dir(), id) os.mkdir(self.tempdir)
def runTest(self): env = os.environ.copy() env["WATCHMAN_SOCK"] = WatchmanInstance.getSharedInstance().getSockPath() dotted = ( os.path.normpath(self.id()) .replace(os.sep, ".") .replace("tests.integration.", "") .replace(".php", "") ) if self.attempt > 0: dotted += "-%d" % self.attempt env["TMPDIR"] = os.path.join(TempDir.get_temp_dir().get_dir(), dotted) os.mkdir(env["TMPDIR"]) # build the node module with npm node_dir = os.path.join(env["TMPDIR"], "fb-watchman") shutil.copytree(os.path.join(WATCHMAN_SRC_DIR, "node"), node_dir) subprocess.check_call(["npm", "install"], cwd=node_dir) env["TMP"] = env["TMPDIR"] env["TEMP"] = env["TMPDIR"] env["IN_PYTHON_HARNESS"] = "1" env["NODE_PATH"] = "%s:%s" % (env["TMPDIR"], env.get("NODE_PATH", "")) proc = subprocess.Popen( self.getCommandArgs(), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) (stdout, stderr) = proc.communicate() status = proc.poll() if status == -signal.SIGINT: Interrupt.setInterrupted() self.fail("Interrupted by SIGINT") return if status != 0: self.fail( "Exit status %d\n%s\n%s\n" % (status, stdout.decode("utf-8"), stderr.decode("utf-8")) ) return self.assertTrue(True, self.getCommandArgs())
# Ensure that we find the watchman we built in the tests if args.watchman_path: bin_dir = os.path.dirname(args.watchman_path) else: bin_dir = os.path.dirname(__file__) os.environ['PYWATCHMAN_PATH'] = os.path.join(os.getcwd(), 'python') os.environ['WATCHMAN_PYTHON_BIN'] = \ os.path.abspath(os.path.join(os.getcwd(), 'python', 'bin')) os.environ['PATH'] = '%s%s%s' % (os.path.abspath(bin_dir), os.pathsep, os.environ['PATH']) # We'll put all our temporary stuff under one dir so that we # can clean it all up at the end temp_dir = TempDir.get_temp_dir(args.keep) def interrupt_handler(signo, frame): Interrupt.setInterrupted() signal.signal(signal.SIGINT, interrupt_handler) class Result(unittest.TestResult): # Make it easier to spot success/failure by coloring the status # green for pass, red for fail and yellow for skip. # also print the elapsed time per test transport = None encoding = None
else: bin_dir = os.path.dirname(__file__) os.environ["PYWATCHMAN_PATH"] = os.path.join(os.getcwd(), "python") os.environ["WATCHMAN_PYTHON_BIN"] = os.path.abspath( os.path.join(os.getcwd(), "python", "bin") ) os.environ["PATH"] = "%s%s%s" % ( os.path.abspath(bin_dir), os.pathsep, os.environ["PATH"], ) # We'll put all our temporary stuff under one dir so that we # can clean it all up at the end temp_dir = TempDir.get_temp_dir(args.keep) def interrupt_handler(signo, frame): Interrupt.setInterrupted() signal.signal(signal.SIGINT, interrupt_handler) class Result(unittest.TestResult): # Make it easier to spot success/failure by coloring the status # green for pass, red for fail and yellow for skip. # also print the elapsed time per test transport = None encoding = None
def runTest(self): env = os.environ.copy() env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance().getSockPath() def clean_file_name(name): name = name.replace(os.sep, '') name = name.replace('tests.integration', '') name = name.replace('.php', '') name = name.replace('_php', '') name = name.replace('.runTest', '') return name dotted = clean_file_name(os.path.normpath(self.id())) env['TMPDIR'] = os.path.join(TempDir.get_temp_dir().get_dir(), dotted) if os.name != 'nt' and len(env['TMPDIR']) > 94: self.fail('temp dir name %s is too long for unix domain sockets' % env['TMPDIR']) os.mkdir(env['TMPDIR']) env['TMP'] = env['TMPDIR'] env['TEMP'] = env['TMPDIR'] env['IN_PYTHON_HARNESS'] = '1' env['WATCHMAN_PYTHON_BINARY'] = sys.executable proc = subprocess.Popen( self.getCommandArgs(), cwd=env.get('WATCHMAN_SRC_DIR', os.getcwd()), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = proc.communicate() status = proc.poll() if status == -signal.SIGINT: Interrupt.setInterrupted() self.fail('Interrupted by SIGINT') return if status != 0: self.fail("Exit status %d\n%s\n%s\n" % (status, stdout, stderr)) return res_pat = re.compile(b'^(not )?ok (\d+) (.*)$') diag_pat = re.compile(b'^# (.*)$') plan_pat = re.compile(b'^1\.\.(\d+)$') # Now parse the TAP output lines = stdout.replace(b'\r\n', b'\n').split(b'\n') last_test = 0 diags = None plan = None for line in lines: res = plan_pat.match(line) if res: plan = int(res.group(1)) continue res = res_pat.match(line) if res: this_test = int(res.group(2)) if this_test != last_test + 1: print(stdout, stderr) self.fail('Expected test number %d, got %d' % ( last_test + 1, this_test)) last_test = this_test if res.group(1) == b'not ': # Failed msg = line if diags is not None: msg = msg + b'\n' + b'\n'.join(diags) self.fail(msg.decode('utf-8')) failed diags = None continue res = diag_pat.match(line) if res: if diags is None: diags = [] diags.append(res.group(1)) continue if line != b'': print('Invalid tap output from %s: %s' % (self.id(), line)) if plan is None: self.fail('no plan was observed') else: self.assertEqual(last_test, plan, '%s planned %d but executed %s tests' % ( self.id(), plan, last_test))