Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #968 from tefra/move-validator
feat: Move analyzer validations to handler
- Loading branch information
Showing
12 changed files
with
208 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from xsdata.codegen.container import ClassContainer | ||
from xsdata.codegen.handlers import ValidateReferences | ||
from xsdata.exceptions import AnalyzerValueError | ||
from xsdata.models.config import ( | ||
GeneratorConfig, | ||
) | ||
from xsdata.utils.testing import ( | ||
AttrFactory, | ||
AttrTypeFactory, | ||
ClassFactory, | ||
ExtensionFactory, | ||
FactoryTestCase, | ||
) | ||
|
||
|
||
class ValidateReferencesTests(FactoryTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.config = GeneratorConfig() | ||
self.container = ClassContainer(config=self.config) | ||
self.handler = ValidateReferences(container=self.container) | ||
|
||
def test_validate_unique_qualified_names(self): | ||
first = ClassFactory.create() | ||
second = first.clone() | ||
self.container.extend([first, second]) | ||
|
||
with self.assertRaises(AnalyzerValueError) as cm: | ||
self.handler.run() | ||
|
||
self.assertEqual("Duplicate types found", str(cm.exception)) | ||
|
||
def test_validate_unique_instances(self): | ||
first = ClassFactory.create() | ||
first.extensions.append(ExtensionFactory.create()) | ||
second = ClassFactory.create() | ||
second.extensions = first.extensions | ||
self.container.extend([first, second]) | ||
|
||
with self.assertRaises(AnalyzerValueError) as cm: | ||
self.handler.run() | ||
|
||
self.assertEqual("Cross reference detected", str(cm.exception)) | ||
|
||
def test_validate_unresolved_references(self): | ||
first = ClassFactory.create() | ||
first.attrs.append(AttrFactory.create()) | ||
first.attrs.append(AttrFactory.reference("foo")) | ||
self.container.add(first) | ||
|
||
with self.assertRaises(AnalyzerValueError) as cm: | ||
self.handler.run() | ||
|
||
self.assertEqual("Unresolved reference detected", str(cm.exception)) | ||
|
||
def test_validate_misrepresented_references(self): | ||
first = ClassFactory.create() | ||
inner = ClassFactory.create() | ||
first.inner.append(inner) | ||
first.attrs.append( | ||
AttrFactory.create( | ||
types=[AttrTypeFactory.create(qname="foo", reference=inner.ref)] | ||
) | ||
) | ||
self.container.add(first) | ||
|
||
with self.assertRaises(AnalyzerValueError) as cm: | ||
self.handler.run() | ||
|
||
self.assertEqual("Misrepresented reference", str(cm.exception)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.