コード例 #1
0
 def test_utf_8_chars(self):
     bslint.load_config_file(user_filepath=self.utf8_encoding_config_path,
                             default_filepath=TEST_CONFIG_FILE_PATH)
     file_path = self.non_ascii_chars_file_path
     result = commands.check_file_encoding(file_path)
     expected = None
     self.assertEqual(expected, result)
コード例 #2
0
 def setUpClass(cls):
     trailing_white_space_config_path = os.path.join(
         TESTS_CONFIG_PATH,
         'trailing_white_space/trailing-white-space-config.json')
     bslint.load_config_file(user_filepath=trailing_white_space_config_path,
                             default_filepath=TEST_CONFIG_FILE_PATH)
     cls.common = Common()
コード例 #3
0
 def test_brs_file_without_path_lexed(self):
     bslint.load_config_file(default_filepath=TEST_CONFIG_FILE_PATH)
     runner = bslint.bslint.runner()
     result = runner.files
     runner.join()
     expected = ["print.brs"]
     self.assertEqual(expected, result)
コード例 #4
0
 def test_load_config_file_check_read(self):
     expected = ""
     out = StringIO()
     bslint.load_config_file(out=out)
     result = out.getvalue()
     out.close()
     self.assertEqual(expected, result)
コード例 #5
0
 def test_no_todo_comment(self):
     no_todo_comment_config_path = os.path.join(COMMENTS_CONFIG_PATH, 'no-TODO-comment-config.json')
     bslint.load_config_file(user_filepath=no_todo_comment_config_path, default_filepath=TEST_CONFIG_FILE_PATH)
     file_name = self.valid_comment_single_quote_no_todo_file_path
     expected = [error.get_error_msg(err_const.NO_TODOS, [1]),
                 error.get_error_msg(err_const.NO_TODOS, [17])]
     self.common.lex_file(expected, file_name)
コード例 #6
0
 def test_exceed_max_line_length(self):
     bslint.load_config_file(
         user_filepath=self.small_max_line_length_config_path,
         default_filepath=TEST_CONFIG_FILE_PATH)
     file_name = self.short_line_length_file_path
     expected = [error.get_error_msg(err_const.LINE_LENGTH, [11, 1])]
     self.common.lex_file(expected, file_name)
コード例 #7
0
 def test_skip_line_command_inactive(self):
     inactive_skip_line_config_path = os.path.join(
         BSLINT_COMMAND_CONFIG_PATH, 'inactive-skip-line-config.json')
     bslint.load_config_file(user_filepath=inactive_skip_line_config_path)
     self.common.lex_warnings_match(
         [msg_handler.get_error_msg(err_const.TYPO_IN_CODE, [2])],
         "'BSLint_skip_line\nxgygu = 22\ny = 4")
コード例 #8
0
 def test_print(self):
     bslint.load_config_file(user_filepath=self.trace_free_config_path,
                             default_filepath=TEST_CONFIG_FILE_PATH)
     print_file_path = os.path.join(TRACE_TEST_FILES_PATH, 'print.brs')
     self.common.lex_file(
         [error.get_error_msg(err_const.TRACEABLE_CODE, [3])],
         print_file_path)
コード例 #9
0
 def test_comment_not_empty_lines(self):
     bslint.load_config_file(
         user_filepath=self.single_empty_lines_config_path,
         default_filepath=TEST_CONFIG_FILE_PATH)
     comment_not_empty_lines_file_path = os.path.join(
         EMPTY_LINES_TEST_FILES_PATH, 'comment-not-empty-lines.brs')
     file_name = comment_not_empty_lines_file_path
     self.common.lex_file([], file_name)
コード例 #10
0
 def test_us_dictionary_passing(self):
     us_spellcheck_config_path = os.path.join(
         TESTS_CONFIG_PATH, 'spell_check/us-spellcheck-config.json')
     bslint.load_config_file(user_filepath=us_spellcheck_config_path,
                             default_filepath=TEST_CONFIG_FILE_PATH)
     commands.change_dict_lang(
         bslint.config_loader.CONFIG["spell_check"]["params"]["dictionary"])
     self.common.spell_check(None, "specialized")
コード例 #11
0
 def test_file_reader_no_encoding_check(self):
     bslint.load_config_file(default_filepath=TEST_CONFIG_FILE_PATH)
     file_path = self.ascii_chars_file_path
     fo = open(file_path, "r+")
     str_to_lex = fo.read()
     result = InterfaceHandler.file_reader(file_path)
     expected = {"invalid_encoding": None, "file_content": str_to_lex}
     self.assertEqual(expected, result)
コード例 #12
0
 def test_empty_lines_in_middle_custom_config(self):
     bslint.load_config_file(
         user_filepath=self.double_empty_lines_config_path,
         default_filepath=TEST_CONFIG_FILE_PATH)
     empty_lines_in_middle_file_path = os.path.join(
         EMPTY_LINES_TEST_FILES_PATH, 'empty-lines-in-middle.brs')
     file_name = empty_lines_in_middle_file_path
     self.common.lex_file([], file_name)
