Oscar Pocock
523f518aa8
A few changes: - Added report - Added mid project demo content - Added README.txt - Added Experiments - Added ratings.txt file - Added unit tests - Simplified the prediction code - Added single prediction
35 lines
No EOL
1.2 KiB
Python
35 lines
No EOL
1.2 KiB
Python
from autophotographer.cnn import dataset
|
|
from unittest import mock
|
|
import pytest
|
|
import pandas as pd
|
|
|
|
@mock.patch("pandas.read_csv")
|
|
def test_calculate_image_rating_with_no_ratings(mock_read_csv):
|
|
testEntry = "1 1 0 0 0 0 0 0 0 0 0 0 -1 -1 -1"
|
|
testEntry = testEntry.split()
|
|
testEntry = list(map(int, testEntry))
|
|
df = pd.DataFrame([testEntry])
|
|
mock_read_csv.return_value = df
|
|
index = 1
|
|
assert dataset.calculate_image_rating(index) == 0
|
|
|
|
@mock.patch("pandas.read_csv")
|
|
def test_calculate_image_rating_multiple_ratings(mock_read_csv):
|
|
testEntry = "1 1 1 2 3 4 5 6 7 8 9 10 -1 -1 -1"
|
|
testEntry = testEntry.split()
|
|
testEntry = list(map(int, testEntry))
|
|
df = pd.DataFrame([testEntry])
|
|
mock_read_csv.return_value = df
|
|
index = 1
|
|
assert dataset.calculate_image_rating(index) == 7
|
|
|
|
@mock.patch("pandas.read_csv")
|
|
def test_calculate_image_rating_incorrect_number_of_columns(mock_read_csv):
|
|
with pytest.raises(ValueError):
|
|
testEntry = "1 1 1 2 3 4 5 6 7 8 9 10 -1 -1 -1 9 9 9"
|
|
testEntry = testEntry.split()
|
|
testEntry = list(map(int, testEntry))
|
|
df = pd.DataFrame([testEntry])
|
|
mock_read_csv.return_value = df
|
|
index = 1
|
|
assert dataset.calculate_image_rating(index) |