-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding unit tests for the manager as well as a GH workflow. * Adding unit tests for the common magics. * adding networkx into dependencies * Changing the issue templates * Joining docker run operations together * Update README.md
- Loading branch information
Showing
16 changed files
with
461 additions
and
28 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: Bug | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior: | ||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Screenshots** | ||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Desktop (please complete the following information):** | ||
- OS: [e.g. iOS] | ||
- Browser [e.g. chrome, safari] | ||
- Version [e.g. 22] | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
title: '' | ||
labels: Feature request | ||
assignees: kiddinn, bladyjoker, mariuszlitwin | ||
|
||
--- | ||
|
||
**Describe the problem statement you are attempting to solve. Is the feature request related to | ||
a problem? Please describe.** | ||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
|
||
**Describe the solution you'd like** | ||
A clear and concise description of what you want to happen. | ||
|
||
**Describe alternatives you've considered** | ||
A clear and concise description of any alternative solutions or features you've considered. | ||
|
||
**Additional context** | ||
Add any other context or screenshots about the feature request here. |
This file contains 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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
Fixes #<issue_number_goes_here> | ||
This PR fixes #<issue_number_goes_here> | ||
|
||
> It's a good idea to open an issue first for discussion. | ||
> Describe in a sentence or few what the PR accomplishes. | ||
- [ ] Tests pass | ||
- [ ] Appropriate changes to README are included in PR | ||
- [ ] Unit tests added | ||
- [ ] End-to-end tests added | ||
- [ ] Appropriate changes to documentation is included | ||
- [ ] If additional dependencies are needed, are they added into dependency files. |
This file contains 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: pipenv unittests | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] | ||
python-version: [3.7, 3.8] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
pip install pipenv | ||
pipenv install -d | ||
pipenv install -r test_requirements.txt | ||
- name: Test with pytest | ||
run: | | ||
pipenv run pytest |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Tests for the picatrix framework.""" | ||
from typing import Optional | ||
from typing import Text | ||
|
||
from picatrix.lib import framework | ||
from picatrix.lib import manager | ||
|
||
|
||
def my_very_own_test_magic(data: Text, stuff: Optional[int] = 20) -> Text: | ||
"""This is a magic that is used for testing. | ||
Args: | ||
data (str): This is a string. | ||
stuff (int): And this is a number. | ||
Returns: | ||
str: A string that combines the two parameters together. | ||
""" | ||
return f'{data.strip()} - {stuff}' | ||
|
||
|
||
def test_registration(): | ||
"""Test the magic decorator.""" | ||
magic = framework.picatrix_magic(my_very_own_test_magic) | ||
assert magic.__doc__.startswith('usage: %my_very_own_test_magic') | ||
results = magic(line='--stuff 23 this is a text') | ||
assert results == 'this is a text - 23' | ||
|
||
manager.MagicManager.deregister_magic(magic.magic_name) |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Tests for the pixatrix manager.""" | ||
import pytest | ||
import mock | ||
|
||
from picatrix.lib import manager | ||
from picatrix.lib import utils | ||
|
||
|
||
manager.get_ipython = mock.MagicMock() | ||
utils.get_ipython = mock.MagicMock() | ||
|
||
|
||
def test_registration(): | ||
"""Test registering a magic and getting a copy of it and de-registering.""" | ||
manager.MagicManager.clear_magics() | ||
|
||
def my_magic(cell=None, line=None): | ||
"""This is a magic.""" | ||
if not cell: | ||
cell = 'foo' | ||
if not line: | ||
line = 'bar' | ||
return f'{cell}{line}' | ||
|
||
my_magic.magic_name = 'magical_function' | ||
my_magic.fn = my_magic | ||
manager.MagicManager.register_magic(my_magic) | ||
|
||
magic_from_manager = manager.MagicManager.get_magic('magical_function') | ||
assert magic_from_manager() == 'foobar' | ||
|
||
my_magic.magic_name = 'other_magic' | ||
def conditional(): | ||
return False | ||
|
||
manager.MagicManager.register_magic(my_magic, conditional=conditional) | ||
magic_from_manager = manager.MagicManager.get_magic('other_magic') | ||
assert magic_from_manager is None | ||
|
||
manager.MagicManager.register_magic(my_magic) | ||
magic_from_manager = manager.MagicManager.get_magic('other_magic') | ||
assert magic_from_manager() == 'foobar' | ||
|
||
manager.MagicManager.deregister_magic('other_magic') | ||
magic_from_manager = manager.MagicManager.get_magic('other_magic') | ||
assert magic_from_manager is None | ||
|
||
manager.MagicManager.deregister_magic('magical_function') | ||
magic_from_manager = manager.MagicManager.get_magic('magical_function') | ||
assert magic_from_manager is None | ||
|
||
with pytest.raises(KeyError): | ||
manager.MagicManager.deregister_magic('does_not_exist') | ||
|
||
|
||
def test_magic_info(): | ||
"""Test the get_magic_info.""" | ||
# Start by clearing the current registration. | ||
manager.MagicManager.clear_magics() | ||
def magical_func(): | ||
"""This is a magical function that returns pure magic.""" | ||
return 'magic' | ||
|
||
magical_func.magic_name = 'magical_function' | ||
magical_func.fn = magical_func | ||
manager.MagicManager.register_magic(magical_func) | ||
|
||
def second_magic(): | ||
"""This is even more magic.""" | ||
return 'fab' | ||
second_magic.magic_name = 'some_magic' | ||
second_magic.fn = second_magic | ||
manager.MagicManager.register_magic(second_magic) | ||
|
||
def other_magic(): | ||
"""Could this be it?""" | ||
return 'true magic' | ||
|
||
other_magic.magic_name = 'other_magic' | ||
other_magic.fn = other_magic | ||
manager.MagicManager.register_magic(other_magic) | ||
|
||
info_df = manager.MagicManager.get_magic_info(as_pandas=True) | ||
assert len(info_df) == 3 | ||
assert not info_df[info_df.name == 'other_magic'].empty | ||
|
||
desc_set = set(info_df.description.unique()) | ||
expected_set = set([ | ||
'Could this be it?', 'This is even more magic.', | ||
'This is a magical function that returns pure magic.']) | ||
|
||
assert desc_set == expected_set | ||
|
||
entries = manager.MagicManager.get_magic_info(as_pandas=False) | ||
assert len(entries) == 3 | ||
names = [x[0] for x in entries] | ||
assert 'other_magic' in names | ||
assert 'some_magic' in names |
Oops, something went wrong.