예제 #1
0
    def __init__(self, filename, package=None):
        super(SourceFile, self).__init__(filename)
        Coverable.__init__(self)
        FileTokenizer.__init__(self)
        self.package = package

        # parse results
        self.parsed = False
        self.imports = []
        self.globals = []
        self.classes = []
        self.functions = []

        # loading and parsing
        self.load_content()
예제 #2
0
    def __init__(self, filename, package=None):
        super(SourceFile, self).__init__(filename)
        Coverable.__init__(self)
        FileTokenizer.__init__(self)
        self.package = package

        # parse results
        self.parsed = False
        self.imports = []
        self.globals = []
        self.classes = []
        self.functions = []

        # loading and parsing
        self.load_content()
예제 #3
0
 def test_parse(self):
     tz = FileTokenizer(content_file=self.SAMPLE_STRING_1)
     self.assertTrue(tz.has_content())
     self.assertEqual(tz.L, 25)
     self.assertEqual(tz.token, None)
     self.assertEqual(tz.token_type, None)
     self.assertTrue(tz.can_read())
     self.assertEqual(tz.read_ahead(2), 'ab')
     self.assertEqual(tz.read(1), 'a')
     self.assertEqual(tz.find_ahead('\n'), 3)
     self.assertEqual(tz.find_ahead('ab'), 4)
     self.assertEqual(tz.read(to=3), 'bc')
     tz.skip_spaces()
     self.assertEqual(tz.next_char(), 'a')
     self.assertEqual(tz.read_ahead(3), 'bc1')
     self.assertEqual(tz.next_char(skip=2), '1')
     self.assertEqual(tz.read_ahead(2), '\n\n')
     tz.skip_spaces()
     self.assertEqual(tz.read_ahead(1), '2')
     self.assertEqual(tz.read(cond=lambda ch: ch != '\n'), '2')
     self.assertEqual(tz.read_ahead(1), '\n')
     tz.skip_spaces()
     self.assertEqual(tz.read(find='-i'), 'g-h')
     self.assertEqual(tz.read(find='.', beyond=1), '-i-j-k-lm.')
     self.assertEqual(tz.next_char(), None)
     self.assertEqual(tz.next_char(skip=1), None)
     self.assertFalse(tz.can_read())
     self.assertTrue(tz.has_content())
예제 #4
0
 def test_argument_checking(self):
     tz = FileTokenizer(content_file=self.SAMPLE_STRING_1)
     self.assertRaises(ValueError, tz.next_char, skip=-2)
예제 #5
0
 def test_parse(self):
     tz = FileTokenizer(content_file=self.SAMPLE_STRING_1)
     self.assertTrue(tz.has_content())
     self.assertEqual(tz.L, 25)
     self.assertEqual(tz.token, None)
     self.assertEqual(tz.token_type, None)
     self.assertTrue(tz.can_read())
     self.assertEqual(tz.read_ahead(2), "ab")
     self.assertEqual(tz.read(1), "a")
     self.assertEqual(tz.find_ahead("\n"), 3)
     self.assertEqual(tz.find_ahead("ab"), 4)
     self.assertEqual(tz.read(to=3), "bc")
     tz.skip_spaces()
     self.assertEqual(tz.next_char(), "a")
     self.assertEqual(tz.read_ahead(3), "bc1")
     self.assertEqual(tz.next_char(skip=2), "1")
     self.assertEqual(tz.read_ahead(2), "\n\n")
     tz.skip_spaces()
     self.assertEqual(tz.read_ahead(1), "2")
     self.assertEqual(tz.read(cond=lambda ch: ch != "\n"), "2")
     self.assertEqual(tz.read_ahead(1), "\n")
     tz.skip_spaces()
     self.assertEqual(tz.read(find="-i"), "g-h")
     self.assertEqual(tz.read(find=".", beyond=1), "-i-j-k-lm.")
     self.assertEqual(tz.next_char(), None)
     self.assertEqual(tz.next_char(skip=1), None)
     self.assertFalse(tz.can_read())
     self.assertTrue(tz.has_content())