-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added unittest for compiler/lexemes.py #34
base: master
Are you sure you want to change the base?
Conversation
]) | ||
|
||
class Test_parse_for_variable_hierarchies(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work @Boot-Error . Let's try to one-up this test case ;)
Essentially, we can read from a sample site_level_config_file.yaml which contains different use case scenarios for the from keyword.
global_variables:
- &spark_master_ip_address 188.184.104.25
- &spark_master_fqdn simple-lc01.cern.ch
- &spark_worker_ip_address 188.184.30.19
- &spark_worker_fqdn simple-lc02.cern.ch
- &spark_submit_ip_address 188.185.84.189
- &spark_submit_fqdn simple-lc03.cern.ch
- &spark_level_2_configurator sh
- &l2_configurator:
__from__: *spark_level_2_configurator
spark_master_runtime_variables:
- &master_runtime_var_host
__from__: *spark_master_fqdn
spark_worker_runtime_variables:
- &spark_worker_runtime_var_host
__from__: *spark_worker_fqdn
- &spark_worker_runtime_var_spark_master
__from__: *spark_master_fqdn
spark_submit_runtime_variables:
- &submit_runtime_var_host
__from__: *spark_submit_fqdn
preferred_tech_stack:
level_1_configuration: puppet
level_2_configuration:
__from__: *l2_configurator
container_orchestration: docker-swarm
container: docker
We can use PyYAML to parse this file into a python dict and pass it to the parse_variable_hierarchies function.
We can test the output the the parse_variable_hierarchies function to check if the variables that were assigned values using from get the correct values. Let me know if anything needs clarification.
You can incorporate this once you have drafted your proposal ;) Good Luck.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the config is loaded as a dict, then parse_variable_hierarchies function returns the same dictionary (first if condition).
So it is also important to load the same file using ruamel's yaml loader to test if the CommentSeq and CommentMap conditions are functioning too.
And I'm having trouble with loading the same config using ruamel's loader. It fails at __from__: *l2_configurator
. Here is the full stack trace:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/booterror/Development/Contributing/gsoc19/simple_grid_yaml_compiler/venv/lib/python2.7/site-packages/ruamel/yaml/main.py", line 325, in load
return constructor.get_single_data()
File "/home/booterror/Development/Contributing/gsoc19/simple_grid_yaml_compiler/venv/lib/python2.7/site-packages/ruamel/yaml/constructor.py", line 106, in get_single_data
node = self.composer.get_single_node()
File "/home/booterror/Development/Contributing/gsoc19/simple_grid_yaml_compiler/venv/lib/python2.7/site-packages/ruamel/yaml/composer.py", line 78, in get_single_node
document = self.compose_document()
File "/home/booterror/Development/Contributing/gsoc19/simple_grid_yaml_compiler/venv/lib/python2.7/site-packages/ruamel/yaml/composer.py", line 101, in compose_document
node = self.compose_node(None, None)
File "/home/booterror/Development/Contributing/gsoc19/simple_grid_yaml_compiler/venv/lib/python2.7/site-packages/ruamel/yaml/composer.py", line 138, in compose_node
node = self.compose_mapping_node(anchor)
File "/home/booterror/Development/Contributing/gsoc19/simple_grid_yaml_compiler/venv/lib/python2.7/site-packages/ruamel/yaml/composer.py", line 217, in compose_mapping_node
item_value = self.compose_node(node, item_key)
File "/home/booterror/Development/Contributing/gsoc19/simple_grid_yaml_compiler/venv/lib/python2.7/site-packages/ruamel/yaml/composer.py", line 138, in compose_node
node = self.compose_mapping_node(anchor)
File "/home/booterror/Development/Contributing/gsoc19/simple_grid_yaml_compiler/venv/lib/python2.7/site-packages/ruamel/yaml/composer.py", line 217, in compose_mapping_node
item_value = self.compose_node(node, item_key)
File "/home/booterror/Development/Contributing/gsoc19/simple_grid_yaml_compiler/venv/lib/python2.7/site-packages/ruamel/yaml/composer.py", line 138, in compose_node
node = self.compose_mapping_node(anchor)
File "/home/booterror/Development/Contributing/gsoc19/simple_grid_yaml_compiler/venv/lib/python2.7/site-packages/ruamel/yaml/composer.py", line 217, in compose_mapping_node
item_value = self.compose_node(node, item_key)
File "/home/booterror/Development/Contributing/gsoc19/simple_grid_yaml_compiler/venv/lib/python2.7/site-packages/ruamel/yaml/composer.py", line 116, in compose_node
None, None, 'found undefined alias %r' % utf8(alias), event.start_mark
ruamel.yaml.composer.ComposerError: found undefined alias 'l2_configurator'
in "<byte string>", line 29, column 15:
__from__: *l2_configurator
^ (line: 29)
Added unit tests for functions defined in
compiler/lexemes.py
based on #25For function
parse_for_variable_hierarchies
, the test considers 2 cases.CommentedSeq
with aCommentedMap
with__from__
key in it.CommentedMap
with__from__
key in it.CommentedMap
with aCommentedMap
with__from__
key in it.