Skip to content

Commit

Permalink
#328 added tests for example command line
Browse files Browse the repository at this point in the history
* fixed: date not defined when not required causes failure
  • Loading branch information
IanGrimstead authored and IanGrimstead committed Sep 24, 2019
1 parent 4db6fb8 commit 635d689
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ install:
- python -m easy_install -U setuptools
# command to install dependencies
# - python setup.py install
- pip install -e .
- pip install -e .[test]

script:
# for codecov support
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ install:
- python -m pip install -U pip
- python -m easy_install -U setuptools
# command to install dependencies
- python setup.py install
- pip install -e .[test]
# also need to download punkt tokeniser data
- python -m nltk.downloader punkt averaged_perceptron_tagger wordnet

Expand Down
14 changes: 9 additions & 5 deletions scripts/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ def __init__(self, data_filename, docs_mask_dict, pick_method='sum', ngram_range
f'to {number_of_ngrams_after:,}')

self.__cpc_dict = utils.cpc_dict(dataframe)
self.__dates = scripts.utils.date_utils.generate_year_week_dates(dataframe, docs_mask_dict['date_header'])

min_date = min(self.__dates)
max_date = max(self.__dates)
if docs_mask_dict['date_header'] is None:
self.__cached_folder_name = path.join('cached', output_name + f'-mdf-{max_df}')
self.__dates = None
else:
self.__dates = scripts.utils.date_utils.generate_year_week_dates(dataframe,
docs_mask_dict['date_header'])
min_date = min(self.__dates)
max_date = max(self.__dates)
self.__cached_folder_name = path.join('cached', output_name + f'-mdf-{max_df}-{min_date}-{max_date}')

self.__cached_folder_name = path.join('cached', output_name + f'-mdf-{max_df}-{min_date}-{max_date}')
utils.pickle_object('tfidf', self.__tfidf_obj, self.__cached_folder_name)
utils.pickle_object('dates', self.__dates, self.__cached_folder_name)
utils.pickle_object('cpc_dict', self.__cpc_dict, self.__cached_folder_name)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def setup_package():
'xlrd', 'python-Levenshtein', 'gensim==3.4.0', 'statsmodels', 'keras', 'tensorflow',
'keras_tqdm', 'patsy', 'humanfriendly', 'psutil', 'jinja2', 'urllib3==1.22'],
# extras_require={'dev': ['check-manifest'],'test': ['coverage'],},
extras_require={'test': ['pytest']},
python_requires='>=3.6',
cmdclass={
'install': CustomInstaller,
Expand Down
30 changes: 30 additions & 0 deletions tests/test_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import unittest

import pytest

import pygrams


@pytest.mark.skipif('TRAVIS' not in os.environ, reason="Only execute with Travis due to speed")
class TestReadme(unittest.TestCase):
"""
Batch of tests to execute same commands as mentioned in the README.md, to ensure they work without crashing
"""

def test_no_arguments_and_use_cache(self):
# clear cached result
import shutil
shutil.rmtree(os.path.join('cached', 'out-mdf-0.05'), ignore_errors=True)

# should make cache
pygrams.main([])

# load cache
pygrams.main(['-uc', 'out-mdf-0.05'])

def test_10000_patents(self):
pygrams.main(['-ds', 'USPTO-random-10000.pkl.bz2'])

def test_mn_mx(self):
pygrams.main(['-mn', '1', '-mx', '3'])

0 comments on commit 635d689

Please sign in to comment.