Skip to content

Commit

Permalink
Test coverage fix (#4564)
Browse files Browse the repository at this point in the history
* add pprint test for Specific

* add tests for _deserialize

* add serde test for RunFunctionOrConstructorAction

* add tests for object search permission update

* lint

* address comments

* Fixing linting issues and test

- Fixed failing test_Floatconversion test
- Removed @pytest.mark.xfail

Co-authored-by: Jasopaum <[email protected]>
  • Loading branch information
madhavajay and Jasopaum authored Sep 17, 2020
1 parent 4cf7f92 commit e9903b8
Show file tree
Hide file tree
Showing 17 changed files with 220 additions and 62 deletions.
2 changes: 1 addition & 1 deletion docs/basics.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
***************************
Getting Started with PySyft
***************************
***************************
2 changes: 1 addition & 1 deletion docs/codebase_walkthrough.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
**********************************
Step 2 - Learn the PySyft Codebase
**********************************
**********************************
2 changes: 1 addition & 1 deletion docs/coding_standards.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
********************************
Step 4 - Your First Pull Request
********************************
********************************
2 changes: 1 addition & 1 deletion docs/dev_environment.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
***********************************
Step 1 - Setup Your Dev Environment
***********************************
***********************************
2 changes: 1 addition & 1 deletion docs/duet.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*************************
Launch a Duet with PySyft
*************************
*************************
2 changes: 1 addition & 1 deletion docs/finding_an_issue.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
***************************
Step 3 - Your First Project
***************************
***************************
80 changes: 42 additions & 38 deletions docs/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Install PySyft
**************

This page shows how to install Syft version 0.3.0. As this software is currently in alpha,
there are changes happening every day. Thus, the best way to install PySyft is to build
it from source. Each of the tutorials below describe how to build PySyft from source
within each respective operating system.
This page shows how to install Syft version 0.3.0. As this software is currently in
alpha, there are changes happening every day. Thus, the best way to install PySyft is
to build it from source. Each of the tutorials below describe how to build PySyft from
source within each respective operating system.

If you get stuck anywhere in this tutorial, please `join OpenMined's slack <https://slack.openmined.org>`_
and ask a question in the channel called `#topic_beginner_questions <https://openmined.slack.com/archives/C6DEWA4FR>`_.
Expand Down Expand Up @@ -60,9 +60,9 @@ are running one of these versions. Run the following:
> python --version
Python 3.8.1
If the version printed underneath your command is less than 3.6, then you MUST use anaconda
in the next step (which is recommended anyway). Technically, you could try to upgrade your
version of python but fair warning... e're be dragons.
If the version printed underneath your command is less than 3.6, then you MUST use
anaconda in the next step (which is recommended anyway). Technically, you could try to
upgrade your version of python but fair warning... e're be dragons.


Step 3 - Setup Environment
Expand All @@ -72,19 +72,21 @@ I'm sure you're tempted to skip this step. Word from the wise...
`Don't skip this step.
<https://twitter.com/iamtrask/status/1300854373296332809>`_

You are about to install a library with lots of complex dependencies. You don't want to break
something on your computer because you're installing PySyft. And vice versa, you don't want
to later break your PySyft install when installing some other tool later! Friends don't
let friends build libraries from source without using a virtual environment.
You are about to install a library with lots of complex dependencies. You don't want to
break something on your computer because you're installing PySyft. And vice versa, you
don't want to later break your PySyft install when installing some other tool later!
Friends don't let friends build libraries from source without using a virtual
environment.

And since PySyft uses (and will use more and more) non-python dependencies, the best
virtual environment to use for PySyft is conda. Note, if you're tempted to use virtualenv
instead, `read this warning <https://twitter.com/shreyshahi/status/1300855906742140928>`_.
virtual environment to use for PySyft is conda. Note, if you're tempted to use
virtualenv instead, `read this warning <https://twitter.com/shreyshahi/status/1300855906742140928>`_.

Step 3.1 - Install Conda
^^^^^^^^^^^^^^^^^^^^^^^^

First, let's see if you have conda installed! Type "conda" into your Terminal app and hit enter.
First, let's see if you have conda installed! Type "conda" into your Terminal app and
hit enter.

.. code:: console
Expand All @@ -103,15 +105,15 @@ First, let's see if you have conda installed! Type "conda" into your Terminal ap
file (/Users/atrask/.condarc) by default.
create Create a new conda environment from a list of specified
If calling "conda" doesn't return something like this, then you need to install conda. Just
follow the `installation instructions <https://docs.conda.io/projects/conda/en/latest/user-guide/install/>`_
If calling "conda" doesn't return something like this, then you need to install conda.
Just follow the `installation instructions <https://docs.conda.io/projects/conda/en/latest/user-guide/install/>`_
and you'll be fine.

Step 3.2 - Create conda Env
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Now, we want to create a conda virtual environment with the latest verison of Python supported
by syft which, at the time of writing, is 3.8.
Now, we want to create a conda virtual environment with the latest verison of Python
supported by syft which, at the time of writing, is 3.8.

.. code:: console
Expand All @@ -123,41 +125,42 @@ Then follow the instructions it gives you to create your environment.
Step 3.3 - Activate Conda Env
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To activate the environment you created in the last step, simply enter `activate <environment name>`
which if you simply copy pasted the line above, the environment name was "my_syft_env".
To activate the environment you created in the last step, simply enter
`activate <environment name>` which if you simply copy pasted the line above, the
environment name was "my_syft_env".

.. code:: console
conda activate my_syft_env
.. note::

You will need to activate this my_syft_env environment whenever you want to use syft,
unless of course you install syft in another environment.
You will need to activate this my_syft_env environment whenever you want to use
syft, unless of course you install syft in another environment.


Step 4 - Install Dependencies
-----------------------------

Assuming you're still in the base directory of PySyft (as you came to be in step 1), you can
now install the dependencies that PySyft relies on using the following command:
Assuming you're still in the base directory of PySyft (as you came to be in step 1),
you can now install the dependencies that PySyft relies on using the following command:

.. code:: console
pip install -r requirements.txt
This should install all the libraries you need for PySyft. Just in case, let's make sure
you have a compatible version of PyTorch. Your PyTorch version should be 1.3 or later. Open
up a python shell (by running `python` in your Terminal client) and then execute the following
python code.
This should install all the libraries you need for PySyft. Just in case, let's make
sure you have a compatible version of PyTorch. Your PyTorch version should be 1.3 or
later. Open up a python shell (by running `python` in your Terminal client) and then
execute the following python code.

.. code:: python
import torch
print(torch.__version__)
As long as this reads 1.3 or later, you should be good. If it's 1.3 or earlier, then upgrade
it by installing the latest version.
As long as this reads 1.3 or later, you should be good. If it's 1.3 or earlier, then
upgrade it by installing the latest version.

.. code:: console
Expand All @@ -166,16 +169,17 @@ it by installing the latest version.
Step 5 - Install PySyft
-----------------------

You are now ready to install PySyft! We recommend the following just in case you later decide
you want to help edit the codebase.
You are now ready to install PySyft! We recommend the following just in case you later
decide you want to help edit the codebase.

.. code:: python
pip install -e .
This will create a permanent pointer from the PySyft code to your conda VM. That means that if
you make any changes to the code you won't have to re-install PySyft to be able to use them!
If you don't want this fanciness you can also run the good ole fashioned setup.py install.
This will create a permanent pointer from the PySyft code to your conda VM. That means
that if you make any changes to the code you won't have to re-install PySyft to be able
to use them! If you don't want this fanciness you can also run the good ole fashioned
setup.py install.

.. code:: python
Expand All @@ -184,9 +188,9 @@ If you don't want this fanciness you can also run the good ole fashioned setup.p
Step 6 - Run Light Tests
------------------------

At the time of writing, we have quite a few unit tests but most of them are simply testing
the PyTorch runtime. To run the abbreviated set of tests (and make sure your installation
is happy), run the following.
At the time of writing, we have quite a few unit tests but most of them are simply
testing the PyTorch runtime. To run the abbreviated set of tests (and make sure your
installation is happy), run the following.

.. code:: python
Expand Down
2 changes: 1 addition & 1 deletion docs/joining_a_team.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
************************
Step 5 - Join a Dev Team
************************
************************
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
bandit
black
dataclasses # backport to python 3.6
doc8
flake8
flask
forbiddenfruit>=0.1.3
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ import_heading_syft=syft absolute
import_heading_localfolder=syft relative
ignore_comments=False
force_grid_wrap=True
honor_noqa=True
honor_noqa=True
13 changes: 6 additions & 7 deletions src/syft/core/common/serde/deserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ def _deserialize(
obj_type = type(blob).schema2type # type: ignore

# uh-oh! Looks like the type doesn't exist. Let's throw an informative error.
except KeyError:

except AttributeError:
raise TypeError(
"""You tried to deserialize an unsupported type. This can be caused by
several reasons. Either you are actively writing Syft code and forgot
to create one, or you are trying to deserialize an object which was
serialized using a different version of Syft and the object you tried
to deserialize is not supported in this version."""
"You tried to deserialize an unsupported type. This can be caused by "
"several reasons. Either you are actively writing Syft code and forgot "
"to create one, or you are trying to deserialize an object which was "
"serialized using a different version of Syft and the object you tried "
"to deserialize is not supported in this version."
)

return obj_type._proto2object(proto=blob)
Empty file.
17 changes: 17 additions & 0 deletions tests/syft/core/common/serde/deserialize_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# third party
from pytest import raises

# syft absolute
from syft.core.common.serde.deserialize import _deserialize


def test_fail_deserialize_no_format() -> None:
with raises(
ValueError, match="Please pick the format of the data on the deserialization"
):
_deserialize(blob="to deserialize", from_proto=False)


def test_fail_deserialize_wrong_format() -> None:
with raises(TypeError, match="You tried to deserialize an unsupported type."):
_deserialize(blob="to deserialize")
8 changes: 8 additions & 0 deletions tests/syft/core/io/location/specific_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def test_to_string() -> None:
assert obj.__repr__() == "<SpecificLocation:fb1bb067-5bb7-4c49-bece-e700ab0a1514>"


def test_pprint() -> None:
"""Tests that SpecificLocation generates a pretty representation."""

uid = UID(value=uuid.UUID(int=333779996850170035686993356951732753684))
obj = SpecificLocation(id=uid, name="location")
assert obj.pprint == "📌 location (SpecificLocation)@<UID:🙍🛖>"


# --------------------- SERDE ---------------------


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# third party
import torch as th

# syft absolute
import syft as sy
from syft.core.common.uid import UID
from syft.core.node.common.action.function_or_constructor_action import (
RunFunctionOrConstructorAction,
)

# TODO test execution
# TODO test permissions


def test_run_function_or_constructor_action_serde() -> None:
alice = sy.VirtualMachine(name="alice")
alice_client = alice.get_client()

args = (
th.tensor([1, 2, 3]).send(alice_client),
th.tensor([4, 5, 5]).send(alice_client),
)

msg = RunFunctionOrConstructorAction(
path="torch.Tensor.add",
args=args,
kwargs={},
id_at_location=UID(),
address=alice_client.address,
msg_id=UID(),
)

blob = msg.serialize()

msg2 = sy.deserialize(blob=blob)

assert msg2.path == msg.path
# FIXME this cannot be checked before we fix the Pointer serde problem (see _proto2object in Pointer)
# assert msg2.args == msg.args
assert msg2.kwargs == msg.kwargs
assert msg2.address == msg.address
assert msg2.id == msg.id
assert msg2.id_at_location == msg.id_at_location
Loading

0 comments on commit e9903b8

Please sign in to comment.