def test_ok_for_kwonly_annotated_file(): errors = run_validator_for_test_file('kwonly_arg_annotated.py', min_coverage=50) assert not errors errors = run_validator_for_test_file('kwonly_arg_annotated.py', min_coverage=100) assert len(errors) == 1
def test_warning_if_both_strict_mode_and_configurable_order_defined(): with warnings.catch_warnings(record=True) as w: run_validator_for_test_file( 'ok.py', strict_mode=True, attributes_order=['nested_class', 'field', 'method']) assert len(w) == 1
def test_ok_for_strict_names_file(): errors = run_validator_for_test_file('strict_names.py', use_strict_mode=False) assert not errors errors = run_validator_for_test_file('strict_names.py', use_strict_mode=True) assert len(errors) == 2
def test_pep_585_compliance(): errors = run_validator_for_test_file('pep_585.py') assert not errors errors = run_validator_for_test_file('pep_585.py', max_annotations_complexity=1) assert len(errors) == 11 errors = run_validator_for_test_file('pep_585.py', max_annotations_complexity=2) assert len(errors) == 2
def test_ok_for_short_names_file(): errors = run_validator_for_test_file('short_names.py', use_strict_mode=True) assert len(errors) == 4 errors = run_validator_for_test_file('short_names.py', use_strict_mode=False) assert len(errors) == 3 assert ( get_error_message(errors[0]) == "VNE001 single letter variable names like 'a' are not allowed" )
def test_ok_for_empty_string(): errors = run_validator_for_test_file('empty_string.py') assert not errors errors = run_validator_for_test_file('empty_string.py', max_annotations_complexity=1) assert len(errors) == 2 errors = run_validator_for_test_file('empty_string.py', max_annotations_complexity=2) assert not errors
def test_child_attributes_fallback_to_parent_if_not_configured(): assert not run_validator_for_test_file( 'configurable.py', attributes_order=['field', 'nested_class', 'method'], ) errors = run_validator_for_test_file( 'configurable.py', attributes_order=['nested_class', 'field', 'method'], ) assert len(errors) == 1
def test_max_function_length(filename, max_function_length, errors_count): errors = run_validator_for_test_file( filename=filename, max_function_length=max_function_length, ) assert len(errors) == errors_count
def test_nested_last_statement(): errors = run_validator_for_test_file( filename='file_with_deep_nested.py', max_function_length=4, ) assert len(errors) == 1
def test_decorator_is_ignored(): errors = run_validator_for_test_file( filename='file_with_long_decorator.py', max_function_length=6, ) assert len(errors) == 0
def test_pass_function_is_processed(): errors = run_validator_for_test_file( filename='file_pass_function.py', max_function_length=1, ) assert len(errors) == 0
def test_save_delete() -> None: errors = run_validator_for_test_file("special_method.py") assert len(errors) == 4 assert errors[0][2] == "CCE001 A.foo should be after A.__new__" assert errors[1][2] == "CCE001 B.foo should be after B.__init__" assert errors[2][2] == "CCE001 C.foo should be after C.__post_init__" assert errors[3][2] == "CCE001 D.foo should be after D.__str__"
def test_shows_error_for_too_much_arguments(): errors = run_validator_for_test_file( filename='file_with_lots_of_arguments.py', max_parameters_amount=3, ) assert len(errors) == 3
def test_nested_defs_with_returns(max_returns_amount, expected_errors_count): errors = run_validator_for_test_file( filename='file_with_nested_defs.py', max_returns_amount=max_returns_amount, ) assert len(errors) == expected_errors_count
def test_too_much_returns(max_returns_amount, expected_errors_count): errors = run_validator_for_test_file( filename='file_with_lots_of_returns.py', max_returns_amount=max_returns_amount, ) assert len(errors) == expected_errors_count
def test_ok_for_blacklisted_names_file(): errors = run_validator_for_test_file('blacklisted_names.py', use_strict_mode=True) assert len(errors) == 2 assert ( get_error_message(errors[0]) == "VNE002 variable name 'value' should be clarified" )
def test_dosctrings_are_not_part_of_function_length(max_function_length, expected_errors_count): errors = run_validator_for_test_file( filename='file_with_docstring.py', max_function_length=max_function_length, ) assert len(errors) == expected_errors_count
def test_save_delete(): errors = run_validator_for_test_file('special_method.py', ) assert len(errors) == 6 assert errors[0][2] == 'CCE001 A.foo should be after A.__new__' assert errors[1][2] == 'CCE001 B.foo should be after B.__init__' assert errors[2][2] == 'CCE001 C.foo should be after C.__post_init__' assert errors[3][2] == 'CCE001 D.foo should be after D.__str__' assert errors[4][2] == 'CCE001 E.foo should be after E.save' assert errors[5][2] == 'CCE001 F.foo should be after F.delete'
def test_configurable_order_correct_order(): assert not run_validator_for_test_file( 'configurable.py', attributes_order=[ 'constant', 'field', 'meta_class', 'magic_method', 'property_method', 'method', 'private_method', '__str__', ], )
def test_configurable_order_wrong_order(): errors = run_validator_for_test_file( 'configurable.py', attributes_order=[ 'field', 'constant', 'meta_class', 'nested_class', 'magic_method', 'property_method', 'method', '__str__', 'private_method', ], ) assert len(errors) == 2
def test_ok_for_string_annotations_file(): errors = run_validator_for_test_file('string_annotations.py') assert len(errors) == 1 errors = run_validator_for_test_file('string_annotations.py', max_annotations_complexity=1) assert len(errors) == 2
def test_function_purity(): errors = run_validator_for_test_file(filename='file_pure_function.py', ) assert len(errors) == 0
def test_ok_for_unannotated_file(): errors = run_validator_for_test_file('unannotated.py', max_annotations_complexity=1) assert not errors
def test_walrus(): errors = run_validator_for_test_file('walrus.py', max_expression_complexity=1) assert len(errors) == 1
def test_get_error_for_not_too_complex_file_with_blacklisted_vars(): errors = run_validator_for_test_file('too_complex_with_blacklisted.py') assert len(errors) == 1
def test_get_error_for_too_complex_file(): errors = run_validator_for_test_file('too_complex.py') assert len(errors) == 1
def test_validates_annotations_complexity_for_annassigments(): errors = run_validator_for_test_file('var_annotation.py') assert len(errors) == 1
def test_not_raises_errors_for_weird_annotations(): errors = run_validator_for_test_file('weird_annotations.py') assert not errors
def test_fails(): errors = run_validator_for_test_file('long_expressions.py', max_expression_compexity=3) assert len(errors) == 3
def test_always_ok_for_empty_file(): errors = run_validator_for_test_file('empty.py') assert not errors errors = run_validator_for_test_file('empty.py', max_annotations_complexity=1) assert not errors