Skip to content

Commit

Permalink
Added testing of unavailable packages
Browse files Browse the repository at this point in the history
  • Loading branch information
hgrecco committed Jan 28, 2016
1 parent 45acae0 commit bf7fc7c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
language: python

python:
- "3.3"
- "3.4"
- "3.5"

env:
- EXTRAS="N"
- EXTRAS="Y"

install:
- pip install -r supported_pkgs.txt
- if [ $EXTRAS == 'Y' ]; then pip install r supported_pkgs.txt; fi
- pip install coveralls

script:
- python -bb -m coverage run -p --source=serialize --omit="*test*" setup.py test
- coverage combine
Expand Down
32 changes: 25 additions & 7 deletions serialize/testsuite/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

import os
from unittest import TestCase, skipIf

from unittest import TestCase


from serialize import register_class, loads, dumps

from serialize.all import FORMATS, UNAVAILABLE_FORMATS
from serialize import register_class, loads, dumps, load, dump
from serialize.all import FORMATS, UNAVAILABLE_FORMATS, _get_format_from_ext


class X:
Expand Down Expand Up @@ -40,8 +38,9 @@ def from_builtin(content):
register_class(X, to_builtin, from_builtin)


class TestAllAvailable(TestCase):
class TestAvailable(TestCase):

@skipIf(os.environ.get('EXTRAS', None) == 'N', 'Extras not installed')
def test_available(self):
self.assertFalse(UNAVAILABLE_FORMATS)

Expand Down Expand Up @@ -72,6 +71,10 @@ class _TestEncoderDecoder:
def _test_round_trip(self, obj):
self.assertEqual(obj, loads(dumps(obj, self.FMT), self.FMT))

def test_format_from_ext(self):
fh = FORMATS[self.FMT]
self.assertEqual(_get_format_from_ext(fh.extension), self.FMT)

def test_response_bytes(self):

obj = 'here I am'
Expand Down Expand Up @@ -108,8 +111,23 @@ def test_custom_object_in_container(self):
self._test_round_trip(c)


class _TestUnavailable:

def test_raise(self):
self.assertRaises(ValueError, dumps, 'hello', self.FMT)

def test_raise_from_ext(self):
self.assertRaises(ValueError, dumps, 'hello', self.FMT)


for key in FORMATS.keys():
name = "TestEncoderDecoder_%s" % key
globals()[name] = type(name,
(_TestEncoderDecoder, TestCase),
dict(FMT=key))

for key in UNAVAILABLE_FORMATS.keys():
name = "TestEncoderDecoder_%s" % key
globals()[name] = type(name,
(_TestUnavailable, TestCase),
dict(FMT=key))

0 comments on commit bf7fc7c

Please sign in to comment.