diff --git a/circle.yml b/circle.yml index 08f1adc..9988394 100644 --- a/circle.yml +++ b/circle.yml @@ -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) \ No newline at end of file + - bash <(curl -s https://codecov.io/bash) diff --git a/dev-requirements.txt b/dev-requirements.txt index 60b3264..bd3fee3 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -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 \ No newline at end of file +typed-ast==0.6.3 diff --git a/puckdb/db.py b/puckdb/db.py index dad3aa0..b081387 100644 --- a/puckdb/db.py +++ b/puckdb/db.py @@ -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): diff --git a/requirements.txt b/requirements.txt index 8453bfb..ef79345 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ click-datetime==0.2 python-dateutil==2.6.0 pytz==2016.10 sqlalchemy>1.1 -ujson==1.35 \ No newline at end of file +ujson==1.35 +mlalchemy==0.2.1 \ No newline at end of file diff --git a/tests/test_db.py b/tests/test_db.py index 6581ed8..cfef53d 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -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 diff --git a/tests/test_fetch.py b/tests/test_fetch.py index 9cee83e..cdd31b6 100644 --- a/tests/test_fetch.py +++ b/tests/test_fetch.py @@ -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 diff --git a/tests/test_query.py b/tests/test_query.py index d35ffa8..1704a6d 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -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)