-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for the functions in utils.py (#63)
- Loading branch information
Showing
3 changed files
with
43 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ install: | |
- pip install -r test-requirements.txt | ||
script: | ||
- flake8 . | ||
- pytest ./tests/test_*.py |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
from tempfile import TemporaryDirectory | ||
import numpy as np | ||
from PIL import Image | ||
from autowebcompat import utils | ||
|
||
|
||
def test_get_bugs(): | ||
bugs = utils.get_bugs() | ||
assert(isinstance(bugs, list)) | ||
|
||
|
||
def test_mkdir(): | ||
d = TemporaryDirectory() | ||
direc_path = d.name + "/test" | ||
utils.mkdir(direc_path) | ||
assert(os.path.isdir(direc_path)) | ||
utils.mkdir(direc_path) | ||
|
||
|
||
def test_load_image(tmpdir): | ||
d = TemporaryDirectory() | ||
img = Image.new("RGB", (30, 30)) | ||
img.save(d.name + "/Image.jpg") | ||
img = utils.load_image("Image.jpg", d.name) | ||
assert(isinstance(img, np.ndarray)) | ||
assert(img.shape == (32, 24, 3)) | ||
|
||
|
||
def test_read_labels(): | ||
labels = utils.read_labels(file_name='labels.csv') | ||
assert(isinstance(labels, dict)) | ||
|
||
|
||
def test_write_labels(): | ||
label = {1: 1, 2: 2} | ||
d = TemporaryDirectory() | ||
file_path = d.name + "/test.csv" | ||
utils.write_labels(label, file_name=file_path) | ||
assert(os.path.exists(file_path)) |