Skip to content

Commit

Permalink
cleanup settings and now using hypothesis profiles
Browse files Browse the repository at this point in the history
moved std_msgs tests.
  • Loading branch information
asmodehn committed Sep 1, 2017
1 parent 44b1cee commit 5e4a0b9
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ install:
- pip install tox tox-travis

script:
- tox
- tox -- --hypothesis-profile travis

notifications:
email: false
Expand Down
2 changes: 0 additions & 2 deletions pyros_schemas/ros/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

from .utils import _get_rosmsg_members_as_dict

import roslib

# Statically proxying marshmallow useful decorators for methods
pre_load = marshmallow.pre_load
post_load = marshmallow.post_load
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,15 @@ def run(self):
include_package_data=True, # use MANIFEST.in during install.
# Reference for optional dependencies : http://stackoverflow.com/questions/4796936/does-pip-handle-extras-requires-from-setuptools-distribute-based-sources
install_requires=[
'pyros-msgs',
'pyros-msgs>=0.1.1',
# this is needed as install dependency since we embed tests in the package.
'pyros_setup>=0.2.1', # needed to grab ros environment even if distro setup.sh not sourced
'six>=1.5.2',
'marshmallow>=2.9.1',
],
test_requires=[
'pytest>=2.8.0', # as per hypothesis requirement (careful with 2.5.1 on trusty)
'hypothesis>=3.0.1', # to target xenial LTS version
'numpy>=1.8.2', # from trusty version
'marshmallow>=2.9.1',
],
cmdclass={
'rosdevelop': RosDevelopCommand,
Expand Down
17 changes: 17 additions & 0 deletions tests/test_pyros_schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@
six_long = six.integer_types[-1]


if hasattr(hypothesis, 'HealthCheck'):
hypothesis.settings.register_profile("travis", hypothesis.settings(
suppress_health_check=hypothesis.HealthCheck.too_slow
))
else:
hypothesis.settings.register_profile("travis", hypothesis.settings(
# default
))

hypothesis.settings.register_profile("dev", hypothesis.settings(
verbosity=hypothesis.Verbosity.verbose,
))

# default settings
hypothesis.settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'dev'))


def maybe_list(l):
"""Return list of one element if ``l`` is a scalar."""
return l if l is None or isinstance(l, list) else [l]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
from __future__ import absolute_import
from __future__ import print_function
from __future__ import absolute_import, print_function

try:
import std_msgs.msg as std_msgs
import std_msgs.msg as std_msgs
# import pyros_msgs.msg as pyros_msgs
except ImportError:
# Because we need to access Ros message types here (from ROS env or from virtualenv, or from somewhere else)
import pyros_setup
# We rely on default configuration to point us ot the proper distro
pyros_setup.configurable_import().configure().activate()
import std_msgs.msg as std_msgs
# import pyros_msgs.msg as pyros_msgs


import nose
import pytest
import marshmallow

# absolute import ros field types
Expand All @@ -32,55 +22,53 @@
)


@nose.tools.nottest
def gen_rosmsg_test(schemaType, ros_msg, py_inst_expected):
def gen_rosmsg(schemaType, ros_msg, py_inst_expected):
schema = schemaType()

marshalled, errors = schema.dump(ros_msg)
marshalled, errors = schema.load(ros_msg)
assert not errors and marshalled == py_inst_expected

value, errors = schema.load(marshalled)
value, errors = schema.dump(marshalled)
assert not errors and type(value) == type(ros_msg) and value == ros_msg


@nose.tools.nottest
def gen_pymsg_test(schemaType, ros_msg_expected, py_inst):
def gen_pymsg(schemaType, ros_msg_expected, py_inst):

schema = schemaType()

unmarshalled, errors = schema.load(py_inst)
unmarshalled, errors = schema.dump(py_inst)
assert not errors and type(unmarshalled) == type(ros_msg_expected) and unmarshalled == ros_msg_expected

obj, errors = schema.dump(unmarshalled)
obj, errors = schema.load(unmarshalled)
assert not errors and type(obj) == type(py_inst) and obj == py_inst


