コード例 #1
0
    def test_valuefromstringsubstring_equality(self):
        str1 = StringVariable("d1")
        str1a = StringVariable("d1")
        str2 = StringVariable("d2")
        assert str1 == str1a

        t1 = ValueFromStringSubstring(str1, ["abc", "def"])
        t1a = ValueFromStringSubstring(str1a, ["abc", "def"])
        t2 = ValueFromStringSubstring(str2, ["abc", "def"])
        self.assertEqual(t1, t1)
        self.assertEqual(t1, t1a)
        self.assertNotEqual(t1, t2)

        self.assertEqual(hash(t1), hash(t1a))
        self.assertNotEqual(hash(t1), hash(t2))

        t1 = ValueFromStringSubstring(str1, ["abc", "def"])
        t1a = ValueFromStringSubstring(str1a, ["abc", "ghi"])
        self.assertNotEqual(t1, t1a)
        self.assertNotEqual(hash(t1), hash(t1a))

        t1 = ValueFromStringSubstring(str1, ["abc", "def"], True)
        t1a = ValueFromStringSubstring(str1a, ["abc", "def"], False)
        self.assertNotEqual(t1, t1a)
        self.assertNotEqual(hash(t1), hash(t1a))

        t1 = ValueFromStringSubstring(str1, ["abc", "def"], True, True)
        t1a = ValueFromStringSubstring(str1a, ["abc", "def"], True, False)
        self.assertNotEqual(t1, t1a)
        self.assertNotEqual(hash(t1), hash(t1a))
コード例 #2
0
    def test_value_string_substring_flags(self):
        trans = ValueFromStringSubstring(StringVariable("x"), self.patterns)
        with patch('Orange.widgets.data.owcreateclass.map_by_substring') as mbs:
            trans.case_sensitive = True
            trans.transform(self.arr)
            case_sensitive, match_beginning = mbs.call_args[0][-3:-1]
            self.assertTrue(case_sensitive)
            self.assertFalse(match_beginning)

            trans.case_sensitive = False
            trans.match_beginning = True
            trans.transform(self.arr)
            case_sensitive, match_beginning = mbs.call_args[0][-3:-1]
            self.assertFalse(case_sensitive)
            self.assertTrue(match_beginning)
コード例 #3
0
ファイル: test_owcreateclass.py プロジェクト: acopar/orange3
    def test_value_string_substring_flags(self):
        trans = ValueFromStringSubstring(StringVariable(), self.patterns)
        with patch('Orange.widgets.data.owcreateclass.map_by_substring') as mbs:
            trans.case_sensitive = True
            trans.transform(self.arr)
            case_sensitive, match_beginning = mbs.call_args[0][-2:]
            self.assertTrue(case_sensitive)
            self.assertFalse(match_beginning)

            trans.case_sensitive = False
            trans.match_beginning = True
            trans.transform(self.arr)
            case_sensitive, match_beginning = mbs.call_args[0][-2:]
            self.assertFalse(case_sensitive)
            self.assertTrue(match_beginning)
コード例 #4
0
    def test_value_from_string_substring(self):
        trans = ValueFromStringSubstring(StringVariable(), self.patterns)
        arr2 = np.hstack((self.arr.astype(object), [None]))

        with patch("Orange.widgets.data.owcreateclass.map_by_substring") as mbs:
            trans.transform(self.arr)
            a, patterns, case_sensitive, match_beginning = mbs.call_args[0]
            np.testing.assert_equal(a, self.arr)
            self.assertEqual(patterns, self.patterns)
            self.assertFalse(case_sensitive)
            self.assertFalse(match_beginning)

            trans.transform(arr2)
            a, patterns, *_ = mbs.call_args[0]
            np.testing.assert_equal(a, np.hstack((self.arr.astype(str), "")))

        np.testing.assert_equal(trans.transform(arr2), [0, 1, 2, 0, 3, np.nan])
コード例 #5
0
ファイル: test_owcreateclass.py プロジェクト: acopar/orange3
    def test_value_from_string_substring(self):
        trans = ValueFromStringSubstring(StringVariable(), self.patterns)
        arr2 = np.hstack((self.arr.astype(object), [None]))

        with patch('Orange.widgets.data.owcreateclass.map_by_substring') as mbs:
            trans.transform(self.arr)
            a, patterns, case_sensitive, match_beginning = mbs.call_args[0]
            np.testing.assert_equal(a, self.arr)
            self.assertEqual(patterns, self.patterns)
            self.assertFalse(case_sensitive)
            self.assertFalse(match_beginning)

            trans.transform(arr2)
            a, patterns, *_ = mbs.call_args[0]
            np.testing.assert_equal(a,
                                    np.hstack((self.arr.astype(str), "")))

        np.testing.assert_equal(trans.transform(arr2),
                                [0, 1, 2, 0, 3, np.nan])