def test_parser_parse(self): # Do not use a string to avoid issues due to string interning. name = object() self.assertEqual(sys.getrefcount(name), 2) f = io.BytesIO(b"") f.name = name self.assertEqual(sys.getrefcount(f.name), 3) builder = grammar.Builder() parser = _parser.Parser(builder) parser.parse(f) # The Parser object keeps a reference to the input file. self.assertEqual(sys.getrefcount(f), 3) # There are references to the file name from the Parser object # and from the the parsing results. In the case of an empty # input file from the options dictionary stored in the builder. self.assertEqual(sys.getrefcount(name), 5) builder.options = {} self.assertEqual(sys.getrefcount(name), 4) del parser # Once the Parser object is gone we should have just the local # reference to the file object and two references to name. self.assertEqual(sys.getrefcount(name), 3) self.assertEqual(sys.getrefcount(f), 2)
def test_parse_lineno(self): f = io.BytesIO(b"2020-07-30 open Assets:Test") builder = grammar.Builder() parser = _parser.Parser(builder) parser.parse(f, lineno=42) self.assertEqual(builder.entries[0].meta['lineno'], 42)