def test_tempdir(): with tempdir() as tdir: fpath = os.path.join(tdir, 'tmp') with open(fpath, 'w'): pass assert_(not os.path.isdir(tdir)) raised = False try: with tempdir() as tdir: raise ValueError() except ValueError: raised = True assert_(raised) assert_(not os.path.isdir(tdir))
def test_isfileobj(): with tempdir(prefix="numpy_test_compat_") as folder: filename = join(folder, 'a.bin') with open(filename, 'wb') as f: assert_(isfileobj(f)) with open(filename, 'ab') as f: assert_(isfileobj(f)) with open(filename, 'rb') as f: assert_(isfileobj(f))
def test_isfileobj(): with tempdir(prefix="numpy_test_compat_") as folder: filename = join(folder, "a.bin") with open(filename, "wb") as f: assert_(isfileobj(f)) with open(filename, "ab") as f: assert_(isfileobj(f)) with open(filename, "rb") as f: assert_(isfileobj(f))
def check_execute_in(self, **kws): with tempdir() as tmpdir: fn = "file" tmpfile = os.path.join(tmpdir, fn) with open(tmpfile, 'w') as f: f.write('Hello') s, o = exec_command.exec_command( '"%s" -c "f = open(\'%s\', \'r\'); f.close()"' % (self.pyexe, fn), **kws) assert_(s != 0) assert_(o != '') s, o = exec_command.exec_command( '"%s" -c "f = open(\'%s\', \'r\'); print(f.read()); ' 'f.close()"' % (self.pyexe, fn), execute_in=tmpdir, **kws) assert_(s == 0) assert_(o == 'Hello')
def check_execute_in(self, **kws): with tempdir() as tmpdir: fn = "file" tmpfile = os.path.join(tmpdir, fn) f = open(tmpfile, 'w') f.write('Hello') f.close() s, o = exec_command.exec_command( '"%s" -c "f = open(\'%s\', \'r\'); f.close()"' % (self.pyexe, fn), **kws) self.assertNotEqual(s, 0) self.assertNotEqual(o, '') s, o = exec_command.exec_command( '"%s" -c "f = open(\'%s\', \'r\'); print(f.read()); ' 'f.close()"' % (self.pyexe, fn), execute_in=tmpdir, **kws) self.assertEqual(s, 0) self.assertEqual(o, 'Hello')
def check_execute_in(self, **kws): with tempdir() as tmpdir: fn = "file" tmpfile = os.path.join(tmpdir, fn) f = open(tmpfile, 'w') f.write('Hello') f.close() s, o = exec_command.exec_command( '"%s" -c "f = open(\'%s\', \'r\'); f.close()"' % (self.pyexe, fn), **kws) assert_(s != 0) assert_(o != '') s, o = exec_command.exec_command( '"%s" -c "f = open(\'%s\', \'r\'); print(f.read()); ' 'f.close()"' % (self.pyexe, fn), execute_in=tmpdir, **kws) assert_(s == 0) assert_(o == 'Hello')
def get_targets(self, targets, groups, **kwargs): FakeCCompilerOpt.conf_target_groups = groups opt = self.nopt( cpu_baseline=kwargs.get("baseline", "min"), cpu_dispatch=kwargs.get("dispatch", "max"), trap_files=kwargs.get("trap_files", ""), trap_flags=kwargs.get("trap_flags", "") ) with tempdir() as tmpdir: file = os.path.join(tmpdir, "test_targets.c") with open(file, 'w') as f: f.write(targets) gtargets = [] gflags = {} fake_objects = opt.try_dispatch([file]) for source, flags in fake_objects: gtar = path.basename(source).split('.')[1:-1] glen = len(gtar) if glen == 0: gtar = "baseline" elif glen == 1: gtar = gtar[0].upper() else: # converting multi-target into parentheses str format to be equivalent # to the configuration statements syntax. gtar = ('('+' '.join(gtar)+')').upper() gtargets.append(gtar) gflags[gtar] = flags has_baseline, targets = opt.sources_status[file] targets = targets + ["baseline"] if has_baseline else targets # convert tuple that represent multi-target into parentheses str format targets = [ '('+' '.join(tar)+')' if isinstance(tar, tuple) else tar for tar in targets ] if len(targets) != len(gtargets) or not all(t in gtargets for t in targets): raise AssertionError( "'sources_status' returns different targets than the compiled targets\n" "%s != %s" % (targets, gtargets) ) # return targets from 'sources_status' since the order is matters return targets, gflags
def check_execute_in(self, **kws): with tempdir() as tmpdir: fn = "file" tmpfile = os.path.join(tmpdir, fn) with open(tmpfile, "w") as f: f.write("Hello") s, o = exec_command.exec_command( "\"%s\" -c \"f = open('%s', 'r'); f.close()\"" % (self.pyexe, fn), **kws ) assert_(s != 0) assert_(o != "") s, o = exec_command.exec_command( "\"%s\" -c \"f = open('%s', 'r'); print(f.read()); " 'f.close()"' % (self.pyexe, fn), execute_in=tmpdir, **kws ) assert_(s == 0) assert_(o == "Hello")