コード例 #13
0
 def test_equal_max_line_length(self):
     bslint.load_config_file(
         user_filepath=self.small_max_line_length_config_path,
         default_filepath=TEST_CONFIG_FILE_PATH)
     equal_max_line_length_file_path = os.path.join(
         STYLING_TEST_FILES_PATH, 'equal-max-line-length.txt')
     file_name = equal_max_line_length_file_path
     self.common.lex_file([], file_name)
コード例 #14
0
 def test_one_consecutive_empty_line(self):
     bslint.load_config_file(
         user_filepath=self.single_empty_lines_config_path,
         default_filepath=TEST_CONFIG_FILE_PATH)
     one_consecutive_empty_line_file_path = os.path.join(
         EMPTY_LINES_TEST_FILES_PATH, 'one-consecutive-empty-line.brs')
     file_name = one_consecutive_empty_line_file_path
     self.common.lex_file([], file_name)
コード例 #15
0
 def test_default_config_overwritten(self):
     bslint.load_config_file(default_filepath=TEST_CONFIG_FILE_PATH)
     general_ignore_test_files_path = os.path.join(
         TESTS_RESOURCES_PATH, 'general_ignore_test_files')
     result = bslint.bslint.runner(general_ignore_test_files_path)
     self.assertFalse(result.config["check_trace_free"]["active"])
     self.assertEqual(["sub_directory1_test_files"],
                      result.config["ignore"])
コード例 #16
0
 def test_read_json_bad_file_name(self):
     out = StringIO()
     config_file = os.path.join(CONFIG_PATH, 'fig.json')
     bslint.load_config_file(config_file, out=out)
     result = out.getvalue()
     out.close()
     expected = msg_handler.get_print_msg(print_const.NO_BSLINTRC)
     self.assertEqual(expected, result)
コード例 #17
0
 def test_incorrect_path(self):
     out = StringIO()
     brs_file_path = "falsepath/file.brs"
     bslint.load_config_file(default_filepath=TEST_CONFIG_FILE_PATH,
                             out=out)
     result = bslint.bslint.runner(to_lex=brs_file_path,
                                   out=out).printed_output
     self.assertEqual(
         msg_handler.get_print_msg(print_const.PATH_DOESNT_EXIST), result)
コード例 #18
0
 def test_valid_declaration_with_extra_spaces_in_params(self):
     active_method_extra_spacing_declaration_config_path = os.path.join(
         TESTS_CONFIG_PATH,
         'check_method_declaration/active_method_extra_spacing_declaration.json'
     )
     bslint.load_config_file(
         user_filepath=active_method_extra_spacing_declaration_config_path,
         default_filepath=TEST_CONFIG_FILE_PATH)
     self.common.method_dec_spacing(None, "function  declaration(a,  b)")
コード例 #19
0
 def test_many_spaces_around_operator_with_config(self):
     three_spaces_around_operators_path = \
         os.path.join(TESTS_CONFIG_PATH, 'spaces_around_operators/3-spaces-around-operators-config.json')
     bslint.load_config_file(
         user_filepath=three_spaces_around_operators_path)
     expected = [
         error.get_error_msg(err_const.NO_SPACE_AROUND_OPERATORS, [3, 1])
     ]
     self.common.lex_string(expected, 'this   =        "words"')
コード例 #20
0
 def test_single_indentation(self):
     bslint.load_config_file(user_filepath=self.indentation_config_path,
                             default_filepath=TEST_CONFIG_FILE_PATH)
     expected = None
     current_indentation_level = 1
     characters = "    var i = 3"
     indentation_level = 0
     result = commands.check_indentation(current_indentation_level,
                                         characters, indentation_level)
     self.assertEqual(expected, result[0])
コード例 #21
0
 def test_advanced_indentation_success(self):
     bslint.load_config_file(user_filepath=self.indentation_config_path,
                             default_filepath=TEST_CONFIG_FILE_PATH)
     advanced_indentation_file_path = os.path.join(
         STYLING_TEST_FILES_PATH, 'advanced-indentation.txt')
     file_name = advanced_indentation_file_path
     file = open(file_name, "r+").read()
     expected = []
     result = Lexer().lex(file)
     self.assertEqual(expected, result[const.WARNINGS])
コード例 #22
0
 def test_skip_file_command_skip_start_inactive(self):
     inactive_skip_file_config_path = os.path.join(
         BSLINT_COMMAND_CONFIG_PATH, 'inactive-skip-file-config.json')
     bslint.load_config_file(user_filepath=inactive_skip_file_config_path,
                             default_filepath=TEST_CONFIG_FILE_PATH)
     self.common.lex_warnings_match([
         msg_handler.get_error_msg(err_const.TYPO_IN_CODE, [2]),
         msg_handler.get_error_msg(err_const.NO_SPACE_AROUND_OPERATORS,
                                   [1, 2])
     ], "'BSLint_skip_file\nxgygu =22\ny = 4")
コード例 #23
0
 def test_invalid_declaration_with_extra_spaces_in_params(self):
     bslint.load_config_file(
         user_filepath=self.active_method_spacing_declaration_config_path,
         default_filepath=TEST_CONFIG_FILE_PATH)
     expected = {
         'error_key': 'METHOD_DECLARATION_SPACING',
         'error_params': []
     }
     self.common.method_dec_spacing(expected,
                                    "function declaration(a,   b, c,  d)")
コード例 #24
0
 def test_todo_no_comment(self):
     valid_comment_single_quote_no_todo_config_path = os.path.join(COMMENTS_CONFIG_PATH,
                                                                   'valid-comment-single-quote-no-TODO.json')
     bslint.load_config_file(user_filepath=valid_comment_single_quote_no_todo_config_path,
                             default_filepath=TEST_CONFIG_FILE_PATH)
     file_name = self.valid_comment_single_quote_no_todo_file_path
     expected = [error.get_error_msg(err_const.NON_CONVENTIONAL_TODO_AND_NO_COMMENTS, [11]),
                 error.get_error_msg(err_const.NON_CONVENTIONAL_TODO_AND_NO_COMMENTS, [12]),
                 error.get_error_msg(err_const.NON_CONVENTIONAL_TODO_AND_NO_COMMENTS, [17])]
     self.common.lex_file(expected, file_name)
コード例 #25
0
 def test_multiple_tokens_and_empty_lines(self):
     bslint.load_config_file(
         user_filepath=self.single_empty_lines_config_path,
         default_filepath=TEST_CONFIG_FILE_PATH)
     multiple_tokens_and_empty_lines_file_path = os.path.join(
         EMPTY_LINES_TEST_FILES_PATH, 'multiple-tokens-and-empty-lines.brs')
     file_name = multiple_tokens_and_empty_lines_file_path
     expected = [
         error.get_error_msg(err_const.CONSECUTIVE_EMPTY_LINES, [1, 3])
     ]
     self.common.lex_file(expected, file_name)
コード例 #26
0
 def test_empty_lines_in_middle(self):
     bslint.load_config_file(
         user_filepath=self.single_empty_lines_config_path,
         default_filepath=TEST_CONFIG_FILE_PATH)
     empty_lines_in_middle_file_path = os.path.join(
         EMPTY_LINES_TEST_FILES_PATH, 'empty-lines-in-middle.brs')
     file_name = empty_lines_in_middle_file_path
     expected = [
         error.get_error_msg(err_const.CONSECUTIVE_EMPTY_LINES, [1, 4])
     ]
     self.common.lex_file(expected, file_name)
コード例 #27
0
 def test_us_dictionary_failing(self):
     us_spellcheck_config_path = os.path.join(
         TESTS_CONFIG_PATH, 'spell_check/us-spellcheck-config.json')
     bslint.load_config_file(user_filepath=us_spellcheck_config_path,
                             default_filepath=TEST_CONFIG_FILE_PATH)
     commands.change_dict_lang(
         bslint.config_loader.CONFIG["spell_check"]["params"]["dictionary"])
     self.common.spell_check(
         {
             "error_key": err_const.TYPO_IN_CODE,
             "error_params": []
         }, "specialised")
コード例 #28
0
 def test_only_empty_lines_custom_config(self):
     bslint.load_config_file(
         user_filepath=self.double_empty_lines_config_path,
         default_filepath=TEST_CONFIG_FILE_PATH)
     only_empty_lines_file_path = os.path.join(EMPTY_LINES_TEST_FILES_PATH,
                                               'only-empty-lines.brs')
     file_name = only_empty_lines_file_path
     expected = [
         error.get_error_msg(err_const.CONSECUTIVE_EMPTY_LINES, [2, 3]),
         error.get_error_msg(err_const.CONSECUTIVE_EMPTY_LINES, [2, 4])
     ]
     self.common.lex_file(expected, file_name)
コード例 #29
0
 def test_multi_line_errors(self):
     bslint.load_config_file(
         user_filepath=self.small_max_line_length_config_path,
         default_filepath=TEST_CONFIG_FILE_PATH)
     multi_line_file_path = os.path.join(STYLING_TEST_FILES_PATH,
                                         'multiline-assignment.txt')
     file_name = multi_line_file_path
     expected = [
         error.get_error_msg(err_const.LINE_LENGTH, [11, 1]),
         error.get_error_msg(err_const.LINE_LENGTH, [11, 2])
     ]
     self.common.lex_file(expected, file_name)
コード例 #30
0
 def test_indent_with_only_tabs_with_error(self):
     tab_only_indentation_config_path = os.path.join(
         TESTS_CONFIG_PATH, 'indentation/tab-only-indentation.json')
     bslint.load_config_file(user_filepath=tab_only_indentation_config_path,
                             default_filepath=TEST_CONFIG_FILE_PATH)
     indent_with_tabs_only_file_path = os.path.join(
         STYLING_TEST_FILES_PATH, 'indent-with-tabs-only.txt')
     file_name = indent_with_tabs_only_file_path
     file = open(file_name, "r+").read()
     expected = [error.get_error_msg(err_const.TAB_AND_SPACES, [10])]
     result = Lexer().lex(file)
     self.assertEqual(expected, result[const.WARNINGS])