Skip to content

Commit

Permalink
yaml keys are now case sensitive again. fix #998
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed Dec 26, 2017
1 parent 6a9632e commit c156cd3
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 15 deletions.
3 changes: 3 additions & 0 deletions mpf/core/config_processor.py
Expand Up @@ -26,6 +26,9 @@ def load_config_file(filename, config_type: str, verify_version=True, halt_on_er
if not ConfigValidator.config_spec:
ConfigValidator.load_config_spec()

if not config:
return dict()

for k in config.keys():
try:
if config_type not in ConfigValidator.config_spec[k][
Expand Down
3 changes: 3 additions & 0 deletions mpf/core/data_manager.py
Expand Up @@ -73,6 +73,9 @@ def _load(self):
self.debug_log("Didn't find the %s file. No prob. We'll create "
"it when we save.", self.name)

if not self.data:
self.data = {}

def get_data(self, section=None):
"""Return the value of this DataManager's data.
Expand Down
2 changes: 1 addition & 1 deletion mpf/file_interfaces/yaml_interface.py
Expand Up @@ -275,7 +275,7 @@ def load(self, filename, verify_version=True, halt_on_error=True) -> dict:
@staticmethod
def process(data_string: Iterable[str]) -> dict:
"""Parse yaml from a string."""
return Util.keys_to_lower(yaml.load(data_string, Loader=MpfLoader))
return yaml.load(data_string, Loader=MpfLoader)

def save(self, filename: str, data: dict) -> None: # pragma: no cover
"""Save config to yaml file."""
Expand Down
Expand Up @@ -26,6 +26,3 @@ test_section:
case_sensitive_1: test
Case_sensitive_2: test
case_sensitive_3: Test

Test_section_1:
test: test
2 changes: 1 addition & 1 deletion mpf/tests/machine_files/p_roc/config/config.yaml
Expand Up @@ -4,7 +4,7 @@ hardware:
driverboards: pdb
platform: p_roc

P_ROC:
p_roc:
dmd_timing_cycles: 1, 2, 3, 4

switches:
Expand Down
4 changes: 2 additions & 2 deletions mpf/tests/machine_files/shows/config/test_shows.yaml
Expand Up @@ -171,8 +171,8 @@ show_player:
show_assoc_tokens:
speed: 1
show_tokens:
line1Num: tag1
line1Color: red
line1num: tag1
line1color: red
stop_show_assoc_tokens:
show_assoc_tokens:
action: stop
Expand Down
11 changes: 3 additions & 8 deletions mpf/tests/test_Config.py
Expand Up @@ -14,8 +14,6 @@ def setUp(self):

self.add_to_config_validator('test_section',
dict(__valid_in__='machine'))
self.add_to_config_validator('test_section_1',
dict(__valid_in__='machine'))

super().setUp()

Expand Down Expand Up @@ -49,19 +47,16 @@ def test_config_file(self):
self.assertEqual('+5', self.machine.config['test_section']['str_plus5'])
self.assertEqual('+0.5', self.machine.config['test_section']['str_plus0point5'])

# keys should be all lowercase
# keys should keep case
self.assertIn('case_sensitive_1', self.machine.config['test_section'])
self.assertIn('case_sensitive_2', self.machine.config['test_section'])
self.assertIn('Case_sensitive_2', self.machine.config['test_section'])
self.assertIn('case_sensitive_3', self.machine.config['test_section'])

# values should be case sensitive
self.assertEqual(self.machine.config['test_section']['case_sensitive_1'], 'test')
self.assertEqual(self.machine.config['test_section']['case_sensitive_2'], 'test')
self.assertEqual(self.machine.config['test_section']['Case_sensitive_2'], 'test')
self.assertEqual(self.machine.config['test_section']['case_sensitive_3'], 'Test')

# key should be lowercase even though it's uppercase in the config
self.assertIn('test_section_1', self.machine.config)

def test_config_validator(self):
validation_failure_info = (("key", "entry"), "subkey")
# test config spec syntax error
Expand Down

0 comments on commit c156cd3

Please sign in to comment.