def test_msgbool_ros():
yield gen_rosmsg_test, RosMsgBool, std_msgs.Bool(data=True), {'data': True}
yield gen_rosmsg_test, RosMsgBool, std_msgs.Bool(data=False), {'data': False}
yield gen_rosmsg, RosMsgBool, std_msgs.Bool(data=True), {'data': True}
yield gen_rosmsg, RosMsgBool, std_msgs.Bool(data=False), {'data': False}


def test_msgbool_py():
yield gen_pymsg_test, RosMsgBool, std_msgs.Bool(data=True), {'data': True}
yield gen_pymsg_test, RosMsgBool, std_msgs.Bool(data=False), {'data': False}
yield gen_pymsg, RosMsgBool, std_msgs.Bool(data=True), {'data': True}
yield gen_pymsg, RosMsgBool, std_msgs.Bool(data=False), {'data': False}


def test_msgint8_ros():
yield gen_rosmsg_test, RosMsgInt8, std_msgs.Int8(data=42), {'data': 42}
yield gen_rosmsg, RosMsgInt8, std_msgs.Int8(data=42), {'data': 42}


def test_msgint8_py():
yield gen_pymsg_test, RosMsgInt8, std_msgs.Int8(data=42), {'data': 42}
yield gen_pymsg, RosMsgInt8, std_msgs.Int8(data=42), {'data': 42}

# TODO : test other ints


def test_msgstring_ros():
yield gen_rosmsg_test, RosMsgString, std_msgs.String(data='fortytwo'), {'data': u'fortytwo'}
yield gen_rosmsg, RosMsgString, std_msgs.String(data='fortytwo'), {'data': u'fortytwo'}


def test_msgstring_py():
yield gen_pymsg_test, RosMsgString, std_msgs.String(data='fortytwo'), {'data': u'fortytwo'}
yield gen_pymsg, RosMsgString, std_msgs.String(data='fortytwo'), {'data': u'fortytwo'}


#
Expand Down Expand Up @@ -154,5 +142,6 @@ def test_msgstring_py():

# Just in case we run this directly
if __name__ == '__main__':
import nose
nose.runmodule(__name__)
pytest.main([
'-s', __file__,
])
4 changes: 0 additions & 4 deletions tests/test_pyros_schemas/test_basic_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def fieldtype_and_value(draw, field_type_strat_tuples):
'std_msgs/Duration',
#TODO : more of that...
)))
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose)
def test_field_deserialize_serialize_from_ros_inverse(msg_rostype_and_value):
msg_type = msg_rostype_and_value[0]
msg_value = msg_rostype_and_value[1]
Expand Down Expand Up @@ -149,7 +148,6 @@ def test_field_deserialize_serialize_from_ros_inverse(msg_rostype_and_value):
'std_msgs/Duration',
#TODO : more of that...
)))
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose)
def test_field_deserialize_from_ros_to_type(msg_rostype_and_value):
msg_type = msg_rostype_and_value[0]
msg_value = msg_rostype_and_value[1]
Expand Down Expand Up @@ -200,7 +198,6 @@ def test_field_deserialize_from_ros_to_type(msg_rostype_and_value):
'duration',
#TODO : more of that...
)))
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose)
def test_field_serialize_deserialize_from_py_inverse(msg_rostype_and_value):
# TODO : make it clearer that we get different data here, even if we still use msg_rostype_and_value
# Same values as for ros message test
Expand Down Expand Up @@ -244,7 +241,6 @@ def test_field_serialize_deserialize_from_py_inverse(msg_rostype_and_value):
'duration',
#TODO : more of that...
)))
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose)
def test_field_serialize_from_py_to_type(msg_rostype_and_value):
# TODO : makeit clearer that we get different data here, even if we still use msg_rostype_and_value
# Same values as for ros message test
Expand Down
6 changes: 1 addition & 5 deletions tests/test_pyros_schemas/test_optional_as_array_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def fieldtypestring_from_rostypestring(rostypestring):

