コード例 #1
0
 def test_all_lexed_correctly(self):
     out = StringIO()
     brs_file_path = os.path.join(LEXING_TEST_FILES_PATH,
                                  'basic-string-assignment.brs')
     result = bslint.bslint.runner(to_lex=brs_file_path,
                                   out=out).printed_output
     self.assertEqual(
         msg_handler.get_print_msg(print_const.NO_MANIFEST) +
         msg_handler.get_print_msg(print_const.NO_BSLINTRC) +
         msg_handler.get_print_msg(print_const.LINTING_COMPLETE) +
         msg_handler.get_print_msg(print_const.ALL_LINTED_CORRECTLY),
         result)
コード例 #2
0
 def print_summary(self):
     PROCESS_LOCK.acquire()
     for file_name in self.messages[const.ERRORS]:
         self.print_issues(file_name, const.ERRORS)
     self.out.write(msg_handler.get_print_msg(print_const.LINTING_COMPLETE))
     if self.is_lexed_correctly:
         self.out.write(
             msg_handler.get_print_msg(print_const.ALL_LINTED_CORRECTLY))
     else:
         self.out.write(
             msg_handler.get_print_msg(print_const.TOTAL_WARNINGS,
                                       [self.issues_total[const.WARNINGS]]))
         self.out.write(
             msg_handler.get_print_msg(print_const.TOTAL_ERRORS,
                                       [self.issues_total[const.ERRORS]]))
     PROCESS_LOCK.release()
コード例 #3
0
 def print_issues(self, file_name, issue_type):
     self.out.write(
         msg_handler.get_print_msg(print_const.FILE_NAME,
                                   ["file://" + file_name]))
     for message in self.messages[issue_type][file_name]:
         self.out.write(message)
     number_issues = len(self.messages[issue_type][file_name])
     self.issues_total[issue_type] += number_issues
コード例 #4
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)
コード例 #5
0
ファイル: config_loader.py プロジェクト: vasiuadriana/bslint
def load_config_file(user_filepath=None,
                     default_filepath=DEFAULT_CONFIG_FILE_PATH,
                     out=sys.stdout):
    default_json = get_default_config(default_filepath)
    try:
        user_json = get_user_config(user_filepath)
        default_json = overwrite_default_config(default_json, user_json)

    except FileNotFoundError:
        out.write(msg_handler.get_print_msg(print_const.NO_BSLINTRC))
    except ValueError:

        out.write(msg_handler.get_print_msg(print_const.CANNOT_PARSE_BSLINTRC))
        default_json = None
    finally:
        global CONFIG
        CONFIG = default_json
        return default_json
コード例 #6
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)
コード例 #7
0
 def test_key_in_bslintrc_not_in_default_config(self):
     out = StringIO()
     invalid_json_path = os.path.join(
         TESTS_RESOURCES_PATH,
         'general_test_files/invalid_key_in_bslintrc/.bslintrc')
     bslint.config_loader.load_config_file(invalid_json_path,
                                           DEFAULT_CONFIG_FILE_PATH, out)
     result = out.getvalue()
     out.close()
     self.assertEqual(
         msg_handler.get_print_msg(print_const.BSLINTRC_KEY_DOSNT_EXIST,
                                   ["check_1"]), result)
コード例 #8
0
 def test_invalid_bslintrc(self):
     out = StringIO()
     invalid_json_path = os.path.join(
         TESTS_RESOURCES_PATH,
         'general_test_files/invalid_bslintrc_test_files/.bslintrc')
     bslint.config_loader.load_config_file(invalid_json_path,
                                           DEFAULT_CONFIG_FILE_PATH, out)
     result = out.getvalue()
     out.close()
     self.assertEqual(
         msg_handler.get_print_msg(print_const.CANNOT_PARSE_BSLINTRC),
         result)
