Skip to content

Commit

Permalink
Merge pull request #70 from studentbrad/studentbrad/pytest
Browse files Browse the repository at this point in the history
Studentbrad/pytest
  • Loading branch information
Bradley Aaron Kohler authored Apr 17, 2020
2 parents 2691a42 + 7dc5b13 commit f791330
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ install:
before_script: 'flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics'
script:
- 'python -m jobfunnel -s demo/settings.yaml -o demo/'
- 'pytest --cov --cov-report=xml jobfunnel'
- 'pytest --cov=jobfunnel --cov-report=xml'
after_success:
- 'bash <(curl -s https://codecov.io/bash)'
2 changes: 1 addition & 1 deletion jobfunnel/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.1.4'
__version__ = '2.1.5'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
license = 'MIT License',
python_requires = '>=3.6.0',
install_requires = requires,
packages = find_packages(exclude=('demo',)),
packages = find_packages(exclude=('demo', 'tests')),
include_package_data = True,
entry_points = {'console_scripts': ['funnel = jobfunnel.__main__:main']})
File renamed without changes.
8 changes: 5 additions & 3 deletions jobfunnel/tests/conftest.py → tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pytest
from unittest.mock import patch
from ..config.parser import parse_config
from ..tools.tools import config_factory
import sys

from unittest.mock import patch

from jobfunnel.config.parser import parse_config
from jobfunnel.tools.tools import config_factory


@pytest.fixture()
def configure_options():
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions jobfunnel/tests/test_countries.py → tests/test_countries.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from typing import Union
from unittest.mock import patch

from ..config.parser import parse_config
from jobfunnel.config.parser import parse_config
from jobfunnel.indeed import Indeed
from jobfunnel.monster import Monster
from jobfunnel.glassdoor import GlassDoor

from ..indeed import Indeed
from ..monster import Monster
from ..glassdoor import GlassDoor

PROVIDERS = {'indeed': Indeed, 'monster': Monster, 'glassdoor': GlassDoor}

Expand Down
20 changes: 12 additions & 8 deletions jobfunnel/tests/test_filters.py → tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from ..tools.filters import tfidf_filter, id_filter, date_filter
import pytest

from collections import OrderedDict
from datetime import datetime, timedelta
from unittest.mock import patch

from jobfunnel.tools.filters import tfidf_filter, id_filter, date_filter


