Skip to content

Commit

Permalink
fix isinstance calls and add some tests (#115)
Browse files Browse the repository at this point in the history
* fix isinstance calls and add some tests

* docstrings for new tests

* now using pandas in tests
  • Loading branch information
jwkvam committed Apr 16, 2017
1 parent fea3038 commit f31cabd
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion bowtie/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Interactive dashboard toolkit."""

__version__ = '0.3.0'
__version__ = '0.3.1-dev'

from bowtie._layout import Layout
from bowtie._command import command
8 changes: 4 additions & 4 deletions bowtie/_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def json_conversion(obj):
# numpy isn't an explicit dependency of bowtie
# so we can't assume it's available
import numpy as np
if isinstance(obj, np.ndarray, np.generic):
if isinstance(obj, (np.ndarray, np.generic)):
return obj.tolist()
except ImportError:
pass
Expand All @@ -54,7 +54,7 @@ def json_conversion(obj):
except ImportError:
pass

if isinstance(obj, datetime, time, date):
if isinstance(obj, (datetime, time, date)):
return obj.isoformat()
raise TypeError('Not sure how to serialize {} of type {}'.format(obj, type(obj)))

Expand All @@ -70,7 +70,7 @@ def encoders(obj):
# numpy isn't an explicit dependency of bowtie
# so we can't assume it's available
import numpy as np
if isinstance(obj, np.ndarray, np.generic):
if isinstance(obj, (np.ndarray, np.generic)):
# https://docs.scipy.org/doc/numpy/reference/arrays.scalars.html
return obj.tolist()
except ImportError:
Expand All @@ -85,7 +85,7 @@ def encoders(obj):
except ImportError:
pass

if isinstance(obj, datetime, time, date):
if isinstance(obj, (datetime, time, date)):
return obj.isoformat()

return obj
Expand Down
6 changes: 2 additions & 4 deletions bowtie/tests/test_compat.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Compat testing
"""
"""Compat testing."""

from bowtie._compat import numargs


def test_numargs():
"""test numargs"""
"""Numargs testing."""

# pylint: disable=missing-docstring
def onearg(x):
Expand Down
8 changes: 2 additions & 6 deletions bowtie/tests/test_compile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Compile tests
"""
"""Compile tests."""

import os

Expand All @@ -19,9 +17,7 @@ def callback(*args):

# pylint: disable=unused-argument
def test_build(remove_build):
"""
Tests the build process.
"""
"""Tests the build process."""
ctrl = Nouislider()
viz = Plotly()

Expand Down
8 changes: 2 additions & 6 deletions bowtie/tests/test_plotly.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Plotly testing
"""
"""Plotly testing."""

import os
import subprocess
Expand All @@ -25,9 +23,7 @@ def callback(*args):

# pylint: disable=unused-argument
def test_plotly(remove_build):
"""
Tests plotly.
"""
"""Tests plotly."""
viz = Plotly()
ctrl = Nouislider()
ctrl2 = Button()
Expand Down
27 changes: 27 additions & 0 deletions bowtie/tests/test_serialize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Serialization testing."""

import numpy as np
import pandas as pd

from bowtie._component import jdumps, pack


NPARRAY = np.array([5, 6])
NPSCALAR = np.int32(5)
DATES = pd.date_range('2017-01-01', periods=2)


def test_json():
"""Tests json encoding numpy and pandas."""
assert jdumps(NPARRAY) == jdumps([5, 6])
assert jdumps(NPSCALAR) == jdumps(5)
assert jdumps(DATES) == jdumps(['2017-01-01T00:00:00', '2017-01-02T00:00:00'])


def test_msgpack():
"""Tests msgpack encoding numpy and pandas."""
assert pack(NPARRAY) == pack([5, 6])
assert pack(NPSCALAR) == pack(5)
assert pack(DATES) == pack(['2017-01-01T00:00:00', '2017-01-02T00:00:00'])
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jinja2
markdown
msgpack-python
numpy
pandas
plotlywrapper
pydocstyle
pylint
Expand Down

0 comments on commit f31cabd

Please sign in to comment.