Skip to content

Commit

Permalink
Add travis test integration
Browse files Browse the repository at this point in the history
  • Loading branch information
eskerda committed May 20, 2016
1 parent d3289aa commit 391a9fa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
@@ -0,0 +1,9 @@
language: python
cache: pip
python:
- "2.7"
install:
# Disable gcc optimizations for greater install speed (lxml)
- CFLAGS="-O0" pip install . --upgrade
script:
- ./runtests.sh
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -23,7 +23,6 @@ Or after downloading/cloning the source:
```bash
python setup.py install
```

Usage
-----
```python
Expand Down
14 changes: 12 additions & 2 deletions runtests.sh 100644 → 100755
@@ -1,3 +1,13 @@
#!/bin/bash
TRAVIS_BUILD=${TRAVIS_BUILD:-0}
export PYTHONPATH=$PYTHONPATH:.
python2 setup.py install
python2 tests/unittest_pybikes.py $@
# It's not a really good idea to test spiders on travis
# limit test to some basic consistency and usage tests
if [ $TRAVIS_BUILD -eq 1 ]; then
python tests/unittest_pybikes.py TestBikeShareStationInstance
python tests/unittest_pybikes.py TestBikeShareSystemInstance
python tests/unittest_pybikes.py TestDataFiles
else
pip install .
python tests/unittest_pybikes.py $@
fi
22 changes: 16 additions & 6 deletions tests/unittest_pybikes.py
Expand Up @@ -6,7 +6,16 @@
import sys

import pybikes
import keys
try:
import keys
except ImportError:
print("Keys for testing not found, going to use invalid keys")

class DumbObject(object):
def __getattr__(self, name):
return 'invalid key'

keys = DumbObject()


class TestSystems(unittest.TestCase):
Expand Down Expand Up @@ -224,11 +233,11 @@ def test_instances(self):
schemas = pybikes.get_all_data()
for schema in schemas:
instances = pybikes.get_instances(schema)
for _, instance in instances:
self._test_instance_unique(instance, schema)
self._test_instance_fields(instance, schema)
for _class, instance in instances:
self._test_instance_unique(instance, schema, _class)
self._test_instance_fields(instance, schema, _class)

def _test_instance_unique(self, instance, schema):
def _test_instance_unique(self, instance, schema, _class):
if instance['tag'] in self.tags:
msg = (
'Tag {} in {} from {} is not unique. '.format(
Expand All @@ -248,10 +257,11 @@ def _test_instance_unique(self, instance, schema):
'schema': schema
}

def _test_instance_fields(self, _instance, schema):
def _test_instance_fields(self, _instance, schema, _class):
self.longMessage = True
# Some fields may be defined as class attributes and then passed into
# instance meta, so we need to instantiate it
# We do not really need keys here
instance = pybikes.get(_instance['tag'], key='foobar')
meta = instance.meta
msg = 'instance {!r}. File: {}'.format(
Expand Down

0 comments on commit 391a9fa

Please sign in to comment.