Skip to content

Commit

Permalink
Switch to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
aaront committed Feb 2, 2017
1 parent a5ccc6f commit 1c70534
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 44 deletions.
6 changes: 3 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ machine:

dependencies:
override:
- pip install nose coverage
- pip install -r dev-requirements.txt
- pip install -r requirements.txt

test:
override:
- nosetests --with-coverage --with-xunit --xunit-file=$CIRCLE_TEST_REPORTS/nose-results.xml
- py.test --cov-config .coveragerc --cov-report xml:$CIRCLE_TEST_REPORTS/coverage.xml --cov puckdb --junitxml $CIRCLE_TEST_REPORTS/test-results.xml tests/
post:
- bash <(curl -s https://codecov.io/bash)
- bash <(curl -s https://codecov.io/bash)
5 changes: 3 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mypy-lang==0.4.6
nose==1.3.7
pytest==3.0.6
pytest-cov==2.4.0
jedi==0.9.0
coverage==4.3.4
typed-ast==0.6.3
typed-ast==0.6.3
1 change: 1 addition & 0 deletions puckdb/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def create(dsn=None):
engine = sa.create_engine(dsn or connect_str)
metadata.drop_all(engine)
metadata.create_all(engine)
return engine


def drop(dsn=None):
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ click-datetime==0.2
python-dateutil==2.6.0
pytz==2016.10
sqlalchemy>1.1
ujson==1.35
ujson==1.35
mlalchemy==0.2.1
12 changes: 5 additions & 7 deletions tests/test_db.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import unittest

from puckdb import db


class TestModelEvents(unittest.TestCase):
class TestModelEvents:
def test_type_parser(self):
self.assertEqual(db.EventType.blocked_shot, db.Event.parse_type('BLOCKED_SHOT'))
self.assertEqual(db.EventType.shot, db.Event.parse_type('SHOT'))
self.assertIsNone(db.Event.parse_type('GAME_SCHEDULED')) # not tracked
self.assertIsNone(db.Event.parse_type('NON_SENSE'))
assert db.EventType.blocked_shot == db.Event.parse_type('BLOCKED_SHOT')
assert db.EventType.shot == db.Event.parse_type('SHOT')
assert db.Event.parse_type('GAME_SCHEDULED') is None # not tracked
assert db.Event.parse_type('NON_SENSE') is None
28 changes: 16 additions & 12 deletions tests/test_fetch.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import asyncio
import unittest
from datetime import datetime

import pytest

from puckdb import db, fetch


class TestAsyncScraper(unittest.TestCase):
def setUp(self):
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(None)
db.create()
@pytest.fixture(scope='session')
def database():
yield db.create()
db.drop()


def tearDown(self):
db.drop()
@pytest.fixture(scope='session')
def loop():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(None)
yield loop


class TestFetch(TestAsyncScraper):
def test_game_urls(self):
class TestFetch:
def test_game_urls(self, database, loop):
date = datetime(2016, 2, 23)
games = fetch.games(date, date, loop=self.loop)
games = fetch.games(date, date, loop=loop)
# TODO: Look up games from DB
# self.assertEqual(9, len(games))
# assert len(games) == 9
37 changes: 18 additions & 19 deletions tests/test_query.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
import unittest
from datetime import datetime

from puckdb import query


class TestGameQuery(unittest.TestCase):
class TestGameQuery:
def test_one_season_range(self):
from_date = datetime(2014, 10, 22)
to_date = datetime(2015, 4, 1)
game_query = query.GameQuery(from_date=from_date, to_date=to_date)
seasons = game_query.by_season()
self.assertEqual(1, len(seasons))
self.assertEqual('20142015', seasons[0])
assert len(seasons) == 1
assert seasons[0] == '20142015'

def test_season_before_range(self):
from_date = datetime(2014, 4, 22)
to_date = datetime(2015, 4, 1)
game_query = query.GameQuery(from_date=from_date, to_date=to_date)
seasons = game_query.by_season()
self.assertEqual(2, len(seasons))
self.assertEqual('20132014', seasons[0])
self.assertEqual('20142015', seasons[1])
assert len(seasons) == 2
assert seasons[0] == '20132014'
assert seasons[1] == '20142015'

def test_season_after_range(self):
from_date = datetime(2014, 10, 22)
to_date = datetime(2015, 9, 1)
game_query = query.GameQuery(from_date=from_date, to_date=to_date)
seasons = game_query.by_season()
self.assertEqual(2, len(seasons))
self.assertEqual('20142015', seasons[0])
self.assertEqual('20152016', seasons[1])
assert len(seasons) == 2
assert seasons[0] == '20142015'
assert seasons[1] == '20152016'

def test_days(self):
from_date = datetime(2015, 10, 22)
to_date = datetime(2015, 10, 30)
game_query = query.GameQuery(from_date=from_date, to_date=to_date)
days = game_query.intervals
self.assertEqual(9, len(days))
self.assertEqual(datetime(2015, 10, 22), days[0].start)
self.assertEqual(datetime(2015, 10, 22), days[0].end)
assert len(days) == 9
assert days[0].start == datetime(2015, 10, 22)
assert days[0].end == datetime(2015, 10, 22)

def test_weeks(self):
from_date = datetime(2015, 10, 22)
to_date = datetime(2016, 2, 23)
game_query = query.GameQuery(from_date=from_date, to_date=to_date)
weeks = game_query.intervals
self.assertEqual(18, len(weeks))
self.assertEqual(datetime(2015, 10, 22), weeks[0].start)
self.assertEqual(datetime(2015, 10, 28), weeks[0].end)
assert len(weeks) == 18
assert weeks[0].start == datetime(2015, 10, 22)
assert weeks[0].end == datetime(2015, 10, 28)

def test_months(self):
from_date = datetime(2013, 10, 22)
to_date = datetime(2016, 2, 23)
game_query = query.GameQuery(from_date=from_date, to_date=to_date)
months = game_query.intervals
self.assertEqual(29, len(months))
self.assertEqual(datetime(2013, 10, 22), months[0].start)
self.assertEqual(datetime(2013, 11, 21), months[0].end)
assert len(months) == 29
assert months[0].start == datetime(2013, 10, 22)
assert months[0].end == datetime(2013, 11, 21)

0 comments on commit 1c70534

Please sign in to comment.