# Path: postgraas_server/init_db.py
# def main():
# 
# Path: postgraas_server/backends/docker/create_db.py
# def create_db_container():
# def main():


from subprocess import check_call
from postgraas_server import init_db
from postgraas_server.backends.docker import create_db
import os
import pytest
import postgraas_server.backends.docker.postgres_instance_driver as pid



this_dir = os.path.dirname(__file__)


@pytest.yield_fixture
def cov_runner():
    # pretty hacky fixture to measure coverage of python scripts started as subprocess.
    # * run the script via 'coverage run', not via python
    # * move the created .coverage files to ../.. so they are merged with the others
    check_call("rm -f .coverage.*", shell=True, cwd=this_dir)

    def run(script):
        command = "coverage run --branch --source ../.. -p {}".format(script)
        check_call(command, cwd=this_dir, shell=True)

    yield run
    check_call("mv .coverage.* ../..", shell=True, cwd=this_dir)


def test_create_init_db(cov_runner):
    # test the standalone 'create_db' and 'init_db' scripts.

# Path: postgraas_server/init_db.py
# def main():
# 
# Path: postgraas_server/backends/docker/create_db.py
# def create_db_container():
# def main():


# Path: tests/test_integration/test_create_db.py
from subprocess import check_call
from postgraas_server import init_db
from postgraas_server.backends.docker import create_db
import os
import pytest
import postgraas_server.backends.docker.postgres_instance_driver as pid




this_dir = os.path.dirname(__file__)


@pytest.yield_fixture
def cov_runner():
    # pretty hacky fixture to measure coverage of python scripts started as subprocess.
    # * run the script via 'coverage run', not via python
    # * move the created .coverage files to ../.. so they are merged with the others
    check_call("rm -f .coverage.*", shell=True, cwd=this_dir)

    def run(script):
        command = "coverage run --branch --source ../.. -p {}".format(script)
        check_call(command, cwd=this_dir, shell=True)

    yield run
    check_call("mv .coverage.* ../..", shell=True, cwd=this_dir)


def test_create_init_db(cov_runner):
    # test the standalone 'create_db' and 'init_db' scripts.

    if pid.check_container_exists('postgraas_master_db'):