-
Notifications
You must be signed in to change notification settings - Fork 33
feat: xblock skill verification event #165
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
b0b6f07
6c6d3f1
b9b80eb
6b6b646
58b1f18
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 |
|---|---|---|
|
|
@@ -5,4 +5,4 @@ | |
| more information about the project. | ||
| """ | ||
|
|
||
| __version__ = "5.0.0" | ||
| __version__ = "5.1.0" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| """Tests for avro.deserializer""" | ||
|
mariajgrimaldi marked this conversation as resolved.
|
||
| import json | ||
| from datetime import datetime | ||
| from typing import List | ||
| from unittest import TestCase | ||
|
|
||
| from opaque_keys.edx.keys import CourseKey, UsageKey | ||
|
|
@@ -175,3 +176,60 @@ def test_deserialization_of_nested_optional_fields(self): | |
| nested_field = data_dict["data"].field_0 | ||
| self.assertIsInstance(nested_field, SimpleAttrsWithDefaults) | ||
| self.assertEqual(nested_field, SimpleAttrsWithDefaults()) | ||
|
|
||
| def test_deserialization_of_list_with_annotation(self): | ||
| """ | ||
| Check that deserialization works as expected when list data is annotated. | ||
| """ | ||
| LIST_SIGNAL = create_simple_signal({"list_input": List[int]}) | ||
| initial_dict = {"list_input": [1, 3]} | ||
| deserializer = AvroSignalDeserializer(LIST_SIGNAL) | ||
| event_data = deserializer.from_dict(initial_dict) | ||
| expected_event_data = [1, 3] | ||
| test_data = event_data["list_input"] | ||
| self.assertIsInstance(test_data, list) | ||
| self.assertEqual(test_data, expected_event_data) | ||
|
|
||
| def test_deserialization_of_list_without_annotation(self): | ||
| """ | ||
| Check that deserialization raises error when list data is not annotated. | ||
| """ | ||
| # create dummy signal to bypass schema check while initializing deserializer | ||
| # This allows us to test whether correct exceptions are raised while deserializing data | ||
| SIGNAL = create_simple_signal({"list_input": List[int]}) | ||
|
rgraber marked this conversation as resolved.
|
||
| LIST_SIGNAL = create_simple_signal({"list_input": List}) | ||
| initial_dict = {"list_input": [1, 3]} | ||
| deserializer = AvroSignalDeserializer(SIGNAL) | ||
| # Update signal with incomplete type info | ||
| deserializer.signal = LIST_SIGNAL | ||
| with self.assertRaises(TypeError): | ||
| deserializer.from_dict(initial_dict) | ||
|
|
||
| def test_deserialization_of_nested_list_fails(self): | ||
| """ | ||
| Check that deserialization raises error when nested list data is passed. | ||
| """ | ||
| # create dummy signal to bypass schema check while initializing deserializer | ||
| # This allows us to test whether correct exceptions are raised while deserializing data | ||
| SIGNAL = create_simple_signal({"list_input": List[int]}) | ||
| LIST_SIGNAL = create_simple_signal({"list_input": List[List[int]]}) | ||
| initial_dict = {"list_input": [[1, 3], [4, 5]]} | ||
| deserializer = AvroSignalDeserializer(SIGNAL) | ||
| # Update signal with incomplete type info | ||
| deserializer.signal = LIST_SIGNAL | ||
| with self.assertRaises(TypeError): | ||
| deserializer.from_dict(initial_dict) | ||
|
Comment on lines
+220
to
+221
Member
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. why should this fail?
Contributor
Author
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. Handling nested lists (with annotation) support again introduces complexity and I did not implement it as it is not required as of now. If we remove inner list type annotation, i.e. change the type to def test_deserialization_of_nested_list_works(self):
SIGNAL = create_simple_signal({"list_input": List[list]})
initial_dict = {"list_input": [[1, 3], [4, 5]]}
deserializer = AvroSignalDeserializer(SIGNAL)
data = deserializer.from_dict(initial_dict)
self.assertEqual(data, initial_dict)
Contributor
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. Do we want List[list] to work? Doesn't that open us up to issues with something like
Contributor
Author
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. @rgraber Good point! I have updated it to allow only simple types like int, str, bool etc. |
||
|
|
||
| def test_deserialization_of_nested_list_with_complex_types_fails(self): | ||
| SIGNAL = create_simple_signal({"list_input": List[list]}) | ||
| with self.assertRaises(TypeError): | ||
| AvroSignalDeserializer(SIGNAL) | ||
| initial_dict = {"list_input": [[1, 3], [4, 5]]} | ||
| # create dummy signal to bypass schema check while initializing deserializer | ||
| # This allows us to test whether correct exceptions are raised while deserializing data | ||
| DUMMY_SIGNAL = create_simple_signal({"list_input": List[int]}) | ||
| deserializer = AvroSignalDeserializer(DUMMY_SIGNAL) | ||
| # Update signal with incorrect type info | ||
| deserializer.signal = SIGNAL | ||
| with self.assertRaises(TypeError): | ||
| deserializer.from_dict(initial_dict) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| """A mapping of python types to the Avro type that we want to use make valid avro schema.""" | ||
| PYTHON_TYPE_TO_AVRO_MAPPING = { | ||
| None: "null", | ||
| SIMPLE_PYTHON_TYPE_TO_AVRO_MAPPING = { | ||
| bool: "boolean", | ||
| int: "long", | ||
| float: "double", | ||
| bytes: "bytes", | ||
| str: "string", | ||
| } | ||
| PYTHON_TYPE_TO_AVRO_MAPPING = { | ||
| **SIMPLE_PYTHON_TYPE_TO_AVRO_MAPPING, | ||
| None: "null", | ||
| dict: "record", | ||
| list: "array", | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.