Skip to content

Commit

Permalink
Fixed linting
Browse files Browse the repository at this point in the history
Fixed Mock Test (pulled out to new file)
Skip certain files for testing.
  • Loading branch information
barbacbd committed Mar 19, 2024
1 parent 0f377e1 commit 8e27ce9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
source = tests
omit = __init__.py, mock.py
22 changes: 22 additions & 0 deletions tests/mock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# pylint: disable=invalid-name
# pylint: disable=missing-function-docstring
import pytest

pytestmark = pytest.mark.skip("Class created for testing purposes only.")


class MockResponse:
'''Class to mock the behavior and results of the requests.get function
in the findGamesByDate function.
'''

def __init__(self, data, status_code):
'''Fill the class with the required data for a response'''
self.data = data
self.code = status_code

def read(self):
return self.data

def json(self):
return self.data
17 changes: 1 addition & 16 deletions tests/test_ann.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from shutil import move, copy
from json import loads
import pandas as pd
from mock import MockResponse
from nhl_model.ann import (
CONFIG_FILE,
correctData,
Expand Down Expand Up @@ -59,22 +60,6 @@ def _moveConfigFileBack(moved):
if exists(_CONFIG_FILE_TEST_PATH):
move(_CONFIG_FILE_TEST_PATH, CONFIG_FILE)

class MockResponse:
'''Class to mock the behavior and results of the requests.get function
in the findGamesByDate function.
'''

def __init__(self, data, status_code):
'''Fill the class with the required data for a response'''
self.data = data
self.code = status_code

def read(self):
return self.data

def json(self):
return self.data


def mocked_requests_get(*args, **kwargs):
if args[0] == _createTodaysDateStr():
Expand Down
43 changes: 13 additions & 30 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# pylint: disable=invalid-name
# pylint: disable=missing-function-docstring
from unittest import TestCase, mock
from os import remove, mkdir
from os.path import dirname, abspath, join, exists
from datetime import datetime
from json import loads, dumps
from shutil import move
from nhl_core.endpoints import MAX_GAME_NUMBER
from mock import MockResponse
from nhl_model.dataset import (
parseBoxScore,
parseBoxScoreSplit,
Expand All @@ -11,12 +18,6 @@
newAPIFile,
BASE_SAVE_DIR
)
from nhl_core.endpoints import MAX_GAME_NUMBER
from os.path import dirname, abspath, join, exists
from json import loads, dumps
from datetime import datetime
from shutil import move
from os import remove, mkdir


def _movedFile(filename):
Expand All @@ -34,28 +35,11 @@ def _moveFileBack(filename, moved):
move(f"{filename}.old", filename)


class MockResponse:
'''Class to mock the behavior and results of the requests.get function
in the findGamesByDate function.
'''

def __init__(self, data, status_code):
'''Fill the class with the required data for a response'''
self.data = data
self.code = status_code

def read(self):
return self.data

def json(self):
return self.data


def mocked_requests_get(*args, **kwargs):
filename = join(dirname(abspath(__file__)), "DatasetMockData.json")
with open(filename, "r") as jsonFile:
jsonData = loads(jsonFile.read())

if jsonData is not None:
return MockResponse(jsonData, 200)
return MockResponse(jsonData, 400)
Expand All @@ -82,7 +66,7 @@ def setUpClass(cls):
cls.oldGameData = {
"gameId": oldGameInfo["game"]["pk"],
}

newFile = join(dirname(abspath(__file__)), "MockDataNew.json")
with open(newFile, "r") as jsonFile:
cls.newJsonData = loads(jsonFile.read())
Expand Down Expand Up @@ -254,7 +238,7 @@ def test_parse_boxscoresplit(self):
with self.subTest(f"Ensuring {key} is found and correct for away team", key=key, value=value):
self.assertTrue(key in awayTeamData)
self.assertEqual(value, awayTeamData[key])

def test_parse_boxscore_new(self):
'''Test the functionality of the parse box score for new datasets.'''
_expectedResults = {
Expand Down Expand Up @@ -408,7 +392,7 @@ def test_parse_boxscoresplit_new(self):
with self.subTest(f"Ensuring {key} is found and correct for away team (new)", key=key, value=value):
self.assertTrue(key in awayTeamData)
self.assertEqual(value, awayTeamData[key])

@mock.patch('requests.get', side_effect=mocked_requests_get)
def test_pull_dataset_api_new_base(self, mock_get):
'''Test pulling the dataset with the new api.'''
Expand Down Expand Up @@ -456,7 +440,7 @@ def test_pull_dataset_api_new_base(self, mock_get):

if expectedResult is None:
self.assertIsNone(currFilename)

remove(currFilename)
self.assertEqual(currFilename, expectedResult)

Expand Down Expand Up @@ -507,7 +491,6 @@ def test_pull_dataset_api_new_negative(self, mock_get):

if expectedResult is None:
self.assertIsNone(currFilename)

remove(currFilename)
self.assertEqual(currFilename, expectedResult)

0 comments on commit 8e27ce9

Please sign in to comment.