def test_getline(self): getline = linecache.getline # Bad values for line number should return an empty string self.assertEqual(getline(FILENAME, 2**15), EMPTY) self.assertEqual(getline(FILENAME, -1), EMPTY) # Float values currently raise TypeError, should it? self.assertRaises(TypeError, getline, FILENAME, 1.1) # Bad filenames should return an empty string self.assertEqual(getline(EMPTY, 1), EMPTY) self.assertEqual(getline(INVALID_NAME, 1), EMPTY) # Check whether lines correspond to those from file iteration for entry in TESTS: filename = support.findfile( entry + '.py') for index, line in enumerate(open(filename)): self.assertEqual(line, getline(filename, index + 1)) # Check module loading for entry in MODULES: filename = support.findfile( entry + '.py') for index, line in enumerate(open(filename)): self.assertEqual(line, getline(filename, index + 1)) # Check that bogus data isn't returned (issue #1309567) empty = linecache.getlines('a/b/c/__init__.py') self.assertEqual(empty, [])
def test_getline(self): getline = linecache.getline # Bad values for line number should return an empty string self.assertEqual(getline(FILENAME, 2**15), EMPTY) self.assertEqual(getline(FILENAME, -1), EMPTY) # Float values currently raise TypeError, should it? self.assertRaises(TypeError, getline, FILENAME, 1.1) # Bad filenames should return an empty string self.assertEqual(getline(EMPTY, 1), EMPTY) self.assertEqual(getline(INVALID_NAME, 1), EMPTY) # Check whether lines correspond to those from file iteration for entry in TESTS: filename = support.findfile(entry + '.py') for index, line in enumerate(open(filename)): self.assertEqual(line, getline(filename, index + 1)) # Check module loading for entry in MODULES: filename = support.findfile(entry + '.py') for index, line in enumerate(open(filename)): self.assertEqual(line, getline(filename, index + 1)) # Check that bogus data isn't returned (issue #1309567) empty = linecache.getlines('a/b/c/__init__.py') self.assertEqual(empty, [])
def test_expat_locator_withinfo(): result = StringIO() xmlgen = XMLGenerator(result) parser = create_parser() parser.setContentHandler(xmlgen) parser.parse(findfile("test.xml")) return parser.getSystemId() == findfile("test.xml") and parser.getPublicId() is None
def test_expat_locator_withinfo(self): result = StringIO() xmlgen = XMLGenerator(result) parser = create_parser() parser.setContentHandler(xmlgen) parser.parse(findfile("test.xml")) self.assertEquals(parser.getSystemId(), findfile("test.xml")) self.assertEquals(parser.getPublicId(), None)
def test_expat_locator_withinfo(): result = StringIO() xmlgen = LocatorTest(result) parser = make_parser() parser.setContentHandler(xmlgen) parser.parse(findfile("test.xml")) return xmlgen.location.getSystemId() == findfile("test.xml") and \ xmlgen.location.getPublicId() is None
def test_expat_locator_withinfo(): result = StringIO() xmlgen = XMLGenerator(result) parser = create_parser() parser.setContentHandler(xmlgen) parser.parse(findfile("test.xml")) return parser.getSystemId() == findfile("test.xml") and \ parser.getPublicId() is None
def make_test_output(): parser = make_parser() result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) parser.parse(findfile("test.xml")) outf = open(findfile("test.xml.out"), "w") outf.write(result.getvalue()) outf.close()
def make_test_output(): parser = create_parser() result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) parser.parse(findfile("test" + os.extsep + "xml")) outf = open(findfile("test" + os.extsep + "xml" + os.extsep + "out"), "w") outf.write(result.getvalue()) outf.close()
def test_syspath_initializer(self): fn = test_support.findfile('check_for_initializer_in_syspath.py') jar = test_support.findfile('syspath_initializer.jar') env = dict(CLASSPATH=jar, PATH=os.environ.get('PATH', '')) if WINDOWS: # TMP is needed to give property java.io.tmpdir a sensible value env['TMP'] = os.environ.get('TMP', '.') # SystemRoot is needed to remote debug the subprocess JVM env['SystemRoot'] = os.environ.get('SystemRoot', '') self.assertEquals(0, subprocess.call([sys.executable, fn], env=env))
def test_main(): uu.decode(findfile("testrgb.uue"), "test.rgb") uu.decode(findfile("greyrgb.uue"), "greytest.rgb") # Test a 3 byte color image testimage("test.rgb") # Test a 1 byte greyscale image testimage("greytest.rgb") unlink("test.rgb") unlink("greytest.rgb")
def test_main(): uu.decode(findfile('testrgb.uue'), 'test.rgb') uu.decode(findfile('greyrgb.uue'), 'greytest.rgb') # Test a 3 byte color image testimage('test.rgb') # Test a 1 byte greyscale image testimage('greytest.rgb') unlink('test.rgb') unlink('greytest.rgb')
def testimg(rgb_file, raw_file): rgb_file = findfile(rgb_file) raw_file = findfile(raw_file) width, height = rgbimg.sizeofimage(rgb_file) rgb = rgbimg.longimagedata(rgb_file) if len(rgb) != width * height * 4: raise error, 'bad image length' raw = open(raw_file, 'rb').read() if rgb != raw: raise error, \ 'images don\'t match for '+rgb_file+' and '+raw_file for depth in [1, 3, 4]: rgbimg.longstoimage(rgb, width, height, depth, '@.rgb') os.unlink('@.rgb')
def test_expat_file(): parser = make_parser() result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) parser.parse(open(findfile("test.xml"))) #print result.getvalue() , xml_test_out f = open(findfile("test.xml.result"), 'wt') f.write(result.getvalue()) f.close() return result.getvalue() == xml_test_out
def load_teststring(name): dir = test_support.findfile('cjkencodings') with open(os.path.join(dir, name + '.txt'), 'rb') as f: encoded = f.read() with open(os.path.join(dir, name + '-utf8.txt'), 'rb') as f: utf8 = f.read() return encoded, utf8
def setClassLoaderAndCheck(self, orig_jar, prefix, compile_path=''): # Create a new jar and compile prefer_compiled into it orig_jar = test_support.findfile(orig_jar) jar = os.path.join(self.temp_dir, os.path.basename(orig_jar)) shutil.copy(orig_jar, jar) code = os.path.join(self.temp_dir, 'prefer_compiled.py') fp = open(code, 'w') fp.write('compiled = True') fp.close() py_compile.compile(code) zip = zipfile.ZipFile(jar, 'a') zip.write( os.path.join(self.temp_dir, 'prefer_compiled$py.class'), os.path.join(compile_path, 'jar_pkg', 'prefer_compiled$py.class')) zip.close() Thread.currentThread( ).contextClassLoader = test_support.make_jar_classloader(jar) import flat_in_jar self.assertEquals(flat_in_jar.value, 7) import jar_pkg self.assertEquals(prefix + '/jar_pkg/__init__.py', jar_pkg.__file__) from jar_pkg import prefer_compiled self.assertEquals(prefix + '/jar_pkg/prefer_compiled$py.class', prefer_compiled.__file__) self.assert_(prefer_compiled.compiled) self.assertRaises(NameError, __import__, 'flat_bad') self.assertRaises(NameError, __import__, 'jar_pkg.bad')
def setClassLoaderAndCheck(self, orig_jar, prefix, compile_path=''): # Create a new jar and compile prefer_compiled into it orig_jar = test_support.findfile(orig_jar) jar = os.path.join(self.temp_dir, os.path.basename(orig_jar)) shutil.copy(orig_jar, jar) code = os.path.join(self.temp_dir, 'prefer_compiled.py') fp = open(code, 'w') fp.write('compiled = True') fp.close() py_compile.compile(code) zip = zipfile.ZipFile(jar, 'a') zip.write(os.path.join(self.temp_dir, 'prefer_compiled$py.class'), os.path.join(compile_path, 'jar_pkg', 'prefer_compiled$py.class')) zip.close() Thread.currentThread().contextClassLoader = test_support.make_jar_classloader(jar) import flat_in_jar self.assertEquals(flat_in_jar.value, 7) import jar_pkg self.assertEquals(prefix + '/jar_pkg/__init__.py', jar_pkg.__file__) from jar_pkg import prefer_compiled self.assertEquals(prefix + '/jar_pkg/prefer_compiled$py.class', prefer_compiled.__file__) self.assert_(prefer_compiled.compiled) self.assertRaises(NameError, __import__, 'flat_bad') self.assertRaises(NameError, __import__, 'jar_pkg.bad')
def test_import_star(self): self.assertEquals( 0, subprocess.call([ sys.executable, test_support.findfile("import_star_from_java.py") ]))
def test_print_sans_lib(self): # Encode and decode using utf-8 in an environment without the standard # library, to check that a utf-8 codec is always available. See: # http://bugs.jython.org/issue1458 subprocess.call([sys.executable, "-J-Dpython.cachedir.skip=true", "-S", # No site module: avoid codec registry initialised too soon test_support.findfile('print_sans_lib.py')])
class BaseTest(unittest.TestCase): "Base for other testcases." TEXT = 'root:x:0:0:root:/root:/bin/bash\nbin:x:1:1:bin:/bin:\ndaemon:x:2:2:daemon:/sbin:\nadm:x:3:4:adm:/var/adm:\nlp:x:4:7:lp:/var/spool/lpd:\nsync:x:5:0:sync:/sbin:/bin/sync\nshutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\nhalt:x:7:0:halt:/sbin:/sbin/halt\nmail:x:8:12:mail:/var/spool/mail:\nnews:x:9:13:news:/var/spool/news:\nuucp:x:10:14:uucp:/var/spool/uucp:\noperator:x:11:0:operator:/root:\ngames:x:12:100:games:/usr/games:\ngopher:x:13:30:gopher:/usr/lib/gopher-data:\nftp:x:14:50:FTP User:/var/ftp:/bin/bash\nnobody:x:65534:65534:Nobody:/home:\npostfix:x:100:101:postfix:/var/spool/postfix:\nniemeyer:x:500:500::/home/niemeyer:/bin/bash\npostgres:x:101:102:PostgreSQL Server:/var/lib/pgsql:/bin/bash\nmysql:x:102:103:MySQL server:/var/lib/mysql:/bin/bash\nwww:x:103:104::/var/www:/bin/false\n' DATA = 'BZh91AY&SY.\xc8N\x18\x00\x01>_\x80\x00\x10@\x02\xff\xf0\x01\x07n\x00?\xe7\xff\xe00\x01\x99\xaa\x00\xc0\x03F\x86\x8c#&\x83F\x9a\x03\x06\xa6\xd0\xa6\x93M\x0fQ\xa7\xa8\x06\x804hh\x12$\x11\xa4i4\xf14S\xd2<Q\xb5\x0fH\xd3\xd4\xdd\xd5\x87\xbb\xf8\x94\r\x8f\xafI\x12\xe1\xc9\xf8/E\x00pu\x89\x12]\xc9\xbbDL\nQ\x0e\t1\x12\xdf\xa0\xc0\x97\xac2O9\x89\x13\x94\x0e\x1c7\x0ed\x95I\x0c\xaaJ\xa4\x18L\x10\x05#\x9c\xaf\xba\xbc/\x97\x8a#C\xc8\xe1\x8cW\xf9\xe2\xd0\xd6M\xa7\x8bXa<e\x84t\xcbL\xb3\xa7\xd9\xcd\xd1\xcb\x84.\xaf\xb3\xab\xab\xad`n}\xa0lh\tE,\x8eZ\x15\x17VH>\x88\xe5\xcd9gd6\x0b\n\xe9\x9b\xd5\x8a\x99\xf7\x08.K\x8ev\xfb\xf7xw\xbb\xdf\xa1\x92\xf1\xdd|/";\xa2\xba\x9f\xd5\xb1#A\xb6\xf6\xb3o\xc9\xc5y\\\xebO\xe7\x85\x9a\xbc\xb6f8\x952\xd5\xd7"%\x89>V,\xf7\xa6z\xe2\x9f\xa3\xdf\x11\x11"\xd6E)I\xa9\x13^\xca\xf3r\xd0\x03U\x922\xf26\xec\xb6\xed\x8b\xc3U\x13\x9d\xc5\x170\xa4\xfa^\x92\xacDF\x8a\x97\xd6\x19\xfe\xdd\xb8\xbd\x1a\x9a\x19\xa3\x80ankR\x8b\xe5\xd83]\xa9\xc6\x08\x82f\xf6\xb9"6l$\xb8j@\xc0\x8a\xb0l1..\xbak\x83ls\x15\xbc\xf4\xc1\x13\xbe\xf8E\xb8\x9d\r\xa8\x9dk\x84\xd3n\xfa\xacQ\x07\xb1%y\xaav\xb4\x08\xe0z\x1b\x16\xf5\x04\xe9\xcc\xb9\x08z\x1en7.G\xfc]\xc9\x14\xe1B@\xbb!8`' DATA_CRLF = 'BZh91AY&SY\xaez\xbbN\x00\x01H\xdf\x80\x00\x12@\x02\xff\xf0\x01\x07n\x00?\xe7\xff\xe0@\x01\xbc\xc6`\x86*\x8d=M\xa9\x9a\x86\xd0L@\x0fI\xa6!\xa1\x13\xc8\x88jdi\x8d@\x03@\x1a\x1a\x0c\x0c\x83 \x00\xc4h2\x19\x01\x82D\x84e\t\xe8\x99\x89\x19\x1ah\x00\r\x1a\x11\xaf\x9b\x0fG\xf5(\x1b\x1f?\t\x12\xcf\xb5\xfc\x95E\x00ps\x89\x12^\xa4\xdd\xa2&\x05(\x87\x04\x98\x89u\xe40%\xb6\x19\'\x8c\xc4\x89\xca\x07\x0e\x1b!\x91UIFU%C\x994!DI\xd2\xfa\xf0\xf1N8W\xde\x13A\xf5\x9cr%?\x9f3;I45A\xd1\x8bT\xb1<l\xba\xcb_\xc00xY\x17r\x17\x88\x08\x08@\xa0\ry@\x10\x04$)`\xf2\xce\x89z\xb0s\xec\x9b.iW\x9d\x81\xb5-+t\x9f\x1a\'\x97dB\xf5x\xb5\xbe.[.\xd7\x0e\x81\xe7\x08\x1cN`\x88\x10\xca\x87\xc3!"\x80\x92R\xa1/\xd1\xc0\xe6mf\xac\xbd\x99\xcca\xb3\x8780>\xa4\xc7\x8d\x1a\\"\xad\xa1\xabyBg\x15\xb9l\x88\x88\x91k"\x94\xa4\xd4\x89\xae*\xa6\x0b\x10\x0c\xd6\xd4m\xe86\xec\xb5j\x8a\x86j\';\xca.\x01I\xf2\xaaJ\xe8\x88\x8cU+t3\xfb\x0c\n\xa33\x13r2\r\x16\xe0\xb3(\xbf\x1d\x83r\xe7M\xf0D\x1365\xd8\x88\xd3\xa4\x92\xcb2\x06\x04\\\xc1\xb0\xea//\xbek&\xd8\xe6+t\xe5\xa1\x13\xada\x16\xder5"w]\xa2i\xb7[\x97R \xe2IT\xcd;Z\x04dk4\xad\x8a\t\xd3\x81z\x10\xf1:^`\xab\x1f\xc5\xdc\x91N\x14$+\x9e\xae\xd3\x80' EMPTY_DATA = 'BZh9\x17rE8P\x90\x00\x00\x00\x00' with open(findfile("testbz2_bigmem.bz2"), "rb") as f: DATA_BIGMEM = f.read() if has_cmdline_bunzip2: def decompress(self, data): pop = subprocess.Popen("bunzip2", shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) pop.stdin.write(data) pop.stdin.close() ret = pop.stdout.read() pop.stdout.close() if pop.wait() != 0: ret = bz2.decompress(data) return ret else: # bunzip2 isn't available to run on Windows. def decompress(self, data): return bz2.decompress(data)
def test_main(): if verbose: print 'starting...' # This displays the tokenization of tokenize_tests.py to stdout, and # regrtest.py checks that this equals the expected output (in the # test/output/ directory). f = open(findfile('tokenize_tests' + os.extsep + 'txt')) tokenize(f.readline) f.close() # Now run test_roundtrip() over tokenize_test.py too, and over all # (if the "compiler" resource is enabled) or a small random sample (if # "compiler" is not enabled) of the test*.py files. f = findfile('tokenize_tests' + os.extsep + 'txt') test_roundtrip(f) testdir = os.path.dirname(f) or os.curdir testfiles = glob.glob(testdir + os.sep + 'test*.py') if not is_resource_enabled('compiler'): testfiles = random.sample(testfiles, 10) for f in testfiles: test_roundtrip(f) # Test detecton of IndentationError. sampleBadText = """\ def foo(): bar baz """ try: for tok in generate_tokens(StringIO(sampleBadText).readline): pass except IndentationError: pass else: raise TestFailed("Did not detect IndentationError:") # Run the doctests in this module. from test import test_tokenize # i.e., this module from test.test_support import run_doctest run_doctest(test_tokenize) if verbose: print 'finished'
def run_accessibility_script(self, script, error=AttributeError): fn = test_support.findfile(script) self.assertRaises(error, execfile, fn) self.assertEquals( subprocess.call([ sys.executable, "-J-Dpython.cachedir.skip=true", "-J-Dpython.security.respectJavaAccessibility=false", fn ]), 0)
def test_html_diff(self): # Check SF patch 914575 for generating HTML differences f1a = ((patch914575_from1 + '123\n' * 10) * 3) t1a = (patch914575_to1 + '123\n' * 10) * 3 f1b = '456\n' * 10 + f1a t1b = '456\n' * 10 + t1a f1a = f1a.splitlines() t1a = t1a.splitlines() f1b = f1b.splitlines() t1b = t1b.splitlines() f2 = patch914575_from2.splitlines() t2 = patch914575_to2.splitlines() f3 = patch914575_from3 t3 = patch914575_to3 i = difflib.HtmlDiff() j = difflib.HtmlDiff(tabsize=2) k = difflib.HtmlDiff(wrapcolumn=14) full = i.make_file(f1a, t1a, 'from', 'to', context=False, numlines=5) tables = '\n'.join([ '<h2>Context (first diff within numlines=5(default))</h2>', i.make_table(f1a, t1a, 'from', 'to', context=True), '<h2>Context (first diff after numlines=5(default))</h2>', i.make_table(f1b, t1b, 'from', 'to', context=True), '<h2>Context (numlines=6)</h2>', i.make_table(f1a, t1a, 'from', 'to', context=True, numlines=6), '<h2>Context (numlines=0)</h2>', i.make_table(f1a, t1a, 'from', 'to', context=True, numlines=0), '<h2>Same Context</h2>', i.make_table(f1a, f1a, 'from', 'to', context=True), '<h2>Same Full</h2>', i.make_table(f1a, f1a, 'from', 'to', context=False), '<h2>Empty Context</h2>', i.make_table([], [], 'from', 'to', context=True), '<h2>Empty Full</h2>', i.make_table([], [], 'from', 'to', context=False), '<h2>tabsize=2</h2>', j.make_table(f2, t2), '<h2>tabsize=default</h2>', i.make_table(f2, t2), '<h2>Context (wrapcolumn=14,numlines=0)</h2>', k.make_table(f3.splitlines(), t3.splitlines(), context=True, numlines=0), '<h2>wrapcolumn=14,splitlines()</h2>', k.make_table(f3.splitlines(), t3.splitlines()), '<h2>wrapcolumn=14,splitlines(True)</h2>', k.make_table(f3.splitlines(True), t3.splitlines(True)), ]) actual = full.replace('</body>', '\n%s\n</body>' % tables) # temporarily uncomment next three lines to baseline this test #f = open('test_difflib_expect.html','w') #f.write(actual) #f.close() expect = open(findfile('test_difflib_expect.html')).read() self.assertEqual(actual, expect)
def test_expat_inpsource_filename(): parser = make_parser() result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) parser.parse(findfile("test.xml")) return result.getvalue() == xml_test_out
def test_expat_file(): parser = create_parser() result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) parser.parse(open(findfile("test.xml"))) return result.getvalue() == xml_test_out
def test_html_diff(self): # Check SF patch 914575 for generating HTML differences f1a = ((patch914575_from1 + '123\n'*10)*3) t1a = (patch914575_to1 + '123\n'*10)*3 f1b = '456\n'*10 + f1a t1b = '456\n'*10 + t1a f1a = f1a.splitlines() t1a = t1a.splitlines() f1b = f1b.splitlines() t1b = t1b.splitlines() f2 = patch914575_from2.splitlines() t2 = patch914575_to2.splitlines() f3 = patch914575_from3 t3 = patch914575_to3 i = difflib.HtmlDiff() j = difflib.HtmlDiff(tabsize=2) k = difflib.HtmlDiff(wrapcolumn=14) full = i.make_file(f1a,t1a,'from','to',context=False,numlines=5) tables = '\n'.join( [ '<h2>Context (first diff within numlines=5(default))</h2>', i.make_table(f1a,t1a,'from','to',context=True), '<h2>Context (first diff after numlines=5(default))</h2>', i.make_table(f1b,t1b,'from','to',context=True), '<h2>Context (numlines=6)</h2>', i.make_table(f1a,t1a,'from','to',context=True,numlines=6), '<h2>Context (numlines=0)</h2>', i.make_table(f1a,t1a,'from','to',context=True,numlines=0), '<h2>Same Context</h2>', i.make_table(f1a,f1a,'from','to',context=True), '<h2>Same Full</h2>', i.make_table(f1a,f1a,'from','to',context=False), '<h2>Empty Context</h2>', i.make_table([],[],'from','to',context=True), '<h2>Empty Full</h2>', i.make_table([],[],'from','to',context=False), '<h2>tabsize=2</h2>', j.make_table(f2,t2), '<h2>tabsize=default</h2>', i.make_table(f2,t2), '<h2>Context (wrapcolumn=14,numlines=0)</h2>', k.make_table(f3.splitlines(),t3.splitlines(),context=True,numlines=0), '<h2>wrapcolumn=14,splitlines()</h2>', k.make_table(f3.splitlines(),t3.splitlines()), '<h2>wrapcolumn=14,splitlines(True)</h2>', k.make_table(f3.splitlines(True),t3.splitlines(True)), ]) actual = full.replace('</body>','\n%s\n</body>' % tables) # temporarily uncomment next three lines to baseline this test #f = open('test_difflib_expect.html','w') #f.write(actual) #f.close() expect = open(findfile('test_difflib_expect.html')).read() self.assertEqual(actual,expect)
def test_expat_inpsource_filename(self): parser = create_parser() result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) parser.parse(findfile("test" + os.extsep + "xml")) self.assertEquals(result.getvalue(), xml_test_out)
def test_html_diff(self): # Check SF patch 914575 for generating HTML differences f1a = (patch914575_from1 + "123\n" * 10) * 3 t1a = (patch914575_to1 + "123\n" * 10) * 3 f1b = "456\n" * 10 + f1a t1b = "456\n" * 10 + t1a f1a = f1a.splitlines() t1a = t1a.splitlines() f1b = f1b.splitlines() t1b = t1b.splitlines() f2 = patch914575_from2.splitlines() t2 = patch914575_to2.splitlines() f3 = patch914575_from3 t3 = patch914575_to3 i = difflib.HtmlDiff() j = difflib.HtmlDiff(tabsize=2) k = difflib.HtmlDiff(wrapcolumn=14) full = i.make_file(f1a, t1a, "from", "to", context=False, numlines=5) tables = "\n".join( [ "<h2>Context (first diff within numlines=5(default))</h2>", i.make_table(f1a, t1a, "from", "to", context=True), "<h2>Context (first diff after numlines=5(default))</h2>", i.make_table(f1b, t1b, "from", "to", context=True), "<h2>Context (numlines=6)</h2>", i.make_table(f1a, t1a, "from", "to", context=True, numlines=6), "<h2>Context (numlines=0)</h2>", i.make_table(f1a, t1a, "from", "to", context=True, numlines=0), "<h2>Same Context</h2>", i.make_table(f1a, f1a, "from", "to", context=True), "<h2>Same Full</h2>", i.make_table(f1a, f1a, "from", "to", context=False), "<h2>Empty Context</h2>", i.make_table([], [], "from", "to", context=True), "<h2>Empty Full</h2>", i.make_table([], [], "from", "to", context=False), "<h2>tabsize=2</h2>", j.make_table(f2, t2), "<h2>tabsize=default</h2>", i.make_table(f2, t2), "<h2>Context (wrapcolumn=14,numlines=0)</h2>", k.make_table(f3.splitlines(), t3.splitlines(), context=True, numlines=0), "<h2>wrapcolumn=14,splitlines()</h2>", k.make_table(f3.splitlines(), t3.splitlines()), "<h2>wrapcolumn=14,splitlines(True)</h2>", k.make_table(f3.splitlines(True), t3.splitlines(True)), ] ) actual = full.replace("</body>", "\n%s\n</body>" % tables) # temporarily uncomment next two lines to baseline this test # with open('test_difflib_expect.html','w') as fp: # fp.write(actual) with open(findfile("test_difflib_expect.html")) as fp: self.assertEqual(actual, fp.read())
def test_socket_server(self): # run socketserver with a small amount of memory; verify it exits cleanly rc = subprocess.call([sys.executable, "-J-Xmx32m", test_support.findfile("socketserver_test.py")]) # stdout=PIPE) self.assertEquals(rc, 0)
def test_wait_when_sigchild_ignored(self): # NOTE: sigchild_ignore.py may not be an effective test on all OSes. sigchild_ignore = test_support.findfile("sigchild_ignore.py", subdir="subprocessdata") p = subprocess.Popen([sys.executable, sigchild_ignore], stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() self.assertEqual(0, p.returncode, "sigchild_ignore.py exited" " non-zero with this error:\n%s" % stderr)
def test_expat_inpsource_sysid(): parser = make_parser() result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) parser.parse(InputSource(findfile("test.xml"))) return result.getvalue() == xml_test_out
def test_expat_inpsource_filename(): parser = create_parser() result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) parser.parse(findfile("test"+os.extsep+"xml")) return result.getvalue() == xml_test_out
def test_print_sans_lib(self): """Encodes and decodes using utf-8 after in an environment without the standard library Checks that the builtin utf-8 codec is always available: http://bugs.jython.org/issue1458""" subprocess.call([sys.executable, "-J-Dpython.cachedir.skip=true", "-J-Dpython.security.respectJavaAccessibility=false", test_support.findfile('print_sans_lib.py')])
def test_expat_inpsource_sysid(self): parser = create_parser() result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) parser.parse(InputSource(findfile("test"+os.extsep+"xml"))) self.assertEquals(result.getvalue(), xml_test_out)
def test_expat_inpsource_sysid(): parser = create_parser() result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) parser.parse(InputSource(findfile("test" + os.extsep + "xml"))) return result.getvalue() == xml_test_out
def test_print_sans_lib(self): # Encode and decode using utf-8 in an environment without the standard # library, to check that a utf-8 codec is always available. See: # http://bugs.jython.org/issue1458 subprocess.call([ sys.executable, "-J-Dpython.cachedir.skip=true", "-S", # No site module: avoid codec registry initialised too soon test_support.findfile('print_sans_lib.py') ])
def shortname(self,path): # From later versions of Windows (post-Vista), not all files and # directories have short names # This is set at the filesystem level and seems intended to phase # out short (DOS) names # https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file # shortname.bat returns the short name if available, else the full name shortnameLoc = test_support.findfile('shortname.bat') output = subprocess.check_output(['cmd','/c',shortnameLoc,path]) return output.strip()
def shortname(self, path): # From later versions of Windows (post-Vista), not all files and # directories have short names # This is set at the filesystem level and seems intended to phase # out short (DOS) names # https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file # shortname.bat returns the short name if available, else the full name shortnameLoc = test_support.findfile('shortname.bat') output = subprocess.check_output(['cmd', '/c', shortnameLoc, path]) return output.strip()
def test_bug_1727780(self): # verify that version-2-pickles can be loaded # fine, whether they are created on 32-bit or 64-bit # platforms, and that version-3-pickles load fine. files = [("randv2_32.pck", 780), ("randv2_64.pck", 866), ("randv3.pck", 343)] for file, value in files: f = open(test_support.findfile(file), "rb") r = pickle.load(f) f.close() self.assertEqual(r.randrange(1000), value)
def test_proxies_without_classloader(self): # importing with proxy_dir set compiles RunnableImpl there import static_proxy # Use the existing environment with the proxy dir added on the classpath env = dict(os.environ) env["CLASSPATH"] = sys.javaproxy_dir script = test_support.findfile("import_as_java_class.py") self.assertEquals(subprocess.call([sys.executable, "-J-Dpython.cachedir.skip=true", script], env=env), 0)
def test_expat_inpsource_stream(): parser = create_parser() result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) inpsrc = InputSource() inpsrc.setByteStream(open(findfile("test" + os.extsep + "xml"))) parser.parse(inpsrc) return result.getvalue() == xml_test_out
def test_data(self): for filename, expected in TEST_FILES: filename = findfile(filename, subdir='imghdrdata') self.assertEqual(imghdr.what(filename), expected) ufilename = filename.decode(sys.getfilesystemencoding()) self.assertEqual(imghdr.what(ufilename), expected) with open(filename, 'rb') as stream: self.assertEqual(imghdr.what(stream), expected) with open(filename, 'rb') as stream: data = stream.read() self.assertEqual(imghdr.what(None, data), expected)
def test_close_opened_files_on_error(self): non_aifc_file = findfile('pluck-pcm8.wav', subdir='audiodata') class Aifc(aifc.Aifc_read): def __init__(self): pass a = Aifc() with self.assertRaises(aifc.Error): aifc.Aifc_read.__init__(a, non_aifc_file) self.assertTrue(a._file.closed)
def test_expat_inpsource_stream(): parser = make_parser() result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) inpsrc = InputSource() inpsrc.setByteStream(open(findfile("test.xml"))) parser.parse(inpsrc) return result.getvalue() == xml_test_out
def test_read_chunks(self): # SF bug #1541697, this caused sgml parser to hang # Just verify this code doesn't cause a hang. CHUNK = 1024 # increasing this to 8212 makes the problem go away f = open(test_support.findfile('sgml_input.html')) fp = sgmllib.SGMLParser() while 1: data = f.read(CHUNK) fp.feed(data) if len(data) != CHUNK: break
def test_bug_1727780(self): # verify that version-2-pickles can be loaded # fine, whether they are created on 32-bit or 64-bit # platforms, and that version-3-pickles load fine. files = [("randv2_32.pck", 780), ("randv2_64.pck", 866), ("randv3.pck", 343)] for file, value in files: f = open(test_support.findfile(file),"rb") r = pickle.load(f) f.close() self.assertEqual(r.randrange(1000), value)