def testConsolePolyfill(self): self.assertEquals( vinn.ExecuteJsString('console.log("hello", "world");'), 'hello world\n') self.assertEquals( vinn.ExecuteJsString('console.info("hello", "world");'), 'Info: hello world\n') self.assertEquals( vinn.ExecuteJsString('console.warn("hello", "world");'), 'Warning: hello world\n') self.assertEquals( vinn.ExecuteJsString('console.error("hello", "world");'), 'Error: hello world\n')
def testExecuteJsStringStdoutPiping(self): tmp_dir = tempfile.mkdtemp() try: temp_file_name = os.path.join(tmp_dir, 'out_file') with open(temp_file_name, 'w') as f: vinn.ExecuteJsString('print("Hello w0rld");\n', stdout=f) with open(temp_file_name, 'r') as f: self.assertEquals(f.read(), 'Hello w0rld\n') finally: shutil.rmtree(tmp_dir)
def GetGeneratedJs(self, html_text): tmp_dir = tempfile.mkdtemp() try: temp_file_name = os.path.join(tmp_dir, 'test.html') with open(temp_file_name, 'w') as f: f.write(html_text) return vinn.ExecuteJsString( 'write(generateJsFromHTML(read("%s")));' % temp_file_name) finally: shutil.rmtree(tmp_dir)
def testConsoleTimeEndOutput(self): output = vinn.ExecuteJsString( 'console.time("AA");console.timeEnd("AA")') m = re.search('\d+\.\d+', output) if not m: sys.stderr.write('\nExpected to find output of timer AA') self.fail() a_duration = float(m.group()) self.assertTrue(a_duration > 0.0) output = vinn.ExecuteJsString("""console.time("BB"); console.time("CC"); console.timeEnd("CC"); console.timeEnd("BB")""") m = re.findall('(\d+\.\d+)', output) if not m: sys.stderr.write('\nExpected to find output of timer\n') self.fail() c_duration = float(m[0]) b_duration = float(m[1]) self.assertTrue(b_duration > c_duration)
def testExecuteJsStringWithV8Args(self): vinn.ExecuteJsString('var x = 1;', v8_args=['--foo', '--bar=True']) v8_args = self.mock_popen.call_args[0][0] self.assertIn('--foo', v8_args) self.assertIn('--bar=True', v8_args)
def testConsoleTime(self): self.assertEquals(vinn.ExecuteJsString('console.time("AA")'), '')
def testDuplicateSourcePaths(self): output = vinn.ExecuteJsString( "HTMLImportsLoader.loadHTML('/load_simple_html.html');", source_paths=[self.test_data_dir] * 100) self.assertIn('load_simple_html.html is loaded', output)