Skip to content

Commit

Permalink
Implement and document properties function (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtv8 authored Mar 12, 2021
1 parent 9d98b86 commit 10aecec
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/source/user_docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ for code readability.
.. autofunction:: wysdom.schema


Other convenience functions
---------------------------

.. autofunction:: wysdom.properties


Mixins
======

Expand Down
1 change: 1 addition & 0 deletions features/dict.feature
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Feature: Test dictionary DOM objects
example_dict_output == example_dict_input
copy.copy(example).to_builtin() == example_dict_input
copy.deepcopy(example).to_builtin() == example_dict_input
set(properties(example).keys()) == {"first_name", "last_name", "current_address", "previous_addresses", "vehicles"}
"""
And the list walk_elements contains the following tuples:
| element | document | parent | element_key |
Expand Down
2 changes: 1 addition & 1 deletion features/steps/steps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from behave import *

import wysdom
from wysdom import document, parent, key, schema
from wysdom import document, parent, key, schema, properties

import os
import importlib.util
Expand Down
2 changes: 1 addition & 1 deletion wysdom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
from . import dom
from .base_schema import Schema, SchemaType, SchemaNone, SchemaPrimitive, SchemaAnything, SchemaConst
from .object_schema import SchemaArray, SchemaDict, SchemaAnyOf, SchemaObject
from .user_objects import UserProperty, UserObject
from .user_objects import UserProperty, UserObject, properties
from .mixins import ReadsJSON, ReadsYAML, RegistersSubclasses

1 change: 1 addition & 0 deletions wysdom/user_objects/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .UserObject import UserObject, UserProperties
from .UserProperty import UserProperty
from .functions import properties
15 changes: 15 additions & 0 deletions wysdom/user_objects/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Dict

from ..base_schema import Schema
from .UserObject import UserObject


def properties(user_object: UserObject) -> Dict[str, Schema]:
"""
Retrieve the property names and their associated :class:`~wysdom.base_schema.Schema`
objects for a particular `:class:`~wysdom.user_objects.UserObject.
:param user_object: A `:class:`~wysdom.user_objects.UserObject
:return: A dictionary mapping property names to their :class:`~wysdom.base_schema.Schema`
"""
return user_object.__json_schema_properties__.properties

0 comments on commit 10aecec

Please sign in to comment.