Skip to content
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

Feature/python3 #12

Merged
merged 53 commits into from Dec 11, 2018
Merged

Feature/python3 #12

merged 53 commits into from Dec 11, 2018

Conversation

AkhilGNair
Copy link

@AkhilGNair AkhilGNair commented Nov 30, 2018

Hi! Thanks for the package.

This PR is to generate Python classes from JSON schema with type hinting + a marshmallow schema class to enable serialisation + deserialisation.

I haven't yet added all the tests, and will likely not add functionality for all json schema features (for now). The PR is a bit premature, sorry about that.

@expobrain
Copy link
Owner

Hi @AkhilGNair,

thank you very much for your PR, I'll have a look at it soon!

In the meanwhile can I ask you if you can add some kind of notification like rising a NotImplementedError for the feature of JSON-schema which you are not implementing?

@AkhilGNair
Copy link
Author

Hi - yup I will. Going to slowly add more tests to make sure I catch all the NotImplementeds.

Thanks!

@AkhilGNair
Copy link
Author

Hi @expobrain - The tests for the cases I'm implemented pass. There are a couple of cases that still fail, mainly around arrays of aliases, but they raise a NotImplementedException. I'm not sure how to best edit the test case here to show this is expected.

Thanks!

@expobrain
Copy link
Owner

Hi @AkhilGNair,

thank you for all your amazing work!

I'll have a look today, I'll find a solution for the raised NotImplementedException so the unit test will be happy :-)

@expobrain
Copy link
Owner

@AkhilGNair what about something like this:

diff --git a/tests/generator_python3_test.py b/tests/generator_python3_test.py
index 5c60de3..9b1fc0f 100644
--- a/tests/generator_python3_test.py
+++ b/tests/generator_python3_test.py
@@ -1,4 +1,5 @@
 import ast
+import warnings

 from pathlib2 import Path
 import pytest
@@ -28,7 +29,12 @@ def test_generate(schema_filename):
     fixture_filename = FIXTURES_DIR / (schema_filename.name.split(".")[0] + ".py")

     schema = load_schema(schema_filename.read_text())
-    fixture = astor.parse_file(str(fixture_filename))
+
+    try:
+        fixture = astor.parse_file(str(fixture_filename))
+    except FileNotFoundError as e:
+        warnings.warn(f"Fixture not implemented yet {fixture_filename}")
+        return

     generator = Python3Generator(schema)
     result = generator.generate().as_ast()

so the test will pass but leaving a nice warning about it?

It's a temporary solution until I'll implement the generation for those cases.

@AkhilGNair
Copy link
Author

Ah that works nicely! Thank you so much :)

@expobrain expobrain merged commit 803f489 into expobrain:master Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants