I'm trying to package your module as rpm packag. So I'm using typical in such case build, install and test cycle used on building package from non-root account:
- "setup.py build"
- "setup.py install --root </install/prefix>"
- "pytest with PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>
May I ask for help because few units are failing:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-lark-parser-0.11.3-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-lark-parser-0.11.3-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.11, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
Using --randomly-seed=2126451817
rootdir: /home/tkloczko/rpmbuild/BUILD/lark-0.11.3
plugins: forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, expect-1.1.0, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, freezegun-0.4.2, aspectlib-1.5.2, toolbox-0.5, rerunfailures-9.1.1, requests-mock-1.9.3, cov-2.12.1, pyfakefs-4.5.0, flaky-3.7.0, benchmark-3.4.1, xdist-2.3.0, pylama-7.7.1, datadir-1.3.1, regressions-2.2.0, cases-3.6.3, xprocess-0.18.1, black-0.3.12, checkdocs-2.7.1, anyio-3.3.0, Faker-8.11.0, asyncio-0.15.1, trio-0.7.0, httpbin-1.0.0, subtests-0.5.0, isort-2.0.0, hypothesis-6.14.6, mock-3.6.1, profiling-1.7.0, randomly-3.8.0
collected 998 items
tests/test_tools.py .... [ 0%]
tests/test_logger.py ... [ 0%]
tests/test_reconstructor.py ....... [ 1%]
tests/test_trees.py .............. [ 2%]
tests/test_parser.py ...............s.....ss.s.s......ss.....ss..s..s.......s......s.s.s...s.....s...s.s......s...s.....s......s................s...s...s........... [ 17%]
..s...................s.........s.....s...................s...s..s...s........s...................s.........s....................................................... [ 33%]
...........s....s.......s........................s.................s.............s..s...................s....s.s...ss......................s...............s..s.s... [ 50%]
.........s..s...s....................s..................s..........s...s................s.........s..s..s.....s........s.....s.s.......s......s......s....s......... [ 66%]
...........s............s.....s....................s.s............................s.......s....ss..ss..s...........s.ss......s...............s.s........s.s.s...s.s. [ 82%]
....ss...............s.......s.........................s....s............s..........s.......................................... [ 95%]
tests/test_lexer.py . [ 95%]
tests/test_nearley/test_nearley.py ..FF...F [ 96%]
tests/test_cache.py .... [ 96%]
. . [ 97%]
tests/test_cache.py F. [ 97%]
tests/test_grammar.py .......F....... [ 98%]
tests/test_tree_forest_transformer.py ............ [100%]
================================================================================= FAILURES =================================================================================
_________________________________________________________________________ TestNearley.test_include _________________________________________________________________________
self = <tests.test_nearley.test_nearley.TestNearley testMethod=test_include>
def test_include(self):
fn = os.path.join(NEARLEY_PATH, 'test/grammars/folder-test.ne')
> with open(fn) as f:
E FileNotFoundError: [Errno 2] No such file or directory: '/home/tkloczko/rpmbuild/BUILD/lark-0.11.3/tests/test_nearley/nearley/test/grammars/folder-test.ne'
tests/test_nearley/test_nearley.py:48: FileNotFoundError
______________________________________________________________________ TestNearley.test_multi_include ______________________________________________________________________
self = <tests.test_nearley.test_nearley.TestNearley testMethod=test_multi_include>
def test_multi_include(self):
fn = os.path.join(NEARLEY_PATH, 'test/grammars/multi-include-test.ne')
> with open(fn) as f:
E FileNotFoundError: [Errno 2] No such file or directory: '/home/tkloczko/rpmbuild/BUILD/lark-0.11.3/tests/test_nearley/nearley/test/grammars/multi-include-test.ne'
tests/test_nearley/test_nearley.py:61: FileNotFoundError
___________________________________________________________________________ TestNearley.test_css ___________________________________________________________________________
self = <tests.test_nearley.test_nearley.TestNearley testMethod=test_css>
def test_css(self):
fn = os.path.join(NEARLEY_PATH, 'examples/csscolor.ne')
> with open(fn) as f:
E FileNotFoundError: [Errno 2] No such file or directory: '/home/tkloczko/rpmbuild/BUILD/lark-0.11.3/tests/test_nearley/nearley/examples/csscolor.ne'
tests/test_nearley/test_nearley.py:28: FileNotFoundError
__________________________________________________________________________ TestCache.test_imports __________________________________________________________________________
self = <tests.test_cache.TestCache testMethod=test_imports>
def test_imports(self):
g = """
%import .grammars.ab (startab, expr)
"""
> parser = Lark(g, parser='lalr', start='startab', cache=True)
tests/test_cache.py:131:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
lark/lark.py:299: in __init__
self.grammar, used_files = load_grammar(grammar, self.source_path, self.options.import_paths, self.options.keep_all_tokens)
lark/load_grammar.py:1229: in load_grammar
builder.load_grammar(grammar, source)
lark/load_grammar.py:1082: in load_grammar
self.do_import(dotted_path, base_path, aliases, mangle)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <lark.load_grammar.GrammarBuilder object at 0x7f9944b73640>, dotted_path = (Token('RULE', 'grammars'), Token('RULE', 'ab')), base_path = '/usr/bin'
aliases = {Token('RULE', 'expr'): Token('RULE', 'expr'), Token('RULE', 'startab'): Token('RULE', 'startab')}, base_mangle = None
def do_import(self, dotted_path, base_path, aliases, base_mangle=None):
assert dotted_path
mangle = _get_mangle('__'.join(dotted_path), aliases, base_mangle)
grammar_path = os.path.join(*dotted_path) + EXT
to_try = self.import_paths + ([base_path] if base_path is not None else []) + [stdlib_loader]
for source in to_try:
try:
if callable(source):
joined_path, text = source(base_path, grammar_path)
else:
joined_path = os.path.join(source, grammar_path)
with open(joined_path, encoding='utf8') as f:
text = f.read()
except IOError:
continue
else:
h = hashlib.md5(text.encode('utf8')).hexdigest()
if self.used_files.get(joined_path, h) != h:
raise RuntimeError("Grammar file was changed during importing")
self.used_files[joined_path] = h
gb = GrammarBuilder(self.global_keep_all_tokens, self.import_paths, self.used_files)
gb.load_grammar(text, joined_path, mangle)
gb._remove_unused(map(mangle, aliases))
for name in gb._definitions:
if name in self._definitions:
raise GrammarError("Cannot import '%s' from '%s': Symbol already defined." % (name, grammar_path))
self._definitions.update(**gb._definitions)
break
else:
# Search failed. Make Python throw a nice error.
> open(grammar_path, encoding='utf8')
E FileNotFoundError: [Errno 2] No such file or directory: 'grammars/ab.lark'
lark/load_grammar.py:1162: FileNotFoundError
______________________________________________________________________ TestGrammar.test_override_rule ______________________________________________________________________
self = <tests.test_grammar.TestGrammar testMethod=test_override_rule>
def test_override_rule(self):
# Overrides the 'sep' template in existing grammar to add an optional terminating delimiter
# Thus extending it beyond its original capacity
p = Lark("""
%import .test_templates_import (start, sep)
%override sep{item, delim}: item (delim item)* delim?
%ignore " "
""", source_path=__file__)
a = p.parse('[1, 2, 3]')
b = p.parse('[1, 2, 3, ]')
assert a == b
> self.assertRaises(GrammarError, Lark, """
%import .test_templates_import (start, sep)
%override sep{item}: item (delim item)* delim?
""")
tests/test_grammar.py:39:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
lark/lark.py:299: in __init__
self.grammar, used_files = load_grammar(grammar, self.source_path, self.options.import_paths, self.options.keep_all_tokens)
lark/load_grammar.py:1229: in load_grammar
builder.load_grammar(grammar, source)
lark/load_grammar.py:1082: in load_grammar
self.do_import(dotted_path, base_path, aliases, mangle)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def do_import(self, dotted_path, base_path, aliases, base_mangle=None):
assert dotted_path
mangle = _get_mangle('__'.join(dotted_path), aliases, base_mangle)
grammar_path = os.path.join(*dotted_path) + EXT
to_try = self.import_paths + ([base_path] if base_path is not None else []) + [stdlib_loader]
for source in to_try:
try:
if callable(source):
joined_path, text = source(base_path, grammar_path)
else:
joined_path = os.path.join(source, grammar_path)
with open(joined_path, encoding='utf8') as f:
text = f.read()
except IOError:
continue
else:
h = hashlib.md5(text.encode('utf8')).hexdigest()
if self.used_files.get(joined_path, h) != h:
raise RuntimeError("Grammar file was changed during importing")
self.used_files[joined_path] = h
gb = GrammarBuilder(self.global_keep_all_tokens, self.import_paths, self.used_files)
gb.load_grammar(text, joined_path, mangle)
gb._remove_unused(map(mangle, aliases))
for name in gb._definitions:
if name in self._definitions:
raise GrammarError("Cannot import '%s' from '%s': Symbol already defined." % (name, grammar_path))
self._definitions.update(**gb._definitions)
break
else:
# Search failed. Make Python throw a nice error.
> open(grammar_path, encoding='utf8')
E FileNotFoundError: [Errno 2] No such file or directory: 'test_templates_import.lark'
lark/load_grammar.py:1162: FileNotFoundError
============================================================================= warnings summary =============================================================================
tests/test_cache.py:110
/home/tkloczko/rpmbuild/BUILD/lark-0.11.3/tests/test_cache.py:110: DeprecationWarning: invalid escape sequence \d
g = """
tests/test_cache.py:48
/home/tkloczko/rpmbuild/BUILD/lark-0.11.3/tests/test_cache.py:48: PytestCollectionWarning: cannot collect test class 'TestT' because it has a __init__ constructor (from: tests/test_cache.py)
class TestT(Transformer):
tests/test_parser.py:166
/home/tkloczko/rpmbuild/BUILD/lark-0.11.3/tests/test_parser.py:166: DeprecationWarning: invalid escape sequence \d
g = """
tests/test_reconstructor.py:75
/home/tkloczko/rpmbuild/BUILD/lark-0.11.3/tests/test_reconstructor.py:75: DeprecationWarning: invalid escape sequence \s
g = """
tests/test_reconstructor.py:90
/home/tkloczko/rpmbuild/BUILD/lark-0.11.3/tests/test_reconstructor.py:90: DeprecationWarning: invalid escape sequence \s
g = """
tests/test_reconstructor.py:154
/home/tkloczko/rpmbuild/BUILD/lark-0.11.3/tests/test_reconstructor.py:154: DeprecationWarning: invalid escape sequence \s
g1 = """
tests/test_reconstructor.py:162
/home/tkloczko/rpmbuild/BUILD/lark-0.11.3/tests/test_reconstructor.py:162: DeprecationWarning: invalid escape sequence \s
g2 = """
-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================================================================= short test summary info ==========================================================================
SKIPPED [7] tests/test_parser.py:2005: Currently only Earley supports priority sum in rules
SKIPPED [2] tests/test_parser.py:2077: No empty rules
SKIPPED [7] tests/test_parser.py:2309: Serialize currently only works for LALR parsers without custom lexers (though it should be easy to extend)
SKIPPED [9] tests/test_parser.py:1045: cStringIO not available
SKIPPED [3] tests/test_parser.py:2355: match_examples() not supported for CYK/old custom lexer
SKIPPED [9] tests/test_parser.py:1249: Flattening list isn't implemented (and may never be)
SKIPPED [2] tests/test_parser.py:1961: Doesn't work for CYK
SKIPPED [2] tests/test_parser.py:2231: Empty rules
SKIPPED [2] tests/test_parser.py:2220: Empty rules
SKIPPED [2] tests/test_parser.py:1120: Takes forever
SKIPPED [9] tests/test_parser.py:1265: Flattening list isn't implemented (and may never be)
SKIPPED [6] tests/test_parser.py:1705: Only standard lexers care about token priority
SKIPPED [2] tests/test_parser.py:1512: No empty rules
SKIPPED [2] tests/test_parser.py:1194: No empty rules
SKIPPED [2] tests/test_parser.py:1650: No empty rules
SKIPPED [6] tests/test_parser.py:2435: interactive_parser error handling only works with LALR for now
SKIPPED [6] tests/test_parser.py:2398: interactive_parser is only implemented for LALR at the moment
SKIPPED [2] tests/test_parser.py:1451: No empty rules
SKIPPED [9] tests/test_parser.py:1281: Flattening list isn't implemented (and may never be)
SKIPPED [2] tests/test_parser.py:1213: No empty rules
SKIPPED [2] tests/test_parser.py:1233: No empty rules
SKIPPED [4] tests/test_parser.py:2194: Priority not handled correctly right now
SKIPPED [2] tests/test_parser.py:1915: %declare/postlex doesn't work with dynamic
SKIPPED [2] tests/test_parser.py:1938: %declare/postlex doesn't work with dynamic
SKIPPED [1] tests/test_parser.py:754: Only relevant for the dynamic_complete parser
SKIPPED [1] tests/test_parser.py:402: Only relevant for the dynamic_complete parser
FAILED tests/test_nearley/test_nearley.py::TestNearley::test_include - FileNotFoundError: [Errno 2] No such file or directory: '/home/tkloczko/rpmbuild/BUILD/lark-0.11.3...
FAILED tests/test_nearley/test_nearley.py::TestNearley::test_multi_include - FileNotFoundError: [Errno 2] No such file or directory: '/home/tkloczko/rpmbuild/BUILD/lark-...
FAILED tests/test_nearley/test_nearley.py::TestNearley::test_css - FileNotFoundError: [Errno 2] No such file or directory: '/home/tkloczko/rpmbuild/BUILD/lark-0.11.3/tes...
FAILED tests/test_cache.py::TestCache::test_imports - FileNotFoundError: [Errno 2] No such file or directory: 'grammars/ab.lark'
FAILED tests/test_grammar.py::TestGrammar::test_override_rule - FileNotFoundError: [Errno 2] No such file or directory: 'test_templates_import.lark'
========================================================= 5 failed, 889 passed, 103 skipped, 7 warnings in 44.97s ==========================================================
pytest-xprocess reminder::Be sure to terminate the started process by running 'pytest --xkill' if you have not explicitly done so in your fixture with 'xprocess.getinfo(<process_name>).terminate()'.