-
Notifications
You must be signed in to change notification settings - Fork 7
Fix loader correctness and global side-effects from PR #103 review #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |||||||||||||||||||||||||||||||||||||||||
| from unittest import TestCase | ||||||||||||||||||||||||||||||||||||||||||
| from unittest.mock import patch, mock_open | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import yaml as yaml_lib | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| from _loaders.file_test import OPEN, PATH_EXISTS, PATH_ISFILE | ||||||||||||||||||||||||||||||||||||||||||
| from pystreamapi.loaders import yaml | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -62,6 +64,11 @@ def test_yaml_loader_is_lazy(self): | |||||||||||||||||||||||||||||||||||||||||
| data = yaml(file_path) | ||||||||||||||||||||||||||||||||||||||||||
| self.assertIsInstance(data, GeneratorType) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def test_yaml_loader_with_malformed_yaml(self): | ||||||||||||||||||||||||||||||||||||||||||
| malformed_yaml = "key: : invalid" | ||||||||||||||||||||||||||||||||||||||||||
| with self.assertRaises(yaml_lib.YAMLError): | ||||||||||||||||||||||||||||||||||||||||||
| list(yaml(malformed_yaml, read_from_src=True)) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def _check_extracted_data(self, data): | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+67
to
72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Extend malformed YAML coverage to the file-based loader path You’ve covered the
This will verify that both string and file inputs fail the same way for invalid YAML.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| first = next(data) | ||||||||||||||||||||||||||||||||||||||||||
| self.assertEqual(first.attr1, 1) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Consider adding tests for XML loader when using
read_from_src=Truewith different flag combinationsWith the refactor removing the global
configand threading flags through the call chain, theread_from_src=Truepath (_lazy_parse_xml_string) should be covered similarly to the file-path loader.Could you add tests that:
xml(xml_string, read_from_src=True)withretrieve_childrenset to bothTrueandFalse, checking the parsed data shape matches the existing file-based tests.xml(xml_string, read_from_src=True, cast_types=False)and assert numeric/boolean-like values remain strings, mirroringtest_xml_loader_no_casting.You can reuse the existing
file_contentXML string so both entry points (file_pathandread_from_src) stay aligned without much extra test code.Suggested implementation:
These changes assume:
xmlloader already acceptsread_from_srcandretrieve_childrenkeyword arguments, matching the refactor you mentioned.file_contentis the XML string used in other tests in this module, andfile_path/mock_xml_fileare available helpers as shown.If there are existing dedicated tests for
retrieve_children=True/Falsewith the file-path loader earlier in this file, these new tests now assert that theread_from_src=Truepath produces identical output to the file-based path for the same flags, without needing to duplicate structure-specific assertions.