This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
d87f65a
commit c674e14
Showing
4 changed files
with
79 additions
and
6 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
Empty file.
Empty file.
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os | ||
import tempfile | ||
from pathlib import Path | ||
|
||
import pytest | ||
from safeds.data.labeled.containers import ImageDataset | ||
|
||
from safeds_datasets.image import load_mnist, _mnist, load_fashion_mnist, load_kmnist | ||
|
||
|
||
class TestMNIST: | ||
|
||
def test_should_download_and_return_mnist(self): | ||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
train, test = load_mnist(tmpdirname, True) | ||
files = os.listdir(Path(tmpdirname) / _mnist._mnist._mnist_folder) | ||
for mnist_file in _mnist._mnist._mnist_files.values(): | ||
assert mnist_file in files | ||
assert isinstance(train, ImageDataset) | ||
assert isinstance(test, ImageDataset) | ||
assert len(train) == 60_000 | ||
assert len(test) == 10_000 | ||
train_output = train.get_output() | ||
test_output = test.get_output() | ||
assert set(train_output.get_unique_values()) == set(test_output.get_unique_values()) == set(_mnist._mnist._mnist_labels.values()) | ||
|
||
def test_should_raise_if_file_not_found(self): | ||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
with pytest.raises(FileNotFoundError): | ||
load_mnist(tmpdirname, False) | ||
|
||
|
||
class TestFashionMNIST: | ||
|
||
def test_should_download_and_return_mnist(self): | ||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
train, test = load_fashion_mnist(tmpdirname, True) | ||
files = os.listdir(Path(tmpdirname) / _mnist._mnist._fashion_mnist_folder) | ||
for mnist_file in _mnist._mnist._fashion_mnist_files.values(): | ||
assert mnist_file in files | ||
assert isinstance(train, ImageDataset) | ||
assert isinstance(test, ImageDataset) | ||
assert len(train) == 60_000 | ||
assert len(test) == 10_000 | ||
train_output = train.get_output() | ||
test_output = test.get_output() | ||
assert set(train_output.get_unique_values()) == set(test_output.get_unique_values()) == set(_mnist._mnist._fashion_mnist_labels.values()) | ||
|
||
def test_should_raise_if_file_not_found(self): | ||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
with pytest.raises(FileNotFoundError): | ||
load_fashion_mnist(tmpdirname, False) | ||
|
||
|
||
class TestKMNIST: | ||
|
||
def test_should_download_and_return_mnist(self): | ||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
train, test = load_kmnist(tmpdirname, True) | ||
files = os.listdir(Path(tmpdirname) / _mnist._mnist._kuzushiji_mnist_folder) | ||
for mnist_file in _mnist._mnist._kuzushiji_mnist_files.values(): | ||
assert mnist_file in files | ||
assert isinstance(train, ImageDataset) | ||
assert isinstance(test, ImageDataset) | ||
assert len(train) == 60_000 | ||
assert len(test) == 10_000 | ||
train_output = train.get_output() | ||
test_output = test.get_output() | ||
assert set(train_output.get_unique_values()) == set(test_output.get_unique_values()) == set(_mnist._mnist._kuzushiji_mnist_labels.values()) | ||
|
||
def test_should_raise_if_file_not_found(self): | ||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
with pytest.raises(FileNotFoundError): | ||
load_kmnist(tmpdirname, False) |