Ma Zerun 1a7cebe4b9
[Refactor] Refactor unittest (#321)
* Refactor unit tests folder structure.

* Remove label smooth and Vit test in `test_classifiers.py`

* Rename test_utils in dataset to test_dataset_utils

* Split test_models/test_utils/test_utils.py to multiple sub files.

* Add unit tests of classifiers and heads

* Use patch context manager.

* Add unit test of `is_tracing`, and add warning in `is_tracing` if torch
verison is smaller than 1.6.0
2021-07-08 22:49:05 +08:00

22 lines
706 B
Python

import random
import string
import tempfile
from mmcls.datasets.utils import check_integrity, rm_suffix
def test_dataset_utils():
# test rm_suffix
assert rm_suffix('a.jpg') == 'a'
assert rm_suffix('a.bak.jpg') == 'a.bak'
assert rm_suffix('a.bak.jpg', suffix='.jpg') == 'a.bak'
assert rm_suffix('a.bak.jpg', suffix='.bak.jpg') == 'a'
# test check_integrity
rand_file = ''.join(random.sample(string.ascii_letters, 10))
assert not check_integrity(rand_file, md5=None)
assert not check_integrity(rand_file, md5=2333)
tmp_file = tempfile.NamedTemporaryFile()
assert check_integrity(tmp_file.name, md5=None)
assert not check_integrity(tmp_file.name, md5=2333)