예제 #1
0
 def test_add_type(self):
     apiview = ApiView()
     apiview.tokens = []
     apiview.add_type(type_name="a.b.c.1.2.3.MyType")
     tokens = apiview.tokens
     assert len(tokens) == 2
     assert tokens[0].kind == TokenKind.TypeName
     assert tokens[1].kind == TokenKind.Punctuation
예제 #2
0
 def test_multiple_newline_only_add_one(self):
     apiview = ApiView(None, "test", "0.0", "test")
     apiview.add_text(None, "Something")
     apiview.add_newline()
     # subsequent calls result in no change
     apiview.add_newline()
     apiview.add_newline()
     assert self._count_newlines(apiview) == 1
예제 #3
0
 def parse(cls, path):
     from apistub import ApiView
     pkg_name = os.path.split(path)[-1]
     rcfile_path = os.path.join(ApiView.get_root_path(), "pylintrc")
     logging.debug(f"APIView root path: {ApiView.get_root_path()}")
     (pylint_stdout, pylint_stderr) = epylint.py_run(
         f"{path} -f json --recursive=y --rcfile {rcfile_path}",
         return_std=True)
     stderr_str = pylint_stderr.read()
     # strip put stray, non-json lines from stdout
     stdout_lines = [
         x for x in pylint_stdout.readlines()
         if not x.startswith("Exception")
     ]
     try:
         json_items = json.loads("".join(stdout_lines))
         plugin_failed = any(
             [x["symbol"] == "bad-plugin-value" for x in json_items])
         if plugin_failed:
             logging.error(
                 f"Unable to load pylint_guidelines_checker. Check that it is installed."
             )
     except json.JSONDecodeError as err:
         logging.error(f"Error decoding pylint output:\n{stderr_str}")
         logging.error(f"Error content:\n{err}")
         logging.error(f"==STDOUT==\n{stdout_lines}")
         raise err
     cls.items = [
         PylintError(pkg_name, **x) for x in json_items
         if x["message-id"][1:3] == PylintParser.AZURE_CHECKER_CODE
     ]
예제 #4
0
    def test_set_blank_lines(self):
        apiview = ApiView(None, "test", "0.0", "test")
        apiview.set_blank_lines(3)
        assert self._count_newlines(apiview) == 4  # +1 for carriage return

        apiview.add_text(None, "Something")
        apiview.add_newline()
        apiview.set_blank_lines(1)
        apiview.set_blank_lines(5)
        # only the last invocation matters
        apiview.set_blank_lines(2)
        assert self._count_newlines(apiview) == 3  # +1 for carriage return
예제 #5
0
def _tokenize(node):
    apiview = ApiView(pkg_name="test", namespace="test")
    apiview.tokens = []
    node.generate_tokens(apiview)
    return apiview.tokens