Ejemplo n.º 1
0
 def test_unequal_partial_unordered_duplicates(self):
     s = SequenceComparison(1, 2, 2, ordered=False, partial=True)
     assert s != (1, 2)
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=False, partial=True)(failed)>\n'
         'same:\n'
         "[1, 2]\n\n"
         'in expected but not actual:\n'
         "[2]\n"
         '</SequenceComparison(ordered=False, partial=True)>'
     ))
Ejemplo n.º 2
0
 def test_unequal_nested_unhashable_unordered(self):
     s = SequenceComparison({2: True}, {1: True}, {2: True}, {3: True}, ordered=False)
     assert s != ({1: True}, {2: True}, {4: True})
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=False, partial=False)(failed)>\n'
         'same:\n'
         "[{2: True}, {1: True}]\n\n"
         'in expected but not actual:\n'
         "[{2: True}, {3: True}]\n\n"
         'in actual but not expected:\n'
         "[{4: True}]\n"
         '</SequenceComparison(ordered=False, partial=False)>'
     ))
Ejemplo n.º 3
0
 def test_unequal_prefix_match_but_partial_false(self):
     s = SequenceComparison(1, 2, partial=False)
     assert s != (1, 2, 4)
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=True, partial=False)(failed)>\n'
         'same:\n'
         '[1, 2]\n\n'
         'expected:\n'
         '[]\n\n'
         'actual:\n'
         '[4]\n'
         '</SequenceComparison(ordered=True, partial=False)>'
     ))
Ejemplo n.º 4
0
 def test_unequal_generator(self):
     s = SequenceComparison(1, 3)
     assert s != generator(1, 2)
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=True, partial=False)(failed)>\n'
         'same:\n'
         "[1]\n\n"
         'expected:\n'
         '[3]\n\n'
         'actual:\n'
         '[2]\n'
         '</SequenceComparison(ordered=True, partial=False)>'
     ))
Ejemplo n.º 5
0
 def test_unequal_nested(self):
     s = SequenceComparison({1: 'a', 2: 'b'}, [1, 2], recursive=False)
     assert s != ({2: 'b', 3: 'c'}, [1, 3])
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=True, partial=False)(failed)>\n'
         'same:\n'
         "[]\n\n"
         'expected:\n'
         "[{1: 'a', 2: 'b'}, [1, 2]]\n\n"
         'actual:\n'
         "[{2: 'b', 3: 'c'}, [1, 3]]\n"
         '</SequenceComparison(ordered=True, partial=False)>'
     ))
Ejemplo n.º 6
0
 def test_unequal_list(self):
     s = SequenceComparison(1, 2, 3)
     assert s != (1, 2, 4)
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=True, partial=False)(failed)>\n'
         'same:\n'
         '[1, 2]\n\n'
         'expected:\n'
         '[3]\n\n'
         'actual:\n'
         '[4]\n'
         '</SequenceComparison(ordered=True, partial=False)>'
     ))
Ejemplo n.º 7
0
 def test_unequal_full_ordered(self):
     s = SequenceComparison(1, 3, 5, ordered=True, partial=False)
     assert s != (0, 1, 2, 3, 4)
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=True, partial=False)(failed)>\n'
         'same:\n'
         '[]\n\n'
         'expected:\n'
         '[1, 3, 5]\n\n'
         'actual:\n'
         '[0, 1, 2, 3, 4]\n'
         '</SequenceComparison(ordered=True, partial=False)>'
     ))
Ejemplo n.º 8
0
 def test_unequal_partial_unordered(self):
     s = SequenceComparison(1, 3, ordered=False, partial=True)
     assert s != (2, 1, 4)
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=False, partial=True)(failed)>\n'
         'ignored:\n'
         '[2, 4]\n\n'
         'same:\n'
         "[1]\n\n"
         'in expected but not actual:\n'
         "[3]\n"
         '</SequenceComparison(ordered=False, partial=True)>'
     ))
Ejemplo n.º 9
0
 def test_unequal_same_but_all_wrong_order(self):
     s = SequenceComparison(1, 2, 3)
     assert s != (3, 1, 2)
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=True, partial=False)(failed)>\n'
         'same:\n'
         '[]\n\n'
         'expected:\n'
         '[1, 2, 3]\n\n'
         'actual:\n'
         '[3, 1, 2]\n'
         '</SequenceComparison(ordered=True, partial=False)>'
     ))
Ejemplo n.º 10
0
 def test_unequal_partial_ordered_only_one_ignored_recursive(self):
     s = SequenceComparison(1, 2, ordered=True, partial=True, recursive=True)
     assert s != (2, 1, 4)
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=True, partial=True)(failed)>\n'
         'ignored:\n'
         '[4]\n\n'
         'same:\n'
         '[]\n\n'
         'expected:\n'
         '[1, 2]\n\n'
         'actual:\n'
         '[2, 1]\n'
         '</SequenceComparison(ordered=True, partial=True)>'
     ))
Ejemplo n.º 11
0
 def test_unequal_partial_ordered_with_prefix(self):
     s = SequenceComparison('a', 'b', 1, 2, ordered=True, partial=True)
     assert s != ('a', 'b', 2, 1, 4)
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=True, partial=True)(failed)>\n'
         'ignored:\n'
         '[2, 4]\n\n'
         'same:\n'
         "['a', 'b', 1]\n\n"
         'expected:\n'
         '[2]\n\n'
         'actual:\n'
         '[]\n'
         '</SequenceComparison(ordered=True, partial=True)>'
     ))
Ejemplo n.º 12
0
 def test_unequal_partial_ordered_recursive(self):
     s = SequenceComparison(1, 3, 5, ordered=True, partial=True, recursive=True)
     assert s != (1, 2, 3, 4, 0)
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=True, partial=True)(failed)>\n'
         'ignored:\n'
         '[4, 0]\n\n'
         'same:\n'
         '[1]\n\n'
         'expected:\n'
         '[3, 5]\n\n'
         'actual:\n'
         '[2, 3]\n'
         '</SequenceComparison(ordered=True, partial=True)>'
     ))
Ejemplo n.º 13
0
 def test_unequal_nested_recursive(self):
     s = SequenceComparison({1: 'a', 2: 'b'}, [1, 2], recursive=True)
     assert s != ({2: 'b', 3: 'c'}, [1, 3])
     compare(repr(s), expected=(
         '\n'
         '<SequenceComparison(ordered=True, partial=False)(failed)>\n'
         'same:\n'
         "[]\n\n"
         'expected:\n'
         "[{1: 'a', 2: 'b'}, [1, 2]]\n\n"
         'actual:\n'
         "[{2: 'b', 3: 'c'}, [1, 3]]\n\n"
         "While comparing [0]: dict not as expected:\n\n"
         "same:\n"
         "[2]\n\n"
         "in expected but not actual:\n"
         "1: 'a'\n\n"
         "in actual but not expected:\n"
         "3: 'c'\n"
         '</SequenceComparison(ordered=True, partial=False)>'
     ))
