test.unit.test_download.test_main()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 21
rs 9.85
c 0
b 0
f 0
cc 1
nop 0
1
# coding=utf-8
2
3
"""
4
Tests for deepreg/download.py
5
pytest style
6
"""
7
import os
8
import shutil
9
from filecmp import dircmp
10
11
from git import Repo
12
13
from deepreg.download import main
14
15
16
def has_diff_files(dcmp):
17
    if len(dcmp.diff_files) > 0:
18
        return True
19
    for sub_dcmp in dcmp.subdirs.values():
20
        has_diff_files(sub_dcmp)
21
    return False
22
23
24
def test_download():
25
    # Covered by test_main
26
    pass
27
28
29
def test_main():
30
    """
31
    Integration test by checking the output dirs and files exist
32
    """
33
34
    temp_dir = "./deepreg_download_temp_dir"
35
    branch = Repo(".").head.object.hexsha
36
37
    main(args=["--output_dir", temp_dir, "--branch", branch])
38
39
    # Check downloading all req'd folders into temp, verify that they are the same as in main branch.
40
    config_dcmp = dircmp("./config", os.path.join(temp_dir, "config"))
41
    assert not has_diff_files(config_dcmp)
42
43
    data_dcmp = dircmp("./data", os.path.join(temp_dir, "data"))
44
    assert not has_diff_files(data_dcmp)
45
46
    demos_dcmp = dircmp("./demos", os.path.join(temp_dir, "demos"))
47
    assert not has_diff_files(demos_dcmp)
48
49
    shutil.rmtree(temp_dir)
50