Python test.support.findfile() Examples
The following are 30
code examples of test.support.findfile().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
test.support
, or try the search function
.
Example #1
Source File: test_sndhdr.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_data(self): for filename, expected in ( ('sndhdr.8svx', ('8svx', 0, 1, 0, 8)), ('sndhdr.aifc', ('aifc', 44100, 2, 5, 16)), ('sndhdr.aiff', ('aiff', 44100, 2, 5, 16)), ('sndhdr.au', ('au', 44100, 2, 5.0, 16)), ('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)), ('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)), ('sndhdr.voc', ('voc', 0, 1, -1, 8)), ('sndhdr.wav', ('wav', 44100, 2, 5, 16)), ): filename = findfile(filename, subdir="sndhdrdata") what = sndhdr.what(filename) self.assertNotEqual(what, None, filename) self.assertSequenceEqual(what, expected) self.assertEqual(what.filetype, expected[0]) self.assertEqual(what.framerate, expected[1]) self.assertEqual(what.nchannels, expected[2]) self.assertEqual(what.nframes, expected[3]) self.assertEqual(what.sampwidth, expected[4])
Example #2
Source File: test_subprocess.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_pass_fds_inheritable(self): script = support.findfile("fd_status.py", subdir="subprocessdata") inheritable, non_inheritable = os.pipe() self.addCleanup(os.close, inheritable) self.addCleanup(os.close, non_inheritable) os.set_inheritable(inheritable, True) os.set_inheritable(non_inheritable, False) pass_fds = (inheritable, non_inheritable) args = [sys.executable, script] args += list(map(str, pass_fds)) p = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True, pass_fds=pass_fds) output, ignored = p.communicate() fds = set(map(int, output.split(b','))) # the inheritable file descriptor must be inherited, so its inheritable # flag must be set in the child process after fork() and before exec() self.assertEqual(fds, set(pass_fds), "output=%a" % output) # inheritable flag must not be changed in the parent process self.assertEqual(os.get_inheritable(inheritable), True) self.assertEqual(os.get_inheritable(non_inheritable), False)
Example #3
Source File: test_subprocess.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_pipe_cloexec(self): sleeper = support.findfile("input_reader.py", subdir="subprocessdata") fd_status = support.findfile("fd_status.py", subdir="subprocessdata") p1 = subprocess.Popen([sys.executable, sleeper], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=False) self.addCleanup(p1.communicate, b'') p2 = subprocess.Popen([sys.executable, fd_status], stdout=subprocess.PIPE, close_fds=False) output, error = p2.communicate() result_fds = set(map(int, output.split(b','))) unwanted_fds = set([p1.stdin.fileno(), p1.stdout.fileno(), p1.stderr.fileno()]) self.assertFalse(result_fds & unwanted_fds, "Expected no fds from %r to be open in child, " "found %r" % (unwanted_fds, result_fds & unwanted_fds))
Example #4
Source File: test_tarfile.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_test_command_invalid_file(self): zipname = support.findfile('zipdir.zip') rc, out, err = self.tarfilecmd_failure('-t', zipname) self.assertIn(b' is not a tar archive.', err) self.assertEqual(out, b'') self.assertEqual(rc, 1) for tar_name in testtarnames: with self.subTest(tar_name=tar_name): with open(tar_name, 'rb') as f: data = f.read() try: with open(tmpname, 'wb') as f: f.write(data[:511]) rc, out, err = self.tarfilecmd_failure('-t', tmpname) self.assertEqual(out, b'') self.assertEqual(rc, 1) finally: support.unlink(tmpname)
Example #5
Source File: test_tarfile.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_test_command_invalid_file(self): zipname = support.findfile('zipdir.zip') rc, out, err = self.tarfilecmd_failure('-t', zipname) self.assertIn(b' is not a tar archive.', err) self.assertEqual(out, b'') self.assertEqual(rc, 1) for tar_name in testtarnames: with self.subTest(tar_name=tar_name): with open(tar_name, 'rb') as f: data = f.read() try: with open(tmpname, 'wb') as f: f.write(data[:511]) rc, out, err = self.tarfilecmd_failure('-t', tmpname) self.assertEqual(out, b'') self.assertEqual(rc, 1) finally: support.unlink(tmpname)
Example #6
Source File: test_subprocess.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_close_fds_after_preexec(self): fd_status = support.findfile("fd_status.py", subdir="subprocessdata") # this FD is used as dup2() target by preexec_fn, and should be closed # in the child process fd = os.dup(1) self.addCleanup(os.close, fd) p = subprocess.Popen([sys.executable, fd_status], stdout=subprocess.PIPE, close_fds=True, preexec_fn=lambda: os.dup2(1, fd)) output, ignored = p.communicate() remaining_fds = set(map(int, output.split(b','))) self.assertNotIn(fd, remaining_fds)
Example #7
Source File: test_subprocess.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_pipe_cloexec(self): sleeper = support.findfile("input_reader.py", subdir="subprocessdata") fd_status = support.findfile("fd_status.py", subdir="subprocessdata") p1 = subprocess.Popen([sys.executable, sleeper], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=False) self.addCleanup(p1.communicate, b'') p2 = subprocess.Popen([sys.executable, fd_status], stdout=subprocess.PIPE, close_fds=False) output, error = p2.communicate() result_fds = set(map(int, output.split(b','))) unwanted_fds = set([p1.stdin.fileno(), p1.stdout.fileno(), p1.stderr.fileno()]) self.assertFalse(result_fds & unwanted_fds, "Expected no fds from %r to be open in child, " "found %r" % (unwanted_fds, result_fds & unwanted_fds))
Example #8
Source File: test_subprocess.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_close_fds_after_preexec(self): fd_status = support.findfile("fd_status.py", subdir="subprocessdata") # this FD is used as dup2() target by preexec_fn, and should be closed # in the child process fd = os.dup(1) self.addCleanup(os.close, fd) p = subprocess.Popen([sys.executable, fd_status], stdout=subprocess.PIPE, close_fds=True, preexec_fn=lambda: os.dup2(1, fd)) output, ignored = p.communicate() remaining_fds = set(map(int, output.split(b','))) self.assertNotIn(fd, remaining_fds)
Example #9
Source File: test_configparser.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_read_returns_file_list(self): if self.delimiters[0] != '=': self.skipTest('incompatible format') file1 = support.findfile("cfgparser.1") # check when we pass a mix of readable and non-readable files: cf = self.newconfig() parsed_files = cf.read([file1, "nonexistent-file"]) self.assertEqual(parsed_files, [file1]) self.assertEqual(cf.get("Foo Bar", "foo"), "newbar") # check when we pass only a filename: cf = self.newconfig() parsed_files = cf.read(file1) self.assertEqual(parsed_files, [file1]) self.assertEqual(cf.get("Foo Bar", "foo"), "newbar") # check when we pass only missing files: cf = self.newconfig() parsed_files = cf.read(["nonexistent-file"]) self.assertEqual(parsed_files, []) # check when we pass no files: cf = self.newconfig() parsed_files = cf.read([]) self.assertEqual(parsed_files, []) # shared by subclasses
Example #10
Source File: test_tokenize.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_random_files(self): # Test roundtrip on random python modules. # pass the '-ucpu' option to process the full directory. import glob, random fn = support.findfile("tokenize_tests.txt") tempdir = os.path.dirname(fn) or os.curdir testfiles = glob.glob(os.path.join(tempdir, "test*.py")) # Tokenize is broken on test_pep3131.py because regular expressions are # broken on the obscure unicode identifiers in it. *sigh* # With roundtrip extended to test the 5-tuple mode of untokenize, # 7 more testfiles fail. Remove them also until the failure is diagnosed. testfiles.remove(os.path.join(tempdir, "test_pep3131.py")) for f in ('buffer', 'builtin', 'fileio', 'inspect', 'os', 'platform', 'sys'): testfiles.remove(os.path.join(tempdir, "test_%s.py") % f) if not support.is_resource_enabled("cpu"): testfiles = random.sample(testfiles, 10) for testfile in testfiles: with open(testfile, 'rb') as f: with self.subTest(file=testfile): self.check_roundtrip(f)
Example #11
Source File: test_configparser.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_read_returns_file_list(self): if self.delimiters[0] != '=': self.skipTest('incompatible format') file1 = support.findfile("cfgparser.1") # check when we pass a mix of readable and non-readable files: cf = self.newconfig() parsed_files = cf.read([file1, "nonexistent-file"]) self.assertEqual(parsed_files, [file1]) self.assertEqual(cf.get("Foo Bar", "foo"), "newbar") # check when we pass only a filename: cf = self.newconfig() parsed_files = cf.read(file1) self.assertEqual(parsed_files, [file1]) self.assertEqual(cf.get("Foo Bar", "foo"), "newbar") # check when we pass only missing files: cf = self.newconfig() parsed_files = cf.read(["nonexistent-file"]) self.assertEqual(parsed_files, []) # check when we pass no files: cf = self.newconfig() parsed_files = cf.read([]) self.assertEqual(parsed_files, []) # shared by subclasses
Example #12
Source File: test_sndhdr.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_data(self): for filename, expected in ( ('sndhdr.8svx', ('8svx', 0, 1, 0, 8)), ('sndhdr.aifc', ('aifc', 44100, 2, 5, 16)), ('sndhdr.aiff', ('aiff', 44100, 2, 5, 16)), ('sndhdr.au', ('au', 44100, 2, 5.0, 16)), ('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)), ('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)), ('sndhdr.voc', ('voc', 0, 1, -1, 8)), ('sndhdr.wav', ('wav', 44100, 2, 5, 16)), ): filename = findfile(filename, subdir="sndhdrdata") what = sndhdr.what(filename) self.assertNotEqual(what, None, filename) self.assertSequenceEqual(what, expected) self.assertEqual(what.filetype, expected[0]) self.assertEqual(what.framerate, expected[1]) self.assertEqual(what.nchannels, expected[2]) self.assertEqual(what.nframes, expected[3]) self.assertEqual(what.sampwidth, expected[4])
Example #13
Source File: test_images.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def check_create_from_data(self, ext): testfile = support.findfile('python.' + ext, subdir='imghdrdata') with open(testfile, 'rb') as f: data = f.read() image = tkinter.PhotoImage('::img::test', master=self.root, data=data) self.assertEqual(str(image), '::img::test') self.assertEqual(image.type(), 'photo') self.assertEqual(image.width(), 16) self.assertEqual(image.height(), 16) self.assertEqual(image['data'], data if self.wantobjects else data.decode('latin1')) self.assertEqual(image['file'], '') self.assertIn('::img::test', self.root.image_names()) del image self.assertNotIn('::img::test', self.root.image_names())
Example #14
Source File: test_images.py From ironpython3 with Apache License 2.0 | 6 votes |
def check_create_from_data(self, ext): testfile = support.findfile('python.' + ext, subdir='imghdrdata') with open(testfile, 'rb') as f: data = f.read() image = tkinter.PhotoImage('::img::test', master=self.root, data=data) self.assertEqual(str(image), '::img::test') self.assertEqual(image.type(), 'photo') self.assertEqual(image.width(), 16) self.assertEqual(image.height(), 16) self.assertEqual(image['data'], data if self.wantobjects else data.decode('latin1')) self.assertEqual(image['file'], '') self.assertIn('::img::test', self.root.image_names()) del image self.assertNotIn('::img::test', self.root.image_names())
Example #15
Source File: test_configparser.py From configparser with MIT License | 6 votes |
def test_reading(self): smbconf = support.findfile("cfgparser.2") # check when we pass a mix of readable and non-readable files: cf = self.newconfig() parsed_files = cf.read([smbconf, "nonexistent-file"], encoding='utf-8') self.assertEqual(parsed_files, [smbconf]) sections = [ 'global', 'homes', 'printers', 'print$', 'pdf-generator', 'tmp', 'Agustin', ] self.assertEqual(cf.sections(), sections) self.assertEqual(cf.get("global", "workgroup"), "MDKGROUP") self.assertEqual(cf.getint("global", "max log size"), 50) self.assertEqual(cf.get("global", "hosts allow"), "127.") self.assertEqual(cf.get("tmp", "echo command"), "cat %s; rm %s")
Example #16
Source File: test_configparser.py From configparser with MIT License | 6 votes |
def test_read_returns_file_list_with_bytestring_path(self): if self.delimiters[0] != '=': self.skipTest('incompatible format') file1_bytestring = support.findfile("cfgparser.1").encode() # check when passing an existing bytestring path cf = self.newconfig() parsed_files = cf.read(file1_bytestring) self.assertEqual(parsed_files, [file1_bytestring]) # check when passing an non-existing bytestring path cf = self.newconfig() parsed_files = cf.read(b'nonexistent-file') self.assertEqual(parsed_files, []) # check when passing both an existing and non-existing bytestring path cf = self.newconfig() parsed_files = cf.read([file1_bytestring, b'nonexistent-file']) self.assertEqual(parsed_files, [file1_bytestring]) # shared by subclasses
Example #17
Source File: test_tarfile.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_create_command_dotless_filename(self): files = [support.findfile('tokenize_tests.txt')] try: out = self.tarfilecmd('-c', dotlessname, *files) self.assertEqual(out, b'') with tarfile.open(dotlessname) as tar: tar.getmembers() finally: support.unlink(dotlessname)
Example #18
Source File: test_tarfile.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_create_command_dot_started_filename(self): tar_name = os.path.join(TEMPDIR, ".testtar") files = [support.findfile('tokenize_tests.txt')] try: out = self.tarfilecmd('-c', tar_name, *files) self.assertEqual(out, b'') with tarfile.open(tar_name) as tar: tar.getmembers() finally: support.unlink(tar_name)
Example #19
Source File: test_pstats.py From ironpython3 with Apache License 2.0 | 5 votes |
def setUp(self): stats_file = support.findfile('pstats.pck') self.stats = pstats.Stats(stats_file)
Example #20
Source File: test_sndhdr.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_data(self): for filename, expected in ( ('sndhdr.8svx', ('8svx', 0, 1, 0, 8)), ('sndhdr.aifc', ('aifc', 44100, 2, 5, 16)), ('sndhdr.aiff', ('aiff', 44100, 2, 5, 16)), ('sndhdr.au', ('au', 44100, 2, 5.0, 16)), ('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)), ('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)), ('sndhdr.voc', ('voc', 0, 1, -1, 8)), ('sndhdr.wav', ('wav', 44100, 2, 5, 16)), ): filename = findfile(filename, subdir="sndhdrdata") what = sndhdr.what(filename) self.assertNotEqual(what, None, filename) self.assertSequenceEqual(what, expected)
Example #21
Source File: test_aifc.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_skipunknown(self): #Issue 2245 #This file contains chunk types aifc doesn't recognize. self.f = aifc.open(findfile('Sine-1000Hz-300ms.aif'))
Example #22
Source File: test_tarfile.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_create_command_verbose(self): files = [support.findfile('tokenize_tests.txt'), support.findfile('tokenize_tests-no-coding-cookie-' 'and-utf8-bom-sig-only.txt')] for opt in '-v', '--verbose': try: out = self.tarfilecmd(opt, '-c', tmpname, *files) self.assertIn(b' file created.', out) with tarfile.open(tmpname) as tar: tar.getmembers() finally: support.unlink(tmpname)
Example #23
Source File: test_tarfile.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_create_command(self): files = [support.findfile('tokenize_tests.txt'), support.findfile('tokenize_tests-no-coding-cookie-' 'and-utf8-bom-sig-only.txt')] for opt in '-c', '--create': try: out = self.tarfilecmd(opt, tmpname, *files) self.assertEqual(out, b'') with tarfile.open(tmpname) as tar: tar.getmembers() finally: support.unlink(tmpname)
Example #24
Source File: test_tarfile.py From ironpython3 with Apache License 2.0 | 5 votes |
def make_simple_tarfile(self, tar_name): files = [support.findfile('tokenize_tests.txt'), support.findfile('tokenize_tests-no-coding-cookie-' 'and-utf8-bom-sig-only.txt')] self.addCleanup(support.unlink, tar_name) with tarfile.open(tar_name, 'w') as tf: for tardata in files: tf.add(tardata, arcname=os.path.basename(tardata))
Example #25
Source File: test_ossaudiodev.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_playback(self): sound_info = read_sound_file(findfile('audiotest.au')) self.play_sound_file(*sound_info)
Example #26
Source File: test_imghdr.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_string_data(self): with warnings.catch_warnings(): warnings.simplefilter("ignore", BytesWarning) for filename, _ in TEST_FILES: filename = findfile(filename, subdir='imghdrdata') with open(filename, 'rb') as stream: data = stream.read().decode('latin1') with self.assertRaises(TypeError): imghdr.what(io.StringIO(data)) with self.assertRaises(TypeError): imghdr.what(None, data)
Example #27
Source File: test_imghdr.py From ironpython3 with Apache License 2.0 | 5 votes |
def setUpClass(cls): cls.testfile = findfile('python.png', subdir='imghdrdata') with open(cls.testfile, 'rb') as stream: cls.testdata = stream.read()
Example #28
Source File: audiotests.py From ironpython3 with Apache License 2.0 | 5 votes |
def setUpClass(cls): cls.sndfilepath = findfile(cls.sndfilename, subdir='audiodata')
Example #29
Source File: test_mimetypes.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_encoding(self): getpreferredencoding = locale.getpreferredencoding self.addCleanup(setattr, locale, 'getpreferredencoding', getpreferredencoding) locale.getpreferredencoding = lambda: 'ascii' filename = support.findfile("mime.types") mimes = mimetypes.MimeTypes([filename]) exts = mimes.guess_all_extensions('application/vnd.geocube+xml', strict=True) self.assertEqual(exts, ['.g3', '.g\xb3'])
Example #30
Source File: test_images.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def setUpClass(cls): AbstractTkTest.setUpClass.__func__(cls) cls.testfile = support.findfile('python.xbm', subdir='imghdrdata')