Beispiel #1
0
    def test_traverse_changed(self):
        calls = []
        op = (lambda dt: calls.append(dt) or Field(dt.name, str))
        fields = Fields(
            Field('spam', ANY),
            Field('eggs', None),
        )
        transformed = fields.traverse(op)

        self.assertIsNot(transformed, fields)
        self.assertEqual(transformed,
                         Fields(
                             Field('spam', str),
                             Field('eggs', str),
                         ))
        self.assertEqual(calls, [
            Field('spam', ANY),
            Field('eggs', None),
        ])
Beispiel #2
0
    def test_traverse_noop(self):
        calls = []
        op = (lambda dt: calls.append(dt) or dt)
        fields = Fields(
            Field('spam'),
            Field('ham'),
            Field('eggs'),
        )
        transformed = fields.traverse(op)

        self.assertIs(transformed, fields)
        self.assertCountEqual(
            calls,
            [
                # Note that it did not recurse into the fields.
                Field('spam'),
                Field('ham'),
                Field('eggs'),
            ])