File: conftest.py

package info (click to toggle)
wsclean 3.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,296 kB
  • sloc: cpp: 129,246; python: 22,066; sh: 360; ansic: 230; makefile: 185
file content (101 lines) | stat: -rw-r--r-- 2,962 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import os
import shutil
import sys
from subprocess import check_call

import pytest

# Append current directory to system path in order to import testconfig
sys.path.append(".")

# Import configuration variables as test configuration (tcf)
import config_vars as tcf


@pytest.fixture(scope="session", autouse=True)
def prepare_workdir():
    # Changes to directory containing the data.
    # Optionally removes the entire working directory
    # at the end of a test session. Use with care!
    cwd = os.getcwd()
    os.makedirs(tcf.WORKING_DIR, exist_ok=True)
    os.chdir(tcf.WORKING_DIR)
    os.makedirs(tcf.RESULTS_DIR, exist_ok=True)

    # Download and untar beam pattern file
    if not os.path.isfile(tcf.MWA_COEFF_FILE):
        check_call(
            [
                "wget",
                "-q",
                os.path.join(tcf.EVERYBEAM_DATA_URL, tcf.MWA_COEFF_ARCHIVE),
            ]
        )
        check_call(["tar", "xf", tcf.MWA_COEFF_ARCHIVE])

    yield

    if (
        "CLEANUP_WSCLEAN_TESTS" in os.environ
        and int(os.environ["CLEANUP_WSCLEAN_TESTS"]) == 1
    ):
        os.chdir(cwd)
        shutil.rmtree(tcf.WORKING_DIR)


@pytest.fixture(scope="class")
def prepare_large_ms():
    if not os.path.isfile(f"{tcf.MWA_MS}/table.f1"):
        check_call(
            [
                "wget",
                "-q",
                os.path.join(tcf.IDG_DATA_URL, f"{tcf.MWA_MS}.tgz"),
            ]
        )
        check_call(["tar", "-xf", f"{tcf.MWA_MS}.tgz"])
        os.remove(f"{tcf.MWA_MS}.tgz")
    else:
        pass


@pytest.fixture(scope="class")
def prepare_mock_ms():
    os.makedirs(tcf.MWA_MOCK_MS, exist_ok=True)

    if not os.path.isfile(tcf.MWA_MOCK_ARCHIVE):
        url = os.path.join(
            tcf.EVERYBEAM_DATA_URL, "MWA-single-timeslot.tar.bz2"
        )
        check_call(f"wget -q {url} -O {tcf.MWA_MOCK_ARCHIVE}".split())
        check_call(
            f"tar -xf {tcf.MWA_MOCK_ARCHIVE} -C {tcf.MWA_MOCK_MS} --strip-components=1".split()
        )

    # From python 3.8 onwards, use copytree(..., dirs_exist_ok=True)
    if not os.path.isdir(tcf.MWA_MOCK_FULL):
        shutil.copytree(tcf.MWA_MOCK_MS, tcf.MWA_MOCK_FULL)

    if not os.path.isdir(tcf.MWA_MOCK_FACET):
        shutil.copytree(tcf.MWA_MOCK_MS, tcf.MWA_MOCK_FACET)


@pytest.fixture(scope="function")
def tmp_mwa_mock_facet(tmp_path):
    mwa_mock_facet_path = tmp_path / tcf.MWA_MOCK_FACET
    shutil.copytree(tcf.MWA_MOCK_FACET, mwa_mock_facet_path)
    return mwa_mock_facet_path


@pytest.fixture(scope="class")
def prepare_model_image():
    if not os.path.isfile(tcf.MODEL_IMAGE):
        wget = f"wget -q {os.path.join(tcf.WSCLEAN_DATA_URL, tcf.MODEL_IMAGE)}"
        check_call(wget.split())


@pytest.fixture(scope="class")
def prepare_mock_soltab():
    if not os.path.isfile(tcf.MOCK_SOLTAB_2POL):
        wget = f"wget -q {os.path.join(tcf.WSCLEAN_DATA_URL, tcf.MOCK_SOLTAB_2POL)}"
        check_call(wget.split())