deckard_pytest.py 1.53 KB
Newer Older
1 2 3 4 5
import logging
import os
import subprocess
import sys

6
import pytest
7

8 9
import deckard

10 11 12 13 14

def set_coverage_env(path, qmin):
    """Sets up enviroment variables so code coverage utility can work."""
    if os.environ.get("COVERAGE"):
        exports = subprocess.check_output([os.environ["COVERAGE_ENV_SCRIPT"],
15
                                           os.environ["DAEMONSRCDIR"],
16 17 18
                                           os.environ["COVERAGE_STATSDIR"],
                                           path + "-qmin-" + str(qmin)]).decode()
        for export in exports.split():
19 20
            key, value = export.split("=", 1)
            value = value.strip('"')
21 22 23 24 25 26 27
            os.environ[key] = value


def check_platform():
    if sys.platform == 'windows':
        pytest.exit('Not supported at all on Windows')

Tomas Krizek's avatar
Tomas Krizek committed
28

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
# Suppress extensive Augeas logging
logging.getLogger("augeas").setLevel(logging.ERROR)


check_platform()


def run_test(path, qmin, config):
    set_coverage_env(path, qmin)
    try:
        del os.environ["SOCKET_WRAPPER_DIR"]
    except KeyError:
        pass
    deckard.process_file(path, qmin, config)


45
def test_passes_qmin_on(scenario):
46
    if scenario.qmin is True or scenario.qmin is None:
47
        run_test(scenario.path, True, scenario.config)
48 49 50 51
    else:
        pytest.skip("Query minimization is off in test config")


52
def test_passes_qmin_off(scenario):
53
    if scenario.qmin is False or scenario.qmin is None:
54
        run_test(scenario.path, False, scenario.config)
55 56
    else:
        pytest.skip("Query minimization is on in test config")