Skip to content

Commit fa9b88d

Browse files
committed
Merge pull request #189 from ocefpaf/refactor_tests
Using py.test instead of nose
2 parents b76b08f + b107a0e commit fa9b88d

File tree

5 files changed

+197
-153
lines changed

5 files changed

+197
-153
lines changed

.travis.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ before_install:
1111
- wget http://bit.ly/miniconda -O miniconda.sh
1212
- bash miniconda.sh -b -p $HOME/miniconda
1313
- export PATH="$HOME/miniconda/bin:$PATH"
14-
- conda update --yes conda
15-
- travis_retry conda create --yes -n test $CONDA pip jinja2 pandas mock six nose
14+
- conda update --yes --all
15+
- travis_retry conda create --yes -n test $CONDA --file requirements.txt
1616
- source activate test
17+
- travis_retry conda install --yes pip mock pytest pandas
1718
- travis_retry pip install vincent
1819

19-
install:
20-
- python setup.py install
21-
2220
script:
23-
- cd tests && nosetests --verbose --nocapture folium_tests.py
21+
- python setup.py test
22+

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Jinja2==2.7.2
1+
Jinja2

setup.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
# -*- coding: utf-8 -*-
22

3-
from __future__ import absolute_import
4-
53
import os
6-
import re
74
import sys
8-
import codecs
9-
try:
10-
from setuptools import setup
11-
except ImportError:
12-
from distutils.core import setup
5+
from setuptools import setup
6+
from setuptools.command.test import test as TestCommand
137

148
rootpath = os.path.abspath(os.path.dirname(__file__))
159

1610

11+
class PyTest(TestCommand):
12+
def finalize_options(self):
13+
TestCommand.finalize_options(self)
14+
# FIXME: '--doctest-modules'
15+
self.test_args = ['--verbose']
16+
self.test_suite = True
17+
18+
def run_tests(self):
19+
import pytest
20+
errno = pytest.main(self.test_args)
21+
sys.exit(errno)
22+
23+
1724
def read(*parts):
18-
return codecs.open(os.path.join(rootpath, *parts), 'r').read()
25+
return open(os.path.join(rootpath, *parts), 'r').read()
1926

2027

21-
def find_version(*file_paths):
22-
version_file = read(*file_paths)
23-
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
24-
version_file, re.M)
25-
if version_match:
26-
return version_match.group(1)
27-
raise RuntimeError("Unable to find version string.")
28+
def extract_version(module='folium'):
29+
version = None
30+
fname = os.path.join(rootpath, module, '__init__.py')
31+
with open(fname) as f:
32+
for line in f:
33+
if (line.startswith('__version__')):
34+
_, version = line.split('=')
35+
version = version.strip()[1:-1] # Remove quotation characters.
36+
break
37+
return version
2838

2939

3040
def walk_subpkg(name):
@@ -47,20 +57,23 @@ def walk_subpkg(name):
4757
'templates/*.js',
4858
'templates/*.txt'] + walk_subpkg('templates/tiles')}
4959
pkgs = ['folium',
50-
'folium.plugins',
51-
]
60+
'folium.plugins']
5261

5362
LICENSE = read('LICENSE.txt')
54-
version = find_version('folium', '__init__.py')
5563
long_description = '{}\n{}'.format(read('README.rst'), read('CHANGES.txt'))
5664

65+
# Dependencies.
66+
with open('requirements.txt') as f:
67+
tests_require = f.readlines()
68+
install_requires = [t.strip() for t in tests_require]
69+
70+
5771
config = dict(name='folium',
58-
version=version,
72+
version=extract_version(),
5973
description='Make beautiful maps with Leaflet.js & Python',
6074
long_description=long_description,
6175
author='Rob Story',
6276
author_email='[email protected]',
63-
license='MIT License',
6477
url='https://github.com/python-visualization/folium',
6578
keywords='data visualization',
6679
classifiers=['Development Status :: 4 - Beta',
@@ -70,16 +83,11 @@ def walk_subpkg(name):
7083
'License :: OSI Approved :: MIT License'],
7184
packages=pkgs,
7285
package_data=pkg_data,
86+
cmdclass=dict(test=PyTest),
87+
tests_require=['pytest'],
88+
license=LICENSE,
89+
install_requires=install_requires,
7390
zip_safe=False)
7491

7592

76-
if sys.argv[-1] == 'publish':
77-
os.system("python setup.py sdist upload")
78-
print("Remember to also tag the version.")
79-
sys.exit()
80-
elif sys.argv[-1] == 'tag':
81-
os.system("git tag -a %s -m 'version %s'" % (version, version))
82-
os.system("git push --tags")
83-
sys.exit()
84-
8593
setup(**config)

0 commit comments

Comments
 (0)