Example #1
0
    def test_property_has_wild_attr(self):
        obj = ClassFactory.create()
        self.assertFalse(obj.has_wild_attr)

        obj.attrs.append(AttrFactory.create())
        obj.attrs.append(AttrFactory.create())
        self.assertFalse(obj.has_wild_attr)

        obj.attrs.append(AttrFactory.any())
        self.assertTrue(obj.has_wild_attr)
Example #2
0
    def test_process(self, mock_create_substitutions, mock_process_attribute):
        def init_substitutions():
            self.processor.substitutions = {}

        mock_create_substitutions.side_effect = init_substitutions

        target = ClassFactory.create(
            attrs=[AttrFactory.enumeration(), AttrFactory.any(), AttrFactory.element(),]
        )

        self.processor.process(target)
        self.processor.process(ClassFactory.create())
        mock_process_attribute.assert_called_once_with(target, target.attrs[2])
        mock_create_substitutions.assert_called_once()
Example #3
0
    def test_field_choices(self):
        attr = AttrFactory.create(
            choices=[
                AttrFactory.element(
                    namespace="foo",
                    types=[type_float],
                    restrictions=Restrictions(max_exclusive="10"),
                ),
                AttrFactory.element(namespace="bar"),
                AttrFactory.any(namespace="##other"),
                AttrFactory.element(name="bar", default="aa"),
                AttrFactory.element(name="tok", restrictions=Restrictions(tokens=True)),
            ]
        )

        actual = self.filters.field_choices(attr, "foo", ["a", "b"])
        expected = [
            {"name": "attr_B", "type": "Type[float]", "max_exclusive": 10.0},
            {"name": "attr_C", "namespace": "bar", "type": "Type[str]"},
            {
                "name": "attr_D",
                "namespace": "##other",
                "wildcard": True,
                "type": "Type[object]",
            },
            {"default": '"aa"', "name": "bar", "type": "Type[str]"},
            {
                "default_factory": "list",
                "name": "tok",
                "tokens": True,
                "type": "Type[List[str]]",
            },
        ]

        self.assertEqual(expected, actual)

        self.filters.docstring_style = DocstringStyle.ACCESSIBLE
        attr.choices[0].help = "help"
        actual = self.filters.field_choices(attr, None, [])
        self.assertEqual(attr.choices[0].help, actual[0]["doc"])
        self.assertNotIn("doc", actual[1])
Example #4
0
    def test_property_is_wild_attr(self):
        attr = AttrFactory.create()
        self.assertFalse(attr.is_wildcard)

        attr = AttrFactory.any()
        self.assertTrue(attr.is_wildcard)