"tests/git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "c3921599c80f692ec478bcf742481ddaa313f6dc"
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): ...@@ -40,7 +40,7 @@ def mkdir_or_exist(dir_name, mode=0o777):
os.makedirs(dir_name, mode=mode, exist_ok=True) os.makedirs(dir_name, mode=mode, exist_ok=True)
else: else:
if not osp.isdir(dir_name): 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): def symlink(src, dst, overwrite=True, **kwargs):
......
...@@ -2,6 +2,7 @@ from __future__ import division ...@@ -2,6 +2,7 @@ from __future__ import division
import mmcv import mmcv
import numpy as np import numpy as np
import pytest
def test_quantize(): def test_quantize():
...@@ -21,6 +22,13 @@ def test_quantize(): ...@@ -21,6 +22,13 @@ def test_quantize():
assert qarr.shape == arr.shape assert qarr.shape == arr.shape
assert qarr.dtype == np.dtype('uint8') 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(): def test_dequantize():
levels = 20 levels = 20
...@@ -37,6 +45,13 @@ def test_dequantize(): ...@@ -37,6 +45,13 @@ def test_dequantize():
assert arr.shape == qarr.shape assert arr.shape == qarr.shape
assert arr.dtype == np.dtype('float32') 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(): def test_joint():
arr = np.random.randn(100, 100) arr = np.random.randn(100, 100)
......
...@@ -4,13 +4,16 @@ import pytest ...@@ -4,13 +4,16 @@ import pytest
from mmcv import Config, FileNotFoundError from mmcv import Config, FileNotFoundError
def test_empty(): def test_construct():
cfg = Config() cfg = Config()
assert cfg.filename is None assert cfg.filename is None
assert cfg.text == '' assert cfg.text == ''
assert len(cfg) == 0 assert len(cfg) == 0
assert cfg._cfg_dict == {} assert cfg._cfg_dict == {}
with pytest.raises(TypeError):
Config([0, 1])
def test_fromfile(): def test_fromfile():
for filename in ['a.py', 'b.json', 'c.yaml']: for filename in ['a.py', 'b.json', 'c.yaml']:
...@@ -24,6 +27,8 @@ def test_fromfile(): ...@@ -24,6 +27,8 @@ def test_fromfile():
Config.fromfile('no_such_file.py') Config.fromfile('no_such_file.py')
with pytest.raises(ValueError): with pytest.raises(ValueError):
Config.fromfile(osp.join(osp.dirname(__file__), 'data/config/a.b.py')) 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(): def test_dict():
......
import os.path as osp import os.path as osp
import sys import sys
from pathlib import Path
import mmcv import mmcv
import pytest 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(): def test_check_file_exist():
mmcv.check_file_exist(__file__) mmcv.check_file_exist(__file__)
if sys.version_info > (3, 3): 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