Beispiel #1
0
    def test_report(self):
        settings = {
            "context_settings":
                [Context(
                    attributes=dict(x=2, y=2, z=2), metas={},
                    values=dict(
                        descriptors=[
                            ContinuousDescriptor("a", "x + 2", 1),
                            DiscreteDescriptor("b", "x < 3", (), False),
                            DiscreteDescriptor("c", "x > 15", (), True),
                            DiscreteDescriptor("d", "y > x", ("foo", "bar"), False),
                            DiscreteDescriptor("e", "x ** 2 + y == 5", ("foo", "bar"), True),
                            StringDescriptor("f", "str(x)"),
                            DateTimeDescriptor("g", "z")
                        ],
                        currentIndex=0)
                )]
        }

        w = self.create_widget(OWFeatureConstructor, settings)
        v = [ContinuousVariable(name) for name in "xyz"]
        domain = Domain(v, [])
        self.send_signal(w.Inputs.data, Table.from_numpy(domain, [[0, 1, 2]]))
        w.report_items = Mock()
        w.send_report()
        args = w.report_items.call_args[0][1]
        self.assertEqual(list(args), list("abcdefg"))
Beispiel #2
0
 def test_construct_variables_datetime(self):
     data = Table("housing")
     name = 'Date'
     expression = '"2019-07-{:02}".format(int(MEDV/3))'
     featuremodel = PyListModel(
         [DateTimeDescriptor(name=name, expression=expression)])
     data = Table(
         Domain(
             list(data.domain.attributes) +
             construct_variables(featuremodel, data),
             data.domain.class_vars, data.domain.metas), data)
     self.assertTrue(isinstance(data.domain[name], TimeVariable))
     for row in data:
         self.assertEqual("2019-07-{:02}".format(int(row["MEDV"] / 3)),
                          str(row["Date"])[:10])