Skip to content

Commit 769d3f7

Browse files
committed
skeleton of root_parser tests
1 parent 8163cfe commit 769d3f7

2 files changed

Lines changed: 98 additions & 7 deletions

File tree

‎paths_cli/parsing/root_parser.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,10 @@ def _register_parser_plugin(plugin):
104104
raise DUPLICATE_ERROR
105105
ALIASES[alias] = plugin.name
106106

107-
### old versions
108-
109-
def register_builder(parser_name, name, builder):
110-
parser = TYPE_MAPPING[parser_name]
111-
parser.register_builder(builder, name)
112-
113107
def parse(dct):
114108
objs = []
115-
for category, func in TYPE_MAPPING.items():
109+
for category in PARSE_ORDER:
110+
func = PARSERS[category]
116111
yaml_objs = dct.get(category, [])
117112
new = [func(obj) for obj in yaml_objs]
118113
objs.extend(new)
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import pytest
2+
from paths_cli.parsing.root_parser import *
3+
from paths_cli.parsing.root_parser import (
4+
_get_parser, _get_registration_names, _register_builder_plugin,
5+
_register_parser_plugin
6+
)
7+
from unittest.mock import Mock, patch
8+
9+
PARSER_LOC = "paths_cli.parsing.root_parser.PARSERS"
10+
11+
class TestParserProxy:
12+
def setup(self):
13+
pass
14+
15+
def test_proxy(self):
16+
# the _proxy should be the registered parser
17+
pytest.skip()
18+
19+
def test_proxy_nonexisting(self):
20+
# _proxy should error if the no parser is registered
21+
pytest.skip()
22+
23+
def test_named_objs(self):
24+
# the `.named_objs` attribute should work in the proxy
25+
pytest.skip()
26+
27+
def test_call(self):
28+
# the `__call__` method should work in the proxy
29+
# the `__call__` method should work in the proxy
30+
pytest.skip()
31+
32+
def test_parser_for_nonexisting():
33+
# if the nothing is ever registered with the parser, then parser_for
34+
# should error
35+
parsers = {}
36+
with patch.dict(PARSER_LOC, parsers):
37+
assert 'foo' not in parsers
38+
proxy = parser_for('foo')
39+
assert 'foo' not in parsers
40+
with pytest.raises(KeyError):
41+
proxy._proxy
42+
43+
def test_parser_for_existing():
44+
# if a parser already exists when parser_for is called, then parser_for
45+
# should get that as its proxy
46+
pytest.skip()
47+
48+
def test_parser_for_registered():
49+
# if a parser is registered after parser_for is called, then parser_for
50+
# should use that as its proxy
51+
pytest.skip()
52+
53+
def test_get_parser_existing():
54+
# if a parser has been registered, then _get_parser should return the
55+
# registered parser
56+
pytest.skip()
57+
58+
def test_get_parser_nonexisting():
59+
# if a parser has not been registered, then _get_parser should create
60+
# the parser
61+
pytest.skip()
62+
63+
def test_get_registration_names():
64+
# _get_registration_names should always provide the names in order
65+
# `canonical, alias1, alias2, ...` regardless of whether `canonical` is
66+
# also listed in the aliases
67+
pytest.skip()
68+
69+
def test_register_parser_plugin():
70+
# _register_parser_plugin should register parsers that don't exist
71+
pytest.skip()
72+
73+
def test_register_parser_plugin_duplicate():
74+
# if a parser of the same name exists either in canonical or aliases,
75+
# _register_parser_plugin should raise an error
76+
pytest.skip()
77+
78+
def test_register_builder_plugin():
79+
# _register_builder_plugin should register plugins that don't exist,
80+
# including registering the parser if needed
81+
pytest.skip()
82+
83+
def test_register_plugins_unit():
84+
# register_plugins should correctly sort builder and parser plugins, and
85+
# call the correct registration functions
86+
# TODO: patch _register_builder & _register_parser; this is unit, not
87+
# integration
88+
pytest.skip()
89+
90+
def test_register_plugins_integration():
91+
# register_plugins should correctly register plugins
92+
pytest.skip()
93+
94+
def test_parse():
95+
# parser should correctly parse a basic input dict
96+
pytest.skip()

0 commit comments

Comments
 (0)