"src/vscode:/vscode.git/clone" did not exist on "5939ace91bd090a2593b76f57707c104da427c51"
test_path.py 989 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
import os.path as osp
import sys

import mmcv
import pytest


def test_check_file_exist():
    mmcv.check_file_exist(__file__)
    if sys.version_info > (3, 3):
Kai Chen's avatar
Kai Chen committed
11
        with pytest.raises(FileNotFoundError):  # noqa
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
            mmcv.check_file_exist('no_such_file.txt')
    else:
        with pytest.raises(IOError):
            mmcv.check_file_exist('no_such_file.txt')


def test_scandir():
    folder = osp.join(osp.dirname(__file__), 'data/for_scan')
    filenames = ['a.bin', '1.txt', '2.txt', '1.json', '2.json']

    assert set(mmcv.scandir(folder)) == set(filenames)
    assert set(mmcv.scandir(folder, '.txt')) == set(
        [filename for filename in filenames if filename.endswith('.txt')])
    assert set(mmcv.scandir(folder, ('.json', '.txt'))) == set([
        filename for filename in filenames
        if filename.endswith(('.txt', '.json'))
    ])
    assert set(mmcv.scandir(folder, '.png')) == set()
    with pytest.raises(TypeError):
        mmcv.scandir(folder, 111)