attr_list = [[['blurb'], 'Looking for a passionate team player that is willing to learn new technologies. Our company X is still growing at an exponential rate. In order to be a perfect fit'
' you must tell us your favorite movie at the interview; favorite food; and a fun fact about yourself. The ideal fit will also know Python and SDLC.'],
[['blurb'], 'Looking for a passionate developer that is willing to learn new technologies. Our company X is still growing at an exponential rate. In order to be a perfect fit'
Expand All @@ -14,13 +18,13 @@

def test_date_filter(per_id_job_listings):
new_job_listings = per_id_job_listings([attr_list[0], attr_list[1]])
# Assign two different dates to the job_postings
# assign two different dates to the job_postings
job_date = datetime.now() - timedelta(days=10)
new_job_listings['0']['date'] = job_date.strftime('%Y-%m-%d')
job_date = datetime.now() - timedelta(days=3)
new_job_listings['1']['date'] = job_date.strftime('%Y-%m-%d')
date_filter(new_job_listings, 5)
# Assert that that jobs older than 5 days have been removed
# assert that that jobs older than 5 days have been removed
assert list(new_job_listings) == ['1']


Expand All @@ -30,16 +34,16 @@ def test_id_filter(per_id_job_listings):
previous_job_listings = per_id_job_listings([attr_list[1], attr_list[3]])
id_filter(new_job_listings, previous_job_listings,
new_job_listings['0']['provider'])
# Assert that the new job listings have been removed since they already exist
# assert that the new job listings have been removed since they already exist
assert len(new_job_listings) == 0
# Assert that the correct job ids are in the new filtered new_job_listings
# assert that the correct job ids are in the new filtered new_job_listings
assert list(previous_job_listings) == ['0', '1']


def test_tfidf_filter_no_previous_scrape(per_id_job_listings):
new_job_listings = per_id_job_listings(attr_list[0:4])
tfidf_filter(new_job_listings)
# Assert that the correct job ids are in the new filtered new_job_listings
# assert that the correct job ids are in the new filtered new_job_listings
assert list(new_job_listings) == ['1', '3']


Expand All @@ -49,7 +53,7 @@ def test_tfidf_filter_with_previous_scrape(per_id_job_listings):
previous_job_listings = per_id_job_listings(
[attr_list[1], attr_list[3]], first_job_id=2)
tfidf_filter(new_job_listings, previous_job_listings)
# Assert that the new job listings have been removed since they already exist
# assert that the new job listings have been removed since they already exist
assert len(new_job_listings) == 0
# Assert that the correct job ids are in the new filtered new_job_listings
# assert that the correct job ids are in the new filtered new_job_listings
assert list(previous_job_listings) == ['2', '3']
11 changes: 6 additions & 5 deletions jobfunnel/tests/test_parse.py → tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import os
import yaml

from unittest.mock import patch
from pathlib import Path
from unittest.mock import patch

from jobfunnel.config.parser import parse_config, parse_cli, cli_to_yaml, update_yaml, check_config_types, log_levels

from ..config.parser import parse_config, parse_cli, cli_to_yaml, update_yaml, check_config_types, log_levels

config_dict = {
'output_path': 'fish',
Expand All @@ -25,7 +26,7 @@
}

cli_options = [
['', '-s', 'settins.yaml'],
['', '-s', 'settings.yaml'],
['', '-o', '.'],
['', '-kw', 'java', 'python'],
['', '-p', 'ON'],
Expand Down Expand Up @@ -70,7 +71,7 @@ def test_parse_cli_to_yaml_pass(option):
cli_to_yaml(cli)


# Create config fixture to avoid code duplication
# create config fixture to avoid code duplication

@pytest.fixture()
def config_dependency():
Expand All @@ -86,7 +87,7 @@ def setup(default_path='config/settings.yaml', patch_path=None):
"""
# find the jobfunnel root dir
jobfunnel_path = os.path.normpath(
os.path.join(os.path.dirname(__file__), '..'))
os.path.join(os.path.dirname(__file__), '../jobfunnel'))

# load the default settings
default_yaml_path = os.path.join(jobfunnel_path, default_path)
Expand Down
19 changes: 11 additions & 8 deletions jobfunnel/tests/test_tools.py → tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pytest

from dateutil.relativedelta import relativedelta
from datetime import datetime, timedelta

from ..tools.tools import split_url, proxy_dict_to_url, config_factory, post_date_from_relative_post_age, filter_non_printables
from jobfunnel.tools.tools import split_url, proxy_dict_to_url, config_factory, post_date_from_relative_post_age, filter_non_printables

from dateutil.relativedelta import relativedelta

URLS = [
{
Expand Down Expand Up @@ -67,8 +68,7 @@
[['some_option'], 'option_value']
]

# Test clean/dirty characters that may be on title and blurb fields

# test clean/dirty characters that may be on title and blurb fields

def test_filter_non_printables_clean_title(job_listings):
job_list = job_listings(attr_list[0:1])
Expand All @@ -93,8 +93,7 @@ def test_filter_non_printables_diryt_blurb(job_listings):
filter_non_printables(job_list[0])
assert job_list[0]['blurb'] == 'Develop and design software'

# Test job_listing dates with all possible formats

# test job_listing dates with all possible formats

def test_post_date_from_relative_post_age_just_posted_pass(job_listings):
job_list = job_listings(attr_list[4:5])
Expand All @@ -111,13 +110,17 @@ def test_post_date_from_relative_post_age_today_pass(job_listings):
def test_post_date_from_relative_post_age_1_hour_ago_pass(job_listings):
job_list = job_listings(attr_list[6:7])
post_date_from_relative_post_age(job_list)
assert datetime.now().strftime('%Y-%m-%d') == job_list[0]['date']
now = datetime.now()
assert now.strftime('%Y-%m-%d') == job_list[0]['date'] or \
(now - timedelta(days=int(1))).strftime('%Y-%m-%d') == job_list[0]['date']


def test_post_date_from_relative_post_age_2_hours_ago_pass(job_listings):
job_list = job_listings(attr_list[7:8])
post_date_from_relative_post_age(job_list)
assert datetime.now().strftime('%Y-%m-%d') == job_list[0]['date']
now = datetime.now()
assert now.strftime('%Y-%m-%d') == job_list[0]['date'] or \
(now - timedelta(days=int(1))).strftime('%Y-%m-%d') == job_list[0]['date']


def test_post_date_from_relative_ago_post_age_yesterday_ago_pass(job_listings):
Expand Down
16 changes: 8 additions & 8 deletions jobfunnel/tests/test_validate.py → tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

from unittest.mock import patch

from ..config.parser import parse_config
from ..config.validate import validate_config, validate_delay, validate_region
from ..tools.tools import config_factory
from jobfunnel.config.parser import parse_config
from jobfunnel.config.validate import validate_config, validate_delay, validate_region
from jobfunnel.tools.tools import config_factory


# define config dictionaries that are not valid
Expand All @@ -25,8 +25,8 @@
[['log_path'], 'data/jobfunnel_.log'],
[['filter_list_path'], 'data/filter_list_.json']
]
# Test all paths with invalid values

# test all paths with invalid values

def test_filter_list_path_fail(configure_options):
path_configs = config_factory(
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_delay_min_delay_fail(configure_options):
assert str(e.value) == '(min)_delay'


# Test validate_delay with a min_delay greater than delay
# test validate_delay with a min_delay greater than delay

def test_delay_min_delay_greater_than_delay_fail(configure_options):
delay_configs = config_factory(configure_options(['']), attr_list[5: 6])[0]
Expand All @@ -130,7 +130,7 @@ def test_delay_min_delay_greater_than_delay_fail(configure_options):
assert str(e.value) == '(min)_delay'


# Test validate_delay with a delay less than 10(the minimum)
# test validate_delay with a delay less than 10(the minimum)

def test_delay_less_than_10_fail(configure_options):
delay_configs = config_factory(configure_options(['']), attr_list[7: 8])[0]
Expand All @@ -139,7 +139,7 @@ def test_delay_less_than_10_fail(configure_options):
assert str(e.value) == '(min)_delay'


# Test validate_delay with the original configuration
# test validate_delay with the original configuration

def test_delay_pass(configure_options):
validate_delay(configure_options([''])['delay_config'])
Expand All @@ -155,7 +155,7 @@ def test_delay_max_listing_days_fail(configure_options):
assert str(e.value) == 'max_listing_days'


# Test the integration of all parts with the config as a whole
# test the integration of all parts with the config as a whole

@pytest.mark.parametrize('attribute', attr_list)
def test_config_fail(configure_options, attribute):
Expand Down

0 comments on commit f791330

Please sign in to comment.