-
Notifications
You must be signed in to change notification settings - Fork 47
Added unit tests #61
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
Merged
Merged
Added unit tests #61
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f779a2c
Added unit tests to the Python Client API
antaresc 7fbe1f2
Remove commented code
antaresc 70fce13
Added requests to requirements
antaresc e3af07d
Added line to Dockerfile
antaresc 5897a58
Updated fields to match new mixer version.
antaresc 2b66e1e
Added comments and added in PY2 support imports.
antaresc 0a49e75
Clarified comment in get_populations
antaresc cd98d2a
Clarified triple.
antaresc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -32,7 +32,9 @@ | |
|
|
||
|
|
||
| def get_property_labels(dcids, out=True): | ||
| """ Returns a map from given dcids to a list of defined properties defined. | ||
| """ Returns the labels of properties defined for the given dcids. | ||
|
|
||
| The return value is a dictionary mapping dcids to lists of property labels. | ||
|
|
||
| Args: | ||
| dcids: A list of nodes identified by their dcids. | ||
|
|
@@ -47,9 +49,9 @@ def get_property_labels(dcids, out=True): | |
| results = {} | ||
| for dcid in dcids: | ||
| if out: | ||
| results[dcid] = payload[dcid]['outArcs'] | ||
| results[dcid] = payload[dcid]['outLabels'] | ||
| else: | ||
| results[dcid] = payload[dcid]['inArcs'] | ||
| results[dcid] = payload[dcid]['inLabels'] | ||
| return results | ||
|
|
||
|
|
||
|
|
@@ -95,33 +97,36 @@ def get_property_values(dcids, | |
| payload = utils._format_response(res) | ||
|
|
||
| # Create the result format for when dcids is provided as a list. | ||
| result = defaultdict(list) | ||
| results = defaultdict(list) | ||
| for dcid in dcids: | ||
| # Make sure each dcid is mapped to an empty list. | ||
| results[dcid] | ||
|
|
||
| # Add elements to this list as necessary. | ||
| if dcid in payload and prop in payload[dcid]: | ||
| for node in payload[dcid][prop]: | ||
| if 'dcid' in node: | ||
| result[dcid].append(node['dcid']) | ||
| results[dcid].append(node['dcid']) | ||
| elif 'value' in node: | ||
| result[dcid].append(node['value']) | ||
| else: | ||
| result[dcid] = [] | ||
| results[dcid].append(node['value']) | ||
|
|
||
| # Format the result as a Series if a Pandas Series is provided. | ||
| # Format the results as a Series if a Pandas Series is provided. | ||
| if isinstance(dcids, pd.Series): | ||
| return pd.Series([result[dcid] for dcid in dcids]) | ||
| return dict(result) | ||
| return pd.Series([results[dcid] for dcid in dcids]) | ||
| return dict(results) | ||
|
|
||
|
|
||
| def get_triples(dcids, limit=utils._MAX_LIMIT): | ||
| """ Returns a list of triples where the dcid is either a subject or object. | ||
| """ Returns all triples associated with the given dcids. | ||
|
|
||
| The return value is a list of tuples (s, p, o) where s denotes the subject | ||
| entity, p the property, and o the object. | ||
| The return value is a dictionary mapping given dcids to list of triples. The | ||
| triples are repsented as 3-tuples (s, p, o) where "s" denotes the subject, "p" | ||
| the property, and "o" the object. | ||
|
|
||
| Args: | ||
| dcid: A list of dcids to get triples for. | ||
| dcids: A list of dcids to get triples for. | ||
| limit: The maximum number of triples to get for each combination of property | ||
|
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. can say property label to be more clear
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. Will clarify with a section on what a triple is. |
||
| and type of the neighboring node. | ||
| and type of property value. | ||
| """ | ||
| # Generate the GetTriple query and send the request. | ||
| url = utils._API_ROOT + utils._API_ENDPOINTS['get_triples'] | ||
|
|
@@ -131,6 +136,10 @@ def get_triples(dcids, limit=utils._MAX_LIMIT): | |
| # Create a map from dcid to list of triples. | ||
| results = defaultdict(list) | ||
| for dcid in dcids: | ||
| # Make sure each dcid is mapped to an empty list. | ||
| results[dcid] | ||
|
|
||
| # Add triples as appropriate | ||
| for t in payload[dcid]: | ||
| if 'objectId' in t: | ||
| results[dcid].append( | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
no matter how I refresh, I still see this as deleted. will come back to it but can you check that this was put back?
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.
Added back