Exemple #1
0
    def test_handles_builtins_in_expression(self):
        self.assertTrue(
            FeatureConstructorHandler().is_valid_item(
                OWFeatureConstructor.descriptors,
                StringDescriptor("X", "str(A) + str(B)"),
                {"A": vartype(DiscreteVariable)},
                {"B": vartype(DiscreteVariable)}
            )
        )

        # no variables is also ok
        self.assertTrue(
            FeatureConstructorHandler().is_valid_item(
                OWFeatureConstructor.descriptors,
                StringDescriptor("X", "str('foo')"),
                {},
                {}
            )
        )

        # should fail on unknown variables
        self.assertFalse(
            FeatureConstructorHandler().is_valid_item(
                OWFeatureConstructor.descriptors,
                StringDescriptor("X", "str(X)"),
                {},
                {}
            )
        )
Exemple #2
0
 def test_handles_special_characters_in_var_names(self):
     self.assertTrue(
         FeatureConstructorHandler().is_valid_item(
             OWFeatureConstructor.descriptors,
             StringDescriptor("X", "A_2_f"),
             {"A.2 f": vartype(DiscreteVariable)},
             {}
         )
     )