コード例 #9
0
 def test_warning_message_printed(self):
     out = StringIO()
     warning_file_path = os.path.join(
         TESTS_RESOURCES_PATH, 'error_handling_files/warning-file.brs')
     result = bslint.bslint.runner(to_lex=warning_file_path,
                                   out=out).printed_output
     self.assertEqual(
         msg_handler.get_print_msg(print_const.NO_MANIFEST) +
         msg_handler.get_print_msg(print_const.NO_BSLINTRC) +
         msg_handler.get_print_msg(print_const.FILE_NAME,
                                   ["file://" + warning_file_path]) +
         msg_handler.get_print_msg(
             const.WARNINGS,
             [msg_handler.get_error_msg(err_const.TAB_AND_SPACES, [1])]) +
         msg_handler.get_print_msg(
             const.WARNINGS,
             [msg_handler.get_error_msg(err_const.TAB_AND_SPACES, [2])]) +
         msg_handler.get_print_msg(print_const.WARNINGS_IN_FILE, [2]) +
         msg_handler.get_print_msg(print_const.LINTING_COMPLETE) +
         msg_handler.get_print_msg(print_const.TOTAL_WARNINGS, [2]) +
         msg_handler.get_print_msg(print_const.TOTAL_ERRORS, [0]), result)
コード例 #10
0
    def run(self):
        self._get_cli_arguments()
        if self.args.path and not os.path.exists(self.args.path):
            self.is_lexed_correctly = False
            self.out.write(
                msg_handler.get_print_msg(print_const.PATH_DOESNT_EXIST))
            self.send_to_pipe()
            return

        self.manifest_path = self._get_manifest_path(self.args.path)
        self.bslintrc = self._parse_bslintrc(self.manifest_path, self.out)

        self.start_spinner()
        self.lint()
        self.print_summary()
        self.send_to_pipe()
コード例 #11
0
 def _get_cli_arguments(self):
     parser = argparse.ArgumentParser(
         description=msg_handler.get_print_msg(print_const.DESCRIPTION))
     parser.add_argument("--path", "-p", help="Specify directory or file")
     parser.add_argument(
         '--lex',
         "-l",
         help="Runs only the lexer, without parsing the code",
         action='store_true',
         default=False)
     parser.add_argument('--version',
                         "-v",
                         action='version',
                         version=self.get_version(),
                         help="Get current version")
     self.args = parser.parse_args()
コード例 #12
0
 def _get_manifest_path(self, specific_part):
     if specific_part:
         if os.path.isfile(specific_part):
             upper_dir = os.path.dirname(specific_part)
         else:
             upper_dir = specific_part
     else:
         upper_dir = ""
     count = 0
     while self.no_manifest_in_folder(
             upper_dir) and count < const.ALLOWED_SUB_DIR_NUM:
         upper_dir = os.path.join(upper_dir, "../")
         count += 1
     if count == const.ALLOWED_SUB_DIR_NUM:
         self.out.write(msg_handler.get_print_msg(print_const.NO_MANIFEST))
         upper_dir = ""
     return upper_dir
コード例 #13
0
 def test_error_message_printed(self):
     out = StringIO()
     error_file_path = os.path.join(TESTS_RESOURCES_PATH,
                                    'error_handling_files/error-file.brs')
     result = bslint.bslint.runner(to_lex=error_file_path,
                                   out=out).printed_output
     print(result)
     self.assertEqual(
         msg_handler.get_print_msg(print_const.NO_MANIFEST) +
         msg_handler.get_print_msg(print_const.NO_BSLINTRC) +
         msg_handler.get_print_msg(print_const.FILE_NAME,
                                   ["file://" + error_file_path]) +
         msg_handler.get_print_msg(const.ERRORS, [
             msg_handler.get_error_msg(err_const.UNMATCHED_QUOTATION_MARK,
                                       ['"error file', 1])
         ]) + msg_handler.get_print_msg(print_const.LINTING_COMPLETE) +
         msg_handler.get_print_msg(print_const.TOTAL_WARNINGS, [0]) +
         msg_handler.get_print_msg(print_const.TOTAL_ERRORS, [1]), result)
コード例 #14
0
 def print_file_summary(self, file_name):
     number_warnings = len(self.messages[const.WARNINGS][file_name])
     self.out.write(
         msg_handler.get_print_msg(print_const.WARNINGS_IN_FILE,
                                   [number_warnings]))
コード例 #15
0
 def handle_lexing_result(self, filepath, error_type, messages):
     self.is_lexed_correctly = False
     self.messages[error_type][filepath] = []
     for msg in messages:
         self.messages[error_type][filepath].append(
             msg_handler.get_print_msg(error_type, [msg]))