Пример #1
0
def test_set_with_pure_unique(
    assert_errors,
    parse_ast_tree,
    code,
    element,
    default_options,
):
    """Testing that unique elements are allowed."""
    tree = parse_ast_tree(code.format(element, 'other'))

    visitor = WrongCollectionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
Пример #2
0
def test_set_with_pure_duplicate(
    assert_errors,
    parse_ast_tree,
    code,
    element,
    default_options,
):
    """Testing that pure elements can not be contained multiple times."""
    tree = parse_ast_tree(code.format(element, element))

    visitor = WrongCollectionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [NonUniqueItemsInHashViolation])
Пример #3
0
def test_collection_with_impure(
    assert_errors,
    parse_ast_tree,
    code,
    element,
    default_options,
):
    """Testing that impure elements can be contained in set multiple times."""
    tree = parse_ast_tree(code.format(element, element))

    visitor = WrongCollectionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
Пример #4
0
def test_dict_with_regular(
    assert_errors,
    parse_ast_tree,
    code,
    element,
    default_options,
):
    """Testing that regular keys are allowed."""
    tree = parse_ast_tree(code.format(element, element))

    visitor = WrongCollectionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
Пример #5
0
def test_dict_with_float_key(
    assert_errors,
    parse_ast_tree,
    code,
    element,
    default_options,
):
    """Testing that float keys are not allowed."""
    tree = parse_ast_tree(code.format(element, element))

    visitor = WrongCollectionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [FloatKeyViolation])
def test_hash_with_impure(
    assert_errors,
    parse_ast_tree,
    code,
    element,
    default_options,
):
    """Testing that impure elements can be contained in hash."""
    tree = parse_ast_tree(code.format(element, 'correct'))

    visitor = WrongCollectionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [UnhashableTypeInHashViolation])
Пример #7
0
def test_set_with_similar_values(
    assert_errors,
    parse_ast_tree,
    code,
    first,
    second,
    default_options,
):
    """Testing that same values are reported."""
    tree = parse_ast_tree(code.format(first, second))

    visitor = WrongCollectionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [NonUniqueItemsInHashViolation])
def test_hash_with_impure_duplicates(
    assert_errors,
    parse_ast_tree,
    code,
    element,
    default_options,
):
    """Testing that impure elements can be contained in hash."""
    tree = parse_ast_tree(code.format(element, element))

    visitor = WrongCollectionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [
        NonUniqueItemsInHashViolation,
        UnhashableTypeInHashViolation,
        UnhashableTypeInHashViolation,
    ])