本文整理汇总了Python中tests.TestUtilities.bear_test_module函数的典型用法代码示例。如果您正苦于以下问题:Python bear_test_module函数的具体用法?Python bear_test_module怎么用?Python bear_test_module使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bear_test_module函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_filtered_bears
def test_get_filtered_bears(self):
sys.argv = ['coala', '-I']
with bear_test_module():
local_bears, global_bears = get_filtered_bears(
None, self.log_printer)
self.assertEqual(len(local_bears['cli']), TEST_BEARS_COUNT)
self.assertEqual(
[str(bear) for bear in local_bears['cli']],
TEST_BEAR_NAME_REPRS)
with bear_test_module():
local_bears, global_bears = get_filtered_bears(
['Java'], self.log_printer)
local_bears['cli'] = _sort_bears(local_bears['cli'])
global_bears['cli'] = _sort_bears(global_bears['cli'])
self.assertEqual(len(local_bears['cli']), 3)
self.assertEqual(
str(local_bears['cli'][0]),
"<class 'AspectsGeneralTestBear.AspectsGeneralTestBear'>")
self.assertEqual(str(local_bears['cli'][1]),
"<class 'JavaTestBear.JavaTestBear'>")
self.assertEqual(str(local_bears['cli'][2]),
"<class 'LineCountTestBear.LineCountTestBear'>")
self.assertEqual(len(global_bears['cli']), 0)
示例2: test_filter_by_language_c
def test_filter_by_language_c(self):
with bear_test_module():
retval, stdout, stderr = execute_coala(
coala.main, 'coala', '-B', '--filter-by', 'language', 'c')
self.assertEqual(retval, 0)
# 1 bear plus 1 line holding the closing colour escape sequence.
self.assertEqual(len(stdout.strip().splitlines()), 2)
示例3: test_fail_acquire_settings
def test_fail_acquire_settings(self):
with bear_test_module():
retval, output = execute_coala(coala.main, 'coala',
'--non-interactive',
'-b', 'SpaceConsistencyTestBear',
'-c', os.devnull)
self.assertIn('During execution, we found that some', output)
示例4: test_filter_by_language_c
def test_filter_by_language_c(self):
with bear_test_module():
retval, stdout, stderr = execute_coala(
coala.main, 'coala', '-B', '--filter-by', 'language', 'c')
self.assertEqual(retval, 0)
self.assertEqual(len(stdout.strip().splitlines()),
C_BEARS_COUNT_OUTPUT)
示例5: test_version_conflict_in_collecting_bears
def test_version_conflict_in_collecting_bears(self, import_fn, _):
with bear_test_module():
import_fn.side_effect = VersionConflict("msg1", "msg2")
retval, output = execute_coala(coala.main, "coala", "-B")
self.assertEqual(retval, 13)
self.assertIn(("There is a conflict in the version of a " "dependency you have installed"), output)
self.assertIn("pip install msg2", output) # Check recommendation
示例6: test_show_language_bears
def test_show_language_bears(self):
with bear_test_module():
retval, output = execute_coala(
coala_json.main, 'coala-json', '-B', '-l', 'java')
self.assertEqual(retval, 0)
output = json.loads(output)
self.assertEqual(len(output["bears"]), 2)
示例7: test_dependency_resolving
def test_dependency_resolving(self):
sections = {"test": self.section}
self.section['bears'] = "DependentBear"
with simulate_console_inputs("True"), bear_test_module():
fill_settings(sections, acquire_settings, self.log_printer)
self.assertEqual(bool(self.section["use_spaces"]), True)
示例8: test_file_cache_proxy_integration
def test_file_cache_proxy_integration(self, debug=False):
with bear_test_module():
with prepare_file(['disk-copy\n'], None) as (_, filename):
memory_data = 'in-memory\n'
proxy = FileProxy(filename, None, memory_data)
proxymap = FileProxyMap([proxy])
self.cache.set_proxymap(proxymap)
results, exitcode, file_dicts = run_coala(
console_printer=ConsolePrinter(),
log_printer=LogPrinter(),
arg_list=(
'-c', os.devnull,
'-f', filename,
'-b', 'TestBear',
),
autoapply=False,
debug=debug,
cache=self.cache
)
self.assertEqual(exitcode, 0)
self.assertEqual(len(results), 1)
# run_coala() output's name is always lower case
self.assertEqual(file_dicts['cli'][filename.lower()],
(memory_data,))
示例9: test_show_bears_specified_in_args
def test_show_bears_specified_in_args(self):
with bear_test_module():
retval, stdout, stderr = execute_coala(
coala.main, 'coala', '-B', '--bears',
'JavaTestBear', '--no-color')
self.assertEqual(retval, 0)
self.assertEqual(stdout.strip(), 'JavaTestBear')
示例10: test_show_language_bears
def test_show_language_bears(self):
with bear_test_module():
retval, output = execute_coala(
coala.main, 'coala', '-B', '-l', 'java')
self.assertEqual(retval, 0)
# 2 bears plus 1 line holding the closing colour escape sequence
self.assertEqual(len(output.splitlines()), 3)
示例11: test_section_ordering
def test_section_ordering(self, debug=False):
with bear_test_module():
with prepare_file(['#include <a>'], None) as (lines, filename):
retval, stdout, stderr = execute_coala(
coala.main, 'coala', 'b', 'a',
'--non-interactive', '-S',
'a.bears=SpaceConsistencyTestBear',
'a.files={}'.format(filename),
'a.use_spaces=True',
'b.bears=SpaceConsistencyTestBear',
'b.files={}'.format(filename),
'b.use_spaces=True',
'-c', os.devnull,
debug=debug)
stdout_list = stdout.splitlines(True)
self.assertEqual('Executing section b...\n', stdout_list[0])
self.assertEqual('Executing section a...\n', stdout_list[1])
retval, stdout, stderr = execute_coala(
coala.main, 'coala', 'a', 'b',
'--non-interactive', '-S',
'a.bears=SpaceConsistencyTestBear',
'a.files={}'.format(filename),
'a.use_spaces=True',
'b.bears=SpaceConsistencyTestBear',
'b.files={}'.format(filename),
'b.use_spaces=True',
'-c', os.devnull,
debug=debug)
stdout_list = stdout.splitlines(True)
self.assertEqual('Executing section a...\n', stdout_list[0])
self.assertEqual('Executing section b...\n', stdout_list[1])
示例12: test_fill_settings_section_match_with_conflicts
def test_fill_settings_section_match_with_conflicts(self):
self.section = Section('test1')
self.section["files"] = "hello.py"
sections = {'test1': self.section}
self.section.append(Setting('bears', 'BearC'))
with simulate_console_inputs("False") as generator, \
bear_test_module(), retrieve_stdout() as sio:
with generate_files([".editorconfig", "hello.py"],
[editorconfig_4, "pass"],
self.project_dir):
extracted_info = collect_info(self.project_dir)
local_bears, global_bears = fill_settings(
sections, acquire_settings, self.log_printer,
fill_section_method=fill_section,
extracted_info=extracted_info)
self.assertEqual(len(local_bears['test1']), 1)
self.assertEqual(len(global_bears['test1']), 0)
prompt_msg = (
'coala-quickstart has detected multiple potential values '
'for the setting "use_spaces"')
self.assertIn(prompt_msg, sio.getvalue())
self.assertEqual(generator.last_input, 0)
self.assertEqual(bool(self.section['use_spaces']), False)
示例13: test_filter_bears_ci_mode
def test_filter_bears_ci_mode(self):
sys.argv.append('--ci')
with bear_test_module():
languages = []
res_1 = filter_relevant_bears(
languages, self.printer, self.arg_parser, {})
res_2 = []
with generate_files(context_filenames,
context_file_contents,
self.project_dir):
with simulate_console_inputs("Yes") as generator:
extracted_info = collect_info(self.project_dir)
res_2 = filter_relevant_bears(languages,
self.printer,
self.arg_parser,
extracted_info)
# Make sure there was no prompt
self.assertEqual(generator.last_input, -1)
# The NonOptionalSettingBear is not selected due to non-optional
# setting value in non-interactive mode.
additional_bears_by_lang = {
"All": []
}
for lang in res_1:
additional_bears = [bear.name for bear in res_2[lang]
if bear not in res_1[lang]]
for bear in additional_bears_by_lang[lang]:
self.assertIn(bear, additional_bears)
示例14: test_filter_relevant_bears_gruntfile_present
def test_filter_relevant_bears_gruntfile_present(self):
# Reset the IMPORTANT_BEARS_LIST
import coala_quickstart.generation.Bears as Bears
Bears.IMPORTANT_BEARS_LIST = {
"JavaScript": "DoesNotExistBear",
"Python": "DoesNotExistAsWellBear"
}
sys.argv.append('--no-filter-by-capabilities')
with bear_test_module():
languages = [('JavaScript', 70), ('Python', 20)]
res = {}
with generate_files(["Gruntfile.js"],
[gruntfile],
self.project_dir) as gen_files:
extracted_info = collect_info(self.project_dir)
res = filter_relevant_bears(languages,
self.printer,
self.arg_parser,
extracted_info)
expected_results = {
"JavaScript": set(["SomeLinterBear"]),
}
for lang, lang_bears in expected_results.items():
for bear in lang_bears:
res_bears = [b.name for b in res[lang]]
self.assertIn(bear, res_bears)
示例15: test_filter_relevant_bears_with_capabilities
def test_filter_relevant_bears_with_capabilities(self):
# Clear the IMPORTANT_BEARS_LIST
import coala_quickstart.generation.Bears as Bears
Bears.IMPORTANT_BEARS_LIST = {}
with bear_test_module():
languages = []
capability_to_select = 'Smell'
cap_number = (
sorted(ALL_CAPABILITIES).index(capability_to_select) + 1)
res = []
with simulate_console_inputs('1000', str(cap_number)) as generator:
res = filter_relevant_bears(languages,
self.printer,
self.arg_parser,
{})
# 1000 was not a valid option, so there will be two prompts
self.assertEqual(generator.last_input, 1)
expected_results = {
"All": set(["SmellCapabilityBear"])
}
for lang, lang_bears in expected_results.items():
for bear in lang_bears:
res_bears = [b.name for b in res[lang]]
self.assertIn(bear, res_bears)