Ejemplo n.º 1
0
    def test_ensure_str(self):
        values = (1, Number(5), "1", Symbol("hello"))
        for val in values:
            self.assertEqual(str(val), ensure_str(val))

        bad_values = (None, Null(), Glob("*"), Regex(".*"), [], ())
        for val in bad_values:
            self.assertRaises(SifterError, ensure_str, val)
Ejemplo n.º 2
0
    def test_ensure_int(self):
        values = (1, Number(5))
        for val in values:
            self.assertTrue(int(val) is ensure_int(val))

        bad_values = (None, Null(), Glob("*"), Regex(".*"), Symbol("100"),
                      "100", [], ())
        for val in bad_values:
            self.assertRaises(SifterError, ensure_int, val)
Ejemplo n.º 3
0
    def test_int_or_str_sieve(self):
        good_values = (1, Number(5), "hello", Symbol("hello"))

        vals = ExIntStrSieve(Sifter((), ""), *good_values).tokens
        self.assertEqual(good_values, vals)

        bad_values = (None, Null(), Glob("*"), Regex(".*"), [], ())

        self.assertRaises(SifterError, ExIntStrSieve, None, *bad_values)
Ejemplo n.º 4
0
    def test_symbol_sieve(self):
        good_values = (Symbol("Hello"), Symbol("World"))

        vals = ExSymbolSieve(Sifter((), ""), *good_values).tokens
        self.assertEqual(good_values, vals)

        bad_values = (None, Null(), 123, Number(5), "wut", Glob("*"),
                      Regex(".*"), [], ())

        self.assertRaises(SifterError, ExSymbolSieve, None, *bad_values)
Ejemplo n.º 5
0
    def test_matcher_sieve(self):
        good_values = ("hello", Null(), Number(5), Symbol("hello"), Glob("*"),
                       Regex(".*"))

        vals = ExMatcherSieve(Sifter((), ""), *good_values).tokens
        self.assertEqual(good_values, vals)

        bad_values = (None, [], (), 123)

        self.assertRaises(SifterError, ExMatcherSieve, None, *bad_values)
Ejemplo n.º 6
0
    def test_ensure_matcher(self):
        values = ("hello", Null(), Number(5), Symbol("hello"), Glob("*"),
                  Regex(".*"))
        for val in values:
            self.assertTrue(val is ensure_matcher(val))

        bad_values = (None, [], (), 123)
        for val in bad_values:
            self.assertRaises(SifterError, ensure_matcher, val)

        self.assertEqual(list(values), ensure_all_matcher(values))
        self.assertRaises(SifterError, ensure_all_matcher, bad_values)
Ejemplo n.º 7
0
    def test_ensure_symbol(self):
        val = Symbol("Hello")
        self.assertTrue(val is ensure_symbol(val))

        good_values = [val]

        bad_values = (None, Null(), 123, Number(5), "wut", Glob("*"),
                      Regex(".*"), [], ())
        for val in bad_values:
            self.assertRaises(SifterError, ensure_symbol, val)

        self.assertEqual(good_values, ensure_all_symbol(good_values))
        self.assertRaises(SifterError, ensure_all_symbol, bad_values)
Ejemplo n.º 8
0
    def test_ensure_int_or_str(self):
        int_values = (1, Number(5))
        for val in int_values:
            res = ensure_int_or_str(val)
            self.assertTrue(type(res), int)
            self.assertTrue(val == res)

        str_values = ("hello", Symbol("hello"))
        for val in str_values:
            res = ensure_int_or_str(val)
            self.assertTrue(type(res), str)
            self.assertTrue(val == res)

        bad_values = (None, Null(), Glob("*"), Regex(".*"), [], ())
        for val in bad_values:
            self.assertRaises(SifterError, ensure_int_or_str, val)

        good_values = []
        good_values.extend(int_values)
        good_values.extend(str_values)

        self.assertEqual(good_values, ensure_all_int_or_str(good_values))
        self.assertRaises(SifterError, ensure_all_int_or_str, bad_values)
Ejemplo n.º 9
0
    def test_glob(self):
        self.in_data(Glob("Hello"), 4, "Hello")
        self.in_data(Glob("*ll*"), 4, "Hello")
        self.in_data(Glob("*o"), 4, "Hello")

        self.in_data(Glob("HELLO", True), 4, "Hello")
        self.in_data(Glob("*LL*", True), 4, "Hello")
        self.in_data(Glob("*O", True), 4, "Hello")
        self.in_data(Glob("hello", True), 4, "Hello")
        self.in_data(Glob("*ll*", True), 4, "Hello")
        self.in_data(Glob("*o", True), 4, "Hello")

        self.in_data(Glob("?o*"), 5, "World")
        self.in_data(Glob("*d"), 5, "World")

        self.in_data(Glob(""), 11, "")

        self.not_in_data(Glob("hello"))
        self.not_in_data(Glob("ll"))
        self.not_in_data(Glob("o"))
        self.not_in_data(Glob("1"))
        self.not_in_data(Glob("()"))
        self.not_in_data(Glob("[]"))
        self.not_in_data(Glob("None"))