GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — pythonparser/pythonparser/test/test_algorithm.py at master · m-labs/pythonparser
This repository was archived by the owner on Jan 3, 2026. It is now read-only.
Expand file tree/ Copy pathtest_algorithm.pyMore file actions 49 lines (39 loc) · 1.92 KB / Copy pathtest_algorithm.pyFile metadata and controls49 lines (39 loc) · 1.92 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 from __future__ import absolute_import, division, print_function, unicode_literals from .. import parse, algorithm import unittest class AlgorithmTestCase(unittest.TestCase): def test_visitor(self): class FooVisitor(algorithm.Visitor): def __init__(self): self.num_count = self.other_count = 0 def visit_Num(self, node): self.num_count += 1 algorithm.Visitor.generic_visit(self, node) def generic_visit(self, node): self.other_count += 1 algorithm.Visitor.generic_visit(self, node) visitor = FooVisitor() visitor.visit(parse("[1,2,x,y]\n")) self.assertEqual(2, visitor.num_count) self.assertEqual(5, visitor.other_count) def test_compare(self): self.assertFalse(algorithm.compare(parse("1 + 2\n"), parse("1 + 3\n"))) self.assertTrue( algorithm.compare(parse("1 + 2\n"), parse("1 + 2\n"))) self.assertTrue( algorithm.compare(parse("1 + 2\n"), parse("1 + 2\n"))) self.assertFalse(algorithm.compare(parse("1 + 2\n"), parse("1 + 2\n"), compare_locs=True)) def test_transform(self): class FooTransformer(algorithm.Transformer): def visit_Num(self, node): if node.n == 42: return None return node transformer = FooTransformer() self.assertTrue(algorithm.compare(parse("return 10\n"), transformer.visit(parse("return 10\n")))) self.assertTrue(algorithm.compare(parse("return\n"), transformer.visit(parse("return 42\n")))) self.assertTrue(algorithm.compare(parse("[1,2,3]\n"), transformer.visit(parse("[1,2,3]\n")))) self.assertTrue(algorithm.compare(parse("[1,3]\n"), transformer.visit(parse("[1,42,3]\n")))) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |