Commit b98980b7 authored by Kai Chen's avatar Kai Chen
Browse files

add some unit tests

parent ecfce392
......@@ -40,7 +40,7 @@ def mkdir_or_exist(dir_name, mode=0o777):
os.makedirs(dir_name, mode=mode, exist_ok=True)
else:
if not osp.isdir(dir_name):
os.makedirs(dir_name, mode=0o777)
os.makedirs(dir_name, mode=mode)
def symlink(src, dst, overwrite=True, **kwargs):
......
......@@ -2,6 +2,7 @@ from __future__ import division
import mmcv
import numpy as np
import pytest
def test_quantize():
......@@ -21,6 +22,13 @@ def test_quantize():
assert qarr.shape == arr.shape
assert qarr.dtype == np.dtype('uint8')
with pytest.raises(ValueError):
mmcv.quantize(arr, -1, 1, levels=0)
with pytest.raises(ValueError):
mmcv.quantize(arr, -1, 1, levels=10.0)
with pytest.raises(ValueError):
mmcv.quantize(arr, 2, 1, levels)
def test_dequantize():
levels = 20
......@@ -37,6 +45,13 @@ def test_dequantize():
assert arr.shape == qarr.shape
assert arr.dtype == np.dtype('float32')
with pytest.raises(ValueError):
mmcv.dequantize(arr, -1, 1, levels=0)
with pytest.raises(ValueError):
mmcv.dequantize(arr, -1, 1, levels=10.0)
with pytest.raises(ValueError):
mmcv.dequantize(arr, 2, 1, levels)
def test_joint():
arr = np.random.randn(100, 100)
......
......@@ -4,13 +4,16 @@ import pytest
from mmcv import Config, FileNotFoundError
def test_empty():
def test_construct():
cfg = Config()
assert cfg.filename is None
assert cfg.text == ''
assert len(cfg) == 0
assert cfg._cfg_dict == {}
with pytest.raises(TypeError):
Config([0, 1])
def test_fromfile():
for filename in ['a.py', 'b.json', 'c.yaml']:
......@@ -24,6 +27,8 @@ def test_fromfile():
Config.fromfile('no_such_file.py')
with pytest.raises(ValueError):
Config.fromfile(osp.join(osp.dirname(__file__), 'data/config/a.b.py'))
with pytest.raises(IOError):
Config.fromfile(osp.join(osp.dirname(__file__), 'data/color.jpg'))
def test_dict():
......
import os.path as osp
import sys
from pathlib import Path
import mmcv
import pytest
def test_is_filepath():
assert mmcv.is_filepath(__file__)
assert mmcv.is_filepath('abc')
assert mmcv.is_filepath(Path('/etc'))
assert not mmcv.is_filepath(0)
def test_fopen():
assert hasattr(mmcv.fopen(__file__), 'read')
assert hasattr(Path(__file__), 'read')
def test_check_file_exist():
mmcv.check_file_exist(__file__)
if sys.version_info > (3, 3):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment