Exemplo n.º 1
0
    def test_pop_values(self):
        """Test that we can pop values from the record."""

        record = Record(['name', 'drink', 'city'],
                        ['David', 'Coffee', 'Hamburg'])

        self.assertEqual(record.pop('drink'), 'Coffee')
        self.assertEqual(record.keys(), ['name', 'city'])
        self.assertEqual(record.values(), ['David', 'Hamburg'])

        self.assertEqual(record.pop('not existing'), None)
Exemplo n.º 2
0
    def test_key_access(self):
        """Test that Record keys and values can be accessed."""
        assert_name = 'David'
        assert_drink = 'Coffee'

        record = Record(['name', 'drink'], [assert_name, assert_drink])

        self.assertEqual(record.keys(), ['name', 'drink'])
        self.assertEqual(record.values(), [assert_name, assert_drink])
        
        self.assertEqual(record.name, assert_name)
        self.assertEqual(record['name'], assert_name)

        self.assertEqual(record.drink, assert_drink)
        self.assertEqual(record['drink'], assert_drink)

        with self.assertRaises(KeyError):
            record['city']

        with self.assertRaises(AttributeError):
            record.city