# We need a composite strategy to link slot type and slot value
@st.composite
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose, timeout=1)
@hypothesis.settings(timeout=1)
def msg_rostype_and_value(draw, msgs_type_strat_tuples):
msg_type_strat = draw(st.sampled_from(msgs_type_strat_tuples))
# print(msg_type_strat[1]) # just in case, to help debugging strategies
Expand All @@ -111,7 +111,6 @@ def msg_rostype_and_value(draw, msgs_type_strat_tuples):
'pyros_schemas/test_opt_duration_as_array',
#TODO : more of that...
)))
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose)
def test_optfield_deserialize_serialize_from_ros_inverse(msg_rostype_and_value):
msg_type = msg_rostype_and_value[0]
msg_value = msg_rostype_and_value[1]
Expand Down Expand Up @@ -154,7 +153,6 @@ def test_optfield_deserialize_serialize_from_ros_inverse(msg_rostype_and_value):
'pyros_schemas/test_opt_duration_as_array',
#TODO : more of that...
)))
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose)
def test_optfield_deserialize_from_ros_to_type_in_list(msg_rostype_and_value):
msg_type = msg_rostype_and_value[0]
msg_value = msg_rostype_and_value[1]
Expand Down Expand Up @@ -211,7 +209,6 @@ def test_optfield_deserialize_from_ros_to_type_in_list(msg_rostype_and_value):
'optduration',
#TODO : more of that...
)))
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose)
def test_field_serialize_deserialize_from_py_inverse(msg_rostype_and_value):
# TODO : makeit clearer that we get different data here, even if we still use msg_rostype_and_value
# Same values as for ros message test
Expand Down Expand Up @@ -266,7 +263,6 @@ def test_field_serialize_deserialize_from_py_inverse(msg_rostype_and_value):
'opttime',
'optduration',
)))
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose)
def test_field_serialize_from_py_to_listtype(msg_rostype_and_value):
# TODO : makeit clearer that we get different data here, even if we still use msg_rostype_and_value
# Same values as for ros message test
Expand Down
4 changes: 0 additions & 4 deletions tests/test_pyros_schemas/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# We need a composite strategy to link msg type and dict structure
@st.composite
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose)
def msg_rostype_and_dict(draw, msgs_type_strat_tuples):
msg_type_strat = draw(st.sampled_from(msgs_type_strat_tuples))
msg_value = draw(msg_type_strat[1])
Expand All @@ -43,7 +42,6 @@ def msg_rostype_and_dict(draw, msgs_type_strat_tuples):
'std_msgs/Duration',
#TODO : more of that...
)))
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose)
def test_schema_load_dump_fromros_inverse(msg_rostype_value_and_dict):
msg_rostype = msg_rostype_value_and_dict[0] # just for info/debug purposes
ros_msg = msg_rostype_value_and_dict[1]
Expand All @@ -61,7 +59,6 @@ def test_schema_load_dump_fromros_inverse(msg_rostype_value_and_dict):

# We need a composite strategy to link msg type and dict structure
@st.composite
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose)
def msg_dict_and_rostype(draw, msgs_dict_strat_tuples):
msg_dict_strat = draw(st.sampled_from(msgs_dict_strat_tuples))
msg_dict = draw(msg_dict_strat[1])
Expand All @@ -86,7 +83,6 @@ def msg_dict_and_rostype(draw, msgs_dict_strat_tuples):
'std_msgs/Duration',
#TODO : more of that...
)))
@hypothesis.settings(verbosity=hypothesis.Verbosity.verbose)
def test_schema_dump_load_frompy_inverse(msg_rostype_dict_and_value):
msg_rostype = msg_rostype_dict_and_value[0] # just for info/debug purposes
py_inst = msg_rostype_dict_and_value[1]
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ deps =
py_latest: -rrequirements/python/tests.txt

# to always force recreation and avoid unexpected side effects
recreate=False
recreate=True

changedir = tests

Expand Down

0 comments on commit 5e4a0b9

Please sign in to comment.