def test_no_illegal_features():
    """
    Tests whether NoIllegalFeatures works for joins
    """
    test_code = cleandoc("""
            import pandas as pd
            from sklearn.preprocessing import label_binarize, StandardScaler, OneHotEncoder
            from sklearn.compose import ColumnTransformer
            from sklearn.pipeline import Pipeline
            from sklearn.tree import DecisionTreeClassifier

            data = pd.DataFrame({'age': [1, 2, 10, 5], 'B': ['cat_a', 'cat_b', 'cat_a', 'cat_c'], 
                'C': ['cat_a', 'cat_b', 'cat_a', 'cat_c'], 'target': ['no', 'no', 'yes', 'yes']})
                
            column_transformer = ColumnTransformer(transformers=[
                ('numeric', StandardScaler(), ['age']),
                ('categorical', OneHotEncoder(sparse=False), ['B', 'C'])
            ])
            
            income_pipeline = Pipeline([
                ('features', column_transformer),
                ('classifier', DecisionTreeClassifier())])
            
            labels = label_binarize(data['target'], classes=['no', 'yes'])
            income_pipeline.fit(data, labels)
            """)

    inspector_result = PipelineInspector \
        .on_pipeline_from_string(test_code) \
        .add_check(NoIllegalFeatures(['C'])) \
        .execute()

    check_result = inspector_result.check_to_check_results[NoIllegalFeatures(
        ['C'])]
    # pylint: disable=anomalous-backslash-in-string
    expected_result = NoIllegalFeaturesResult(
        NoIllegalFeatures(['C']), CheckStatus.FAILURE,
        StringComparison("Used illegal columns\: .*"),
        SequenceComparison('C', 'age', ordered=False))
    compare(check_result, expected_result)
Ejemplo n.º 15
0
 def test_equal_list(self):
     s = SequenceComparison(1, 2, 3)
     assert s == [1, 2, 3]
Ejemplo n.º 16
0
 def test_equal_nested_unhashable_unordered_partial(self):
     s = SequenceComparison({1}, {2}, {2}, ordered=False, partial=True)
     assert s == ({2}, {1}, {2}, {3})
Ejemplo n.º 17
0
 def test_equal_ordered_duplicates(self):
     s = SequenceComparison(1, 2, 2, ordered=True, partial=True)
     assert s == (1, 2, 2, 3)
Ejemplo n.º 18
0
 def test_unequal_bad_type(self):
     s = SequenceComparison(1, 3)
     assert s != object()
     compare(repr(s),
             expected="<SequenceComparison(ordered=True, partial=False)(failed)>bad type</>")
Ejemplo n.º 19
0
 def test_equal_partial_ordered(self):
     s = SequenceComparison(1, 2, 1, ordered=True, partial=True)
     assert s == (1, 1, 2, 1)
Ejemplo n.º 20
0
 def test_repr(self):
     compare(repr(SequenceComparison(1, 2, 3)),
             expected='<SequenceComparison(ordered=True, partial=False)>1, 2, 3</>')
Ejemplo n.º 21
0
 def test_equal_unordered(self):
     s = SequenceComparison(1, 2, 3, ordered=False)
     assert s == (1, 3, 2)
Ejemplo n.º 22
0
 def test_equal_partial_unordered(self):
     s = SequenceComparison(1, 2, ordered=False, partial=True)
     assert s == (2, 1, 4)
Ejemplo n.º 23
0
 def test_equal_generator(self):
     s = SequenceComparison(1, 2, 3)
     assert s == generator(1, 2, 3)
Ejemplo n.º 24
0
 def test_partial_wrong_type(self):
     s = SequenceComparison(partial=True)
     assert s != object()
Ejemplo n.º 25
0
 def test_equal_tuple(self):
     s = SequenceComparison(1, 2, 3)
     assert s == (1, 2, 3)
Ejemplo n.º 26
0
 def test_repr_long(self):
     actual = repr(SequenceComparison('a', 'b', 'c'*1000))[:60]
     compare(actual,
             expected='\n'
                      "<SequenceComparison(ordered=True, partial=False)>\n'a',\n 'b'")
Ejemplo n.º 27
0
 def test_equal_nested_unhashable_unordered(self):
     s = SequenceComparison({1}, {2}, {2}, ordered=False)
     assert s == ({2}, {1}, {2})
Ejemplo n.º 28
0
 def test_partial_nothing_specified(self):
     s = SequenceComparison(partial=True)
     assert s == {}
Ejemplo n.º 29
0
 def test_repr_after_equal(self):
     s = SequenceComparison(1, 2, 3)
     assert s == (1, 2, 3)
     compare(repr(s), expected='<SequenceComparison(ordered=True, partial=False)>1, 2, 3</>')