-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
48 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |