コード例 #1
0
ファイル: test_record.py プロジェクト: jasonbot/normalize
    def test_false_emptiness(self):
        """Test that Properties with falsy empty values don't throw exceptions"""
        class SophiesRecord(Record):
            placeholder = Property()
            aux_placeholder = Property(empty='')
            age = Property(empty=0)
            name = Property(empty=None)

        sophie = SophiesRecord()
        with self.assertRaises(AttributeError):
            sophie.placeholder
        with self.assertRaises(AttributeError):
            sophie.aux_placeholder

        self.assertFalse(sophie.aux_placeholder0)
        self.assertFalse(sophie.age0)
        self.assertFalse(sophie.name0)
        self.assertFalse(sophie.placeholder0)

        # the properties aren't really set...
        self.assertEqual(VisitorPattern.visit(sophie), {})

        sophie.age = 1
        self.assertEqual(VisitorPattern.visit(sophie), {"age": 1})

        sophie.age = 0
        self.assertEqual(VisitorPattern.visit(sophie), {"age": 0})

        del sophie.age
        self.assertEqual(VisitorPattern.visit(sophie), {})
コード例 #2
0
    def test_false_emptiness(self):
        """Test that Properties with falsy empty values don't throw exceptions"""

        class SophiesRecord(Record):
            placeholder = Property()
            aux_placeholder = Property(empty='')
            age = Property(empty=0)
            name = Property(empty=None)

        sophie = SophiesRecord()
        with self.assertRaises(AttributeError):
            sophie.placeholder
        with self.assertRaises(AttributeError):
            sophie.aux_placeholder

        self.assertFalse(sophie.aux_placeholder0)
        self.assertFalse(sophie.age0)
        self.assertFalse(sophie.name0)
        self.assertFalse(sophie.placeholder0)

        # the properties aren't really set...
        self.assertEqual(VisitorPattern.visit(sophie), {})

        sophie.age = 1
        self.assertEqual(VisitorPattern.visit(sophie), {"age": 1})

        sophie.age = 0
        self.assertEqual(VisitorPattern.visit(sophie), {"age": 0})

        del sophie.age
        self.assertEqual(VisitorPattern.visit(sophie), {})
コード例 #3
0
    def test_cast_collection(self):
        RecordList = list_of(Record)
        casted = VisitorPattern.cast(RecordList, [{}, {}])
        self.assertIsInstance(casted[0], Record)
        self.assertIsInstance(casted, RecordList)

        empty_casted = VisitorPattern.cast(RecordList, [])
        self.assertIsInstance(empty_casted, RecordList)
コード例 #4
0
ファイル: test_visitor.py プロジェクト: mattrowe/normalize
    def test_cast_collection(self):
        RecordList = list_of(Record)
        casted = VisitorPattern.cast(RecordList, [{}, {}])
        self.assertIsInstance(casted[0], Record)
        self.assertIsInstance(casted, RecordList)

        empty_casted = VisitorPattern.cast(RecordList, [])
        self.assertIsInstance(empty_casted, RecordList)
コード例 #5
0
ファイル: test_record.py プロジェクト: hearsaycorp/normalize
    def test_false_emptiness(self):
        """Test that Properties with falsy empty values don't throw
        exceptions"""

        class SophiesRecord(Record):
            placeholder = Property()
            aux_placeholder = Property(default='')
            age = Property(default=0)
            name = V1Property(isa=basestring)

        sophie = SophiesRecord()
        with self.assertRaises(AttributeError):
            sophie.placeholder
        self.assertFalse(sophie.placeholder0)

        self.assertEqual(sophie.aux_placeholder, '')
        self.assertFalse(sophie.aux_placeholder0)

        self.assertEqual(sophie.age, 0)
        self.assertFalse(sophie.age0)

        self.assertEqual(sophie.name, None)
        with self.assertRaises(AttributeError):
            sophie.name0
        sophie.name = "Sophie"
        self.assertEqual(sophie.name, "Sophie")
        sophie.name = None
        self.assertEqual(sophie.name, None)

        # the properties aren't really set, but VisitorPattern sees them.
        expected = {"age": 0, "aux_placeholder": ""}
        self.assertEqual(VisitorPattern.visit(sophie), expected)

        sophie.age = 1
        expected['age'] = 1
        self.assertEqual(VisitorPattern.visit(sophie), expected)

        sophie.age = 0
        expected['age'] = 0
        self.assertEqual(VisitorPattern.visit(sophie), expected)

        del sophie.age
        self.assertEqual(VisitorPattern.visit(sophie), expected)
コード例 #6
0
ファイル: test_record.py プロジェクト: saraducks/normalize
    def test_false_emptiness(self):
        """Test that Properties with falsy empty values don't throw
        exceptions"""

        class SophiesRecord(Record):
            placeholder = Property()
            aux_placeholder = Property(default='')
            age = Property(default=0)
            name = V1Property(isa=basestring)

        sophie = SophiesRecord()
        with self.assertRaises(AttributeError):
            sophie.placeholder
        self.assertFalse(sophie.placeholder0)

        self.assertEqual(sophie.aux_placeholder, '')
        self.assertFalse(sophie.aux_placeholder0)

        self.assertEqual(sophie.age, 0)
        self.assertFalse(sophie.age0)

        self.assertEqual(sophie.name, None)
        with self.assertRaises(AttributeError):
            sophie.name0
        sophie.name = "Sophie"
        self.assertEqual(sophie.name, "Sophie")
        sophie.name = None
        self.assertEqual(sophie.name, None)

        # the properties aren't really set, but VisitorPattern sees them.
        expected = {"age": 0, "aux_placeholder": ""}
        self.assertEqual(VisitorPattern.visit(sophie), expected)

        sophie.age = 1
        expected['age'] = 1
        self.assertEqual(VisitorPattern.visit(sophie), expected)

        sophie.age = 0
        expected['age'] = 0
        self.assertEqual(VisitorPattern.visit(sophie), expected)

        del sophie.age
        self.assertEqual(VisitorPattern.visit(sophie), expected)