コード例 #1
0
    def test_wrapping_resource_attrs(self):
        r = FixedAttrsDict(MagicMock(), properties={})
        to_wrap = FixedAttrsDict(MagicMock(), properties={})
        ret = r._wrap_resource_attr(AgentConfig, to_wrap)
        self.assertEqual(to_wrap, ret)

        ret = r._wrap_resource_attr(AgentConfig, {'poll_interval': 60})
        self.assertEqual(60, ret.poll_interval)
        self.assertTrue(isinstance(ret, AgentConfig))

        ret = r._wrap_resource_attr(AgentConfig, None)
        self.assertIsNone(ret)

        self.assertRaises(TypeError, r._wrap_resource_attr, AgentConfig,
                          'Unsupported Conversion')
コード例 #2
0
    def test_fad_init(self):
        fad = FixedAttrsDict(MagicMock(), properties={'a': 1, 'b': 2})

        # getting a non-existing attribute is handled correctly
        with self.assertRaises(AttributeError):
            fad.a = 2
        # non-existing attribute access is handled correctly
        with self.assertRaises(AttributeError):
            fad.foo
コード例 #3
0
    def test_fad_dir_method(self):
        fad = FixedAttrsDict(MagicMock(),
                             properties={
                                 'href': 1,
                                 '_some_property': 2,
                                 'some_property': 3
                             })

        self.assertEqual({'href', '_some_property', 'some_property'},
                         set(fad.__dir__()))
コード例 #4
0
    def test_getting_fad_property_names(self):
        fad = FixedAttrsDict(MagicMock(),
                             properties={
                                 'href': 1,
                                 '_some_property': 2,
                                 'some_property': 3
                             })

        self.assertEqual(set(fad.__dict__.keys()),
                         {'href', '_some_property', 'some_property'})