コード例 #1
0
ファイル: complex_test.py プロジェクト: zhangyi733/filters
    def test_chainception(self):
        """
        You can also chain FilterChains together.
        """
        fc1 = f.NotEmpty | f.Choice(choices=('Lucky', 'Dusty', 'Ned'))
        fc2 = f.NotEmpty | f.MinLength(4)

        self.filter_type = lambda: fc1 | fc2

        self.assertFilterPasses('Lucky')
        self.assertFilterErrors('El Guapo', [f.Choice.CODE_INVALID])
        self.assertFilterErrors('Ned', [f.MinLength.CODE_TOO_SHORT])
コード例 #2
0
ファイル: complex_test.py プロジェクト: zhangyi733/filters
    def test_stop_after_invalid_value(self):
        """
        A FilterChain stops processing the incoming value after any
        filter fails.
        """
        # This FilterChain will pretty much reject anything that you
        # throw at it.
        self.filter_type =\
            lambda: f.MaxLength(3) | f.MinLength(8) | f.Required

        # Note that the value 'foobar' fails both the MaxLength and the
        # MinLength filters, but the FilterChain stops processing
        # after MaxLength fails.
        self.assertFilterErrors('foobar', [f.MaxLength.CODE_TOO_LONG])
コード例 #3
0
ファイル: macros_test.py プロジェクト: mkatenhusen/filters
 def Filter2():
     return f.Split(r'\s+') | f.MinLength(2)
コード例 #4
0
ファイル: macros_test.py プロジェクト: mkatenhusen/filters
 def MyFilter(min_length=12):
     return f.Unicode | f.MinLength(min_length)
コード例 #5
0
ファイル: macros_test.py プロジェクト: mkatenhusen/filters
 def MyFilter():
     return f.Unicode | f.Strip | f.MinLength(12)