Permalink
Browse files

SettingsFilling: Autofill "language" setting

As quickstart generates language-based sections, the
`language` setting value for all the bears can be
autofilled from the section name.

Closes #135
  • Loading branch information...
satwikkansal committed Aug 5, 2017
1 parent 485b28b commit 4802812fc16364b394889ad9df05f2b83a62d1e1
@@ -270,7 +270,13 @@ def acquire_settings(log_printer, settings_dict, section):
for setting_name, setting_info in sorted(
settings_dict.items(),
key=lambda x: (join_names(x[1]["bears"]), x[0])):
value = require_setting(setting_name, setting_info, section)
# As quickstart generates language-based sections, the value for
# `language` setting can be filled automatically.
if setting_name == "language":
value = section.name
else:
value = require_setting(setting_name, setting_info, section)
result.update({setting_name: value} if value is not None else {})
return result
@@ -225,6 +225,20 @@ def test_fill_section_boolean_setting(self):
self.assertEqual(bool(self.section['use_spaces']), False)
def test_language_setting_autofill(self):
self.section = Section('ruby')
sections = {'ruby': self.section}
self.section.append(Setting('bears', 'LanguageSettingBear'))
with simulate_console_inputs() as generator, bear_test_module():
local_bears, global_bears = fill_settings(
sections, acquire_settings, self.log_printer,
fill_section_method=fill_section,
extracted_info={})
self.assertEqual(generator.last_input, -1)
self.assertEqual(str(self.section['language']), 'ruby')
def test_dependency_resolving(self):
sections = {'test': self.section}
self.section['bears'] = 'DependentBear'
@@ -0,0 +1,9 @@
from coalib.bears.LocalBear import LocalBear
class LanguageSettingBear(LocalBear):
CAN_FIX = {}
LANGUAGES = {"All"}
def run(self, filename, file, language: str):
pass

0 comments on commit 4802812

Please sign in to comment.