Example #1
0
    def __init__(self, filter):
        self.filter_str = filter

        if not Str.contains(filter, ':'):
            self.filter_name = filter
        else:
            m = Filter.PARSE_REGEX.match(filter)
            if m:
                self.filter_name = m.group('filter')
                self.filter_param = m.group('param')
            else:
                raise ValueError('Invalid filter "%s"' % filter)
Example #2
0
        # all test
        self.assertTrue(Lst.any([1, 2, 3], lambda x: x == 1))
        self.assertFalse(Lst.any([1, 2, 3], lambda x: x == 7))

        self.assertTrue(Lst.all([2, 4, 8], lambda x: x % 2 == 0))
        self.assertFalse(Lst.all([2, 5, 8], lambda x: x % 2 == 0))


class StrTest(SimpleTestCase):
    def test_str(self):
        self.assertEqual(Str.casefold('ViỆt Nam'), Str.casefold('việt nam'))

        self.assertTrue(Str.eq('a', 'A'))
        self.assertFalse(Str.eq('a', 'A', case=True))

        self.assertTrue(Str.contains("Hello", "hell"))
        self.assertFalse(Str.contains("Hello", "hell", case=True))

        # base64
        plain_str = 'hello world!'
        b64 = 'aGVsbG8gd29ybGQh'
        self.assertEqual(Str.base64_encode(plain_str), b64)
        self.assertEqual(Str.base64_decode(b64), plain_str)
        plain_str = 'this is a test'
        b64 = 'dGhpcyBpcyBhIHRlc3Q='
        self.assertEqual(Str.base64_encode(plain_str), b64)
        self.assertEqual(Str.base64_decode(b64), plain_str)

        # is_int()
        self.assertTrue(Str.is_int('0'))
        self.assertTrue(Str.is_int('1'))