Exemplo n.º 1
0
 def test_func_with_raises(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_function(
         tests.test_class.raises_class.RaisesClass.
         func_with_raise_and_args_and_return, config,
         tests.test_class.incorrect_class)
     assert result.result == ResultType.OK
Exemplo n.º 2
0
 def test_func_with_incorrect_raise(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_function(
         tests.test_class.raises_class.RaisesClass.
         func_with_incorrect_raise, config,
         tests.test_class.incorrect_class)
     assert result.result == ResultType.FAILED
Exemplo n.º 3
0
 def test_incorrect_class_func_type_mismatch(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_function(
         tests.test_class.incorrect_class.IncorrectTestClass.
         func_type_mismatch, config, tests.test_class.incorrect_class)
     assert result.result == ResultType.FAILED
     assert result.fail_reason == "Argument type differ. Argument 'a' was expected (from signature) to have type '<class 'int'>', but has (in docs) type '<class 'float'>'"
Exemplo n.º 4
0
 def test_incorrect_class_func_name_mismatch(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_function(
         tests.test_class.incorrect_class.IncorrectTestClass.
         func_name_mismatch, config, tests.test_class.incorrect_class)
     assert result.result == ResultType.FAILED
     assert result.fail_reason == "Argument name differ. Expected (from signature) 'a', but got (in docs) 'b'"
Exemplo n.º 5
0
 def test_incorrect_class_func_has_arg_returns_arg(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_function(
         tests.test_class.incorrect_class.IncorrectTestClass.
         func_has_arg_returns_arg, config, tests.test_class.incorrect_class)
     assert result.result == ResultType.FAILED
     assert result.fail_reason == "Return type differ. Expected (from signature) <class 'float'>, but got (in docs) <class 'NoneType'>."
Exemplo n.º 6
0
 def test_incorrect_class_empty_func(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_function(
         tests.test_class.incorrect_class.IncorrectTestClass.empty_func,
         config, tests.test_class.incorrect_class)
     assert result.result == ResultType.FAILED
     assert result.fail_reason == "Number of arguments differ. Expected (from signature) 0 arguments, but found (in docs) 1."
Exemplo n.º 7
0
 def test_func_no_summary_no_fail(self) -> None:
     config = Configuration.get_default_configuration()
     config.fail_on_missing_summary = False
     result = validate_function(
         tests.test_class.nodocstring_class.ClassNoDocString.
         func_no_summary, config, tests.test_class.correct_class)
     assert result.result == ResultType.OK
Exemplo n.º 8
0
 def test_func_no_summary_do_fail(self) -> None:
     config = Configuration.get_default_configuration()
     config.fail_on_missing_summary = True
     result = validate_function(
         tests.test_class.nodocstring_class.ClassNoDocString.
         func_no_summary, config, tests.test_class.correct_class)
     assert result.result == ResultType.FAILED
     assert result.fail_reason == 'Function does not have a summary'
Exemplo n.º 9
0
 def test_incorrect_class_is_fail(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_class(
         tests.test_class.incorrect_class.IncorrectTestClass, config,
         tests.test_class.incorrect_class)
     assert result.result == ResultType.FAILED
     for res in result.function_results:
         assert res.result == ResultType.FAILED
Exemplo n.º 10
0
 def test_fail_on_raises_section_dont_fail(self) -> None:
     config = Configuration.get_default_configuration()
     config.fail_on_raises_section = False
     result = validate_function(
         tests.test_class.raises_class.RaisesClass.
         func_with_incorrect_raise, config,
         tests.test_class.incorrect_class)
     assert result.result == ResultType.OK
Exemplo n.º 11
0
 def test_correct_class_class_is_ok(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_class(
         tests.test_class.correct_class.CorrectTestClass, config,
         tests.test_class.correct_class)
     assert result.result == ResultType.OK
     for res in result.function_results:
         assert res.result == ResultType.OK
Exemplo n.º 12
0
    def test_text_reporter_success_verbosity_1(self) -> None:
        config = Configuration.get_default_configuration()
        config.verbosity = Verbosity.SHOW_FAILED
        reporter = TextReporter(config)

        result = get_result_object(ResultType.OK)
        output = reporter.get_output(result)
        assert output == ""
Exemplo n.º 13
0
    def test_text_reporter_no_doc_no_fail(self) -> None:
        config = Configuration.get_default_configuration()
        config.verbosity = Verbosity.SHOW_ALL
        config.fail_on_missing_docstring = False
        reporter = TextReporter(config)

        result = get_result_object(ResultType.NO_DOC)
        output = reporter.get_output(result)
        assert output == ''
Exemplo n.º 14
0
 def test_func_argument_type_differ(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_function(
         tests.test_ranges.example_class.ExampleClass.
         func_argument_type_differ, config, tests.test_ranges.example_class)
     assert result.result == ResultType.FAILED
     assert 'Argument type differ' in result.fail_reason
     assert result.range is not None
     assert result.range.start_line == 77
     assert result.range.end_line == 84
Exemplo n.º 15
0
 def test_func_parse_exception(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_function(
         tests.test_ranges.example_class.ExampleClass.func_parse_exception,
         config, tests.test_ranges.example_class)
     assert result.result == ResultType.FAILED
     assert 'Unable to parse docstring' in result.fail_reason
     assert result.range is not None
     assert result.range.start_line == 22
     assert result.range.end_line == 32
Exemplo n.º 16
0
 def test_func_number_of_raised_exceptions_differ(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_function(
         tests.test_ranges.example_class.ExampleClass.
         func_number_of_raised_exceptions_differ, config,
         tests.test_ranges.example_class)
     assert result.result == ResultType.FAILED
     assert 'Number of listed raised exceptions does not match actual' in result.fail_reason
     assert result.range is not None
     assert result.range.start_line == 89
     assert result.range.end_line == 100
Exemplo n.º 17
0
 def test_func_no_docstring(self) -> None:
     config = Configuration.get_default_configuration()
     config.fail_on_missing_docstring = True
     result = validate_function(
         tests.test_ranges.example_class.ExampleClass.func_no_docstring,
         config, tests.test_ranges.example_class)
     assert result.result == ResultType.FAILED
     assert result.fail_reason == 'Function does not have a docstring'
     assert result.range is not None
     assert result.range.start_line == 16
     assert result.range.end_line == 16
Exemplo n.º 18
0
    def test_text_reporter_success(self) -> None:
        config = Configuration.get_default_configuration()
        reporter = JSONReporter(config)

        result = get_result_object(ResultType.OK)
        output = reporter.get_output(result)
        d = json.loads(output)
        assert d['result'] == ResultType.OK
        assert d['module_results'][0]['function_results'][0][
            'result'] == ResultType.OK
        assert d['module_results'][0]['class_results'][0]['function_results'][
            0]['result'] == ResultType.OK
Exemplo n.º 19
0
    def test_text_reporter_no_doc_no_fail(self) -> None:
        config = Configuration.get_default_configuration()
        config.fail_on_missing_docstring = False
        reporter = JSONReporter(config)

        result = get_result_object(ResultType.NO_DOC)
        output = reporter.get_output(result)
        d = json.loads(output)
        assert d['result'] == ResultType.NO_DOC
        assert d['module_results'][0]['function_results'][0][
            'result'] == ResultType.NO_DOC
        assert d['module_results'][0]['class_results'][0]['function_results'][
            0]['result'] == ResultType.NO_DOC
Exemplo n.º 20
0
    def test_text_reporter_success_verbosity_2(self) -> None:
        config = Configuration.get_default_configuration()
        config.verbosity = Verbosity.SHOW_ALL
        reporter = TextReporter(config)

        result = get_result_object(ResultType.OK)
        output = reporter.get_output(result)
        messages = [m for m in output.split("\n") if m]

        assert 'FunctionName' in messages[0]
        assert 'OK' in messages[0]

        assert 'MethodName' in messages[1]
        assert 'OK' in messages[1]
Exemplo n.º 21
0
    def test_text_reporter_failed(self) -> None:
        config = Configuration.get_default_configuration()
        config.verbosity = Verbosity.SHOW_ALL
        reporter = TextReporter(config)

        result = get_result_object(ResultType.FAILED, "FAIL REASON")
        output = reporter.get_output(result)
        messages = [m for m in output.split("\n") if m]

        assert 'FunctionName' in messages[0]
        assert 'FAIL | FAIL REASON' in messages[0]

        assert 'MethodName' in messages[1]
        assert 'FAIL | FAIL REASON' in messages[1]
Exemplo n.º 22
0
    def test_text_reporter_no_doc_do_fail(self) -> None:
        config = Configuration.get_default_configuration()
        config.verbosity = Verbosity.SHOW_ALL
        config.fail_on_missing_docstring = True
        reporter = TextReporter(config)

        result = get_result_object(ResultType.NO_DOC)
        output = reporter.get_output(result)

        messages = [m for m in output.split("\n") if m]
        assert 'FunctionName' in messages[0]
        assert 'is missing a docstring' in messages[0]

        assert 'MethodName' in messages[1]
        assert 'is missing a docstring' in messages[1]
Exemplo n.º 23
0
    def test_text_reporter_failed(self) -> None:
        config = Configuration.get_default_configuration()
        reporter = JSONReporter(config)

        result = get_result_object(ResultType.FAILED, "FAIL REASON")
        output = reporter.get_output(result)
        d = json.loads(output)
        assert d['result'] == ResultType.FAILED
        assert d['module_results'][0]['function_results'][0][
            'result'] == ResultType.FAILED
        assert d['module_results'][0]['function_results'][0][
            'fail_reason'] == "FAIL REASON"
        assert d['module_results'][0]['class_results'][0]['function_results'][
            0]['result'] == ResultType.FAILED
        assert d['module_results'][0]['class_results'][0]['function_results'][
            0]['fail_reason'] == "FAIL REASON"
Exemplo n.º 24
0
def get_configuration(root_dir: str,
                      config_path: Optional[str] = None) -> Configuration:
    """Searches for CONFIG_FILE_NAME in root_dir, unless a path is provided.

    Args:
        root_dir (str): The directory to search in.
        config_path (Optional[str], optional): [description]. Defaults to None.

    Returns:
        Configuration: Either a configuration matching the specified/found one, or a default one.
    """
    if config_path:
        return Configuration.get_configuration_from_path(config_path)

    config_paths = [p for p in os.listdir(root_dir) if p == CONFIG_FILE_NAME]
    if len(config_paths) == 0:
        # TODO: Is the interface better by returning Optional[Configuration] (None here)?
        # Then it is clearer that a config was not found.
        return Configuration.get_default_configuration(root_dir)

    path = os.path.join(root_dir, config_paths[0])
    return Configuration.get_configuration_from_path(path)
Exemplo n.º 25
0
 def test_get_type_from_module_raises(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_function(tests.test_utilities.example_class.ExampleClass.func_raises, config, tests.test_utilities.example_class)
     assert 'Unable to parse docstring: a (DEFINITELYNOTACLASS): [description]' in result.fail_reason
Exemplo n.º 26
0
 def test_correct_class_empty_func(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_function(
         tests.test_class.correct_class.CorrectTestClass.empty_func, config,
         tests.test_class.correct_class)
     assert result.result == ResultType.OK
Exemplo n.º 27
0
 def test_correct_class_has_arg_returns_arg(self) -> None:
     config = Configuration.get_default_configuration()
     result = validate_function(
         tests.test_class.correct_class.CorrectTestClass.
         func_has_arg_returns_arg, config, tests.test_class.correct_class)
     assert result.result == ResultType.OK
Exemplo n.º 28
0
 def test_get_default_reporter(self) -> None:
     config = Configuration.get_default_configuration()
     reporter = get_reporter(config=config)
     assert isinstance(reporter, TextReporter)
Exemplo n.º 29
0
 def test_get_reporter(self) -> None:
     config = Configuration.get_default_configuration()
     reporter = get_reporter(config=config, reporter="json")
     assert isinstance(reporter, JSONReporter)
Exemplo n.º 30
0
 def test_get_non_existing_reporter(self) -> None:
     config = Configuration.get_default_configuration()
     with pytest.raises(Exception) as exn_info:
         reporter = get_reporter(config=config, reporter="doesnotexist")
     assert 'Unknown reporter' in str(exn_info.value)