Skip to content

Commit

Permalink
Support for TravisCI and coveralls.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinabrahms committed Oct 20, 2015
1 parent c199a58 commit de461aa
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: python
python: 2.7
sudo: false
env:
- TOX_ENV=py27
- TOX_ENV=py34
install:
- pip install tox
script:
- env
- tox -e $TOX_ENV
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
xbundle
=======

.. image:: https://travis-ci.org/mitodl/xbundle.svg?branch=travis
:target: https://travis-ci.org/mitodl/xbundle

.. image:: https://coveralls.io/repos/mitodl/xbundle/badge.svg?branch=master&service=github
:target: https://coveralls.io/github/mitodl/xbundle?branch=master

``xbundle`` converts back and forth between OLX and "xbundle" style XML
formats. The xbundle format is a single XML file.

Expand Down
2 changes: 1 addition & 1 deletion test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pytest<2.8
pytest-pep8
pytest-pylint
pytest-cov

coveralls
33 changes: 28 additions & 5 deletions tests/test_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from lxml import etree
import os
from shutil import rmtree
from shutil import rmtree, copytree
from subprocess import check_call
from tempfile import mkdtemp
from unittest import TestCase
Expand All @@ -17,6 +17,21 @@
from tests.data import expected as expected_data, input as input_data


def _normalize_xml(dirname):
"""Removes whitespace from xml files in the given directory."""
for dname, _, files in os.walk(dirname):
for fname in files:
fpath = os.path.join(dname, fname)
if not fpath.endswith('.xml'):
continue
with open(fpath) as f:
s = f.read()
s = s.replace('\n', '') # erase newlines
s = s.replace(' ', '') # erase spaces
with open(fpath, 'w') as f:
f.write(s)


class TestImportExport(TestCase):
"""
Test that data is retained after an import/export or export/import cycle.
Expand Down Expand Up @@ -62,10 +77,18 @@ def test_import_export(self): # pylint: disable=no-self-use
try:
bundle.export_to_directory(tdir)

knownDir = os.path.join("input_testdata", "mitx.01.exported")
knownTempDir = os.path.join(tdir, 'mitx.01.exported')
newDir = os.path.join(tdir, "mitx.01")

# Transform xml files to remove spaces. This allows for cross tests
# to pass across platforms with slightly different xml serializers
# (see: travis). We copy the files for easy cleanup.
copytree(knownDir, knownTempDir)
_normalize_xml(tdir)

check_call([
"diff", "-r",
os.path.join("input_testdata", "mitx.01.exported"),
os.path.join(tdir, "mitx.01"),
"diff", "-r", knownTempDir, newDir
])
finally:
rmtree(tdir)
Expand Down Expand Up @@ -196,7 +219,7 @@ def test_import_large(self):
try:
bundle.export_to_directory(tempdir, xml_only=True, newfmt=True)

for root, _, files in os.walk(os.path.join(tempdir, "0.001")):
for _, _, files in os.walk(os.path.join(tempdir, "0.001")):
for filename in files:
# We set xml_only=True so there shouldn't be anything else.
self.assertTrue(filename.endswith(".xml"))
Expand Down
8 changes: 8 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/test_requirements.txt
commands = py.test {posargs}
whitelist_externals=coveralls
passenv = *
setenv =
PYTHONPATH = {toxinidir}

# used to report coverage only on py27 as coveralls can't take
# multiple results.
[testenv:py27]
commands =
py.test {posargs}
coveralls

0 comments on commit de461aa

Please sign in to comment.