Skip to content

Commit

Permalink
Add tests, and TravisCI integration
Browse files Browse the repository at this point in the history
  • Loading branch information
titipata committed Jan 21, 2020
1 parent 08c8867 commit 177869c
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
language: python
env:
- PYTHON=3.5
- PYTHON=3.6
- PYTHON=3.7
- PYTHON=3.8

miniconda:
- wget -q http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
- chmod +x miniconda.sh
- ./miniconda.sh -b -p /home/travis/miniconda
- export PATH=/home/travis/miniconda/bin:$PATH
- conda update --yes conda

install:
- conda create -n testenv --yes pip python=$PYTHON
- source activate testenv
- conda install --yes --file requirements.txt
- python setup.py install

script:
- py.test --cov=pubmed_parser tests/ --verbose

after_success:
- bash <(curl -s https://codecov.io/bash)
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
lxml
unidecode
requests
six
numpy
pytest
pytest-cov
28 changes: 27 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,35 @@
author='Titipat Achakulvisut',
author_email='[email protected]',
license='(c) 2015 - 2019 Titipat Achakulvisut, Daniel E. Acuna',
install_requires=['lxml', 'unidecode', 'requests', 'six', 'numpy'],
install_requires=[
'lxml', 'unidecode', 'requests',
'six', 'numpy', 'pytest',
'pytest-cov'
],
packages=['pubmed_parser'],
package_data={
'pubmed_parser.data': ['*.xml.gz', '*.nxml', '*.txt'],
},
classifiers=[
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Topic :: Software Development",
"Topic :: Scientific/Engineering",
"Operating System :: Microsoft :: Windows",
"Operating System :: Unix",
"Operating System :: MacOS",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8"
],
platforms='any',
project_urls={
'Source': 'https://github.com/titipata/pubmed_parser',
'Documentation': 'http://titipata.github.io/pubmed_parser',
'Bug Reports': 'https://github.com/titipata/pubmed_parser/issues'
}
)
15 changes: 15 additions & 0 deletions tests/test_medline_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import pytest

import pubmed_parser as pp


def test_parse_medline_xml():
"""
Test parse captions and figure ID from an XML file
"""
parsed_xml = pp.parse_pubmed_xml(os.path.join('data', 'pone.0046493.nxml'))
assert len(parsed_xml.get('abstract')) > 0
assert len(parsed_xml.get('full_title')) > 0
assert parsed_xml.get('pmc') == '3460867'
assert parsed_xml.get('doi') == '10.1371/journal.pone.0046493'
31 changes: 31 additions & 0 deletions tests/test_pubmed_oa_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import pytest

import pubmed_parser as pp


def test_parse_pubmed_xml():
"""
Test parse captions and figure ID from an XML file
"""
parsed_xml = pp.parse_pubmed_xml(os.path.join('data', 'pone.0046493.nxml'))
assert len(parsed_xml.get('abstract')) > 0
assert len(parsed_xml.get('full_title')) > 0
assert parsed_xml.get('pmc') == '3460867'
assert parsed_xml.get('doi') == '10.1371/journal.pone.0046493'


def test_parse_pubmed_caption():
"""
Test parse captions and figure ID from an XML file
"""
paragraphs = pp.parse_pubmed_paragraph(os.path.join('data', 'pone.0046493.nxml'))
assert isinstance(paragraphs[0], dict)


def test_parse_pubmed_references():
"""
Test parse references from an XML file
"""
references = pp.parse_pubmed_paragraph(os.path.join('data', 'pone.0046493.nxml'))
assert isinstance(references[0], dict)

0 comments on commit 177869c

Please sign in to comment.