我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用test.test_tokenize()。
def test_tokenize(self): import tokenize as tokenize_module encoding = object() encoding_used = None def mock_detect_encoding(readline): return encoding, ['first', 'second'] def mock__tokenize(readline, encoding): nonlocal encoding_used encoding_used = encoding out = [] while True: next_line = readline() if next_line: out.append(next_line) continue return out counter = 0 def mock_readline(): nonlocal counter counter += 1 if counter == 5: return b'' return counter orig_detect_encoding = tokenize_module.detect_encoding orig__tokenize = tokenize_module._tokenize tokenize_module.detect_encoding = mock_detect_encoding tokenize_module._tokenize = mock__tokenize try: results = tokenize(mock_readline) self.assertEqual(list(results), ['first', 'second', 1, 2, 3, 4]) finally: tokenize_module.detect_encoding = orig_detect_encoding tokenize_module._tokenize = orig__tokenize self.assertTrue(encoding_used, encoding)
def test_main(): from test import test_tokenize support.run_doctest(test_tokenize, True) support.run_unittest(TestTokenizerAdheresToPep0263) support.run_unittest(Test_Tokenize) support.run_unittest(TestDetectEncoding) support.run_unittest(TestTokenize)
def test_main(): from test import test_tokenize test_support.run_doctest(test_tokenize, True) test_support.run_unittest(UntokenizeTest)
def test_main(): from test import test_tokenize test_support.run_doctest(test_tokenize, True)
def test_main(): from test import test_tokenize support.run_doctest(test_tokenize, True) support.run_unittest(TestTokenizerAdheresToPep0263) support.run_unittest(Test_Tokenize) support.run_unittest(TestDetectEncoding) support.run_unittest(TestTokenize) support.run_unittest(UntokenizeTest)