# Path: paratemp/tools.py
# @contextmanager
# def cd(new_dir):
#     prev_dir = os.getcwd()
#     os.chdir(os.path.expanduser(new_dir))
#     try:
#         yield
#     finally:
#         os.chdir(prev_dir)


import distutils.spawn
import errno
import os
import pathlib
import pytest
import shutil
from paratemp.tools import cd
        from paratemp.sim_setup import compile_tprs
        from paratemp.tools import get_temperatures
        from paratemp.sim_setup import compile_tprs
        from paratemp.tools import get_temperatures
        from paratemp.sim_setup import compile_tprs
        from paratemp.sim_setup import compile_tprs
        from paratemp.sim_setup import compile_tprs
        from paratemp.tools import get_temperatures
        from paratemp.sim_setup.para_temp_setup import \
            _add_cpt_to_sub_script as acpt
        from paratemp.sim_setup.para_temp_setup import \
            _add_cpt_to_sub_script as acpt
        from paratemp.sim_setup.para_temp_setup import \
            _add_cpt_to_sub_script as acpt
        from paratemp.sim_setup.para_temp_setup import \
            _add_cpt_to_sub_script as acpt
        from paratemp.sim_setup.para_temp_setup import _find_cpt_base
        from paratemp.sim_setup.para_temp_setup import _find_cpt_base
        files_present = {f.name for f in pt_blank_dir.glob('*')}
        must_contain = {n_top, n_gro, n_template, n_ndx, n_gro_o1, n_gro_o2}
        assert must_contain - files_present == set()

    def test_basic(self, pt_blank_dir, grompp):
        """

        :param pathlib.PosixPath pt_blank_dir:
        :return:
        """
        dir_topo = pt_blank_dir.joinpath('TOPO')
        dir_topo.mkdir()
        number = 2
        with cd(dir_topo):
            compile_tprs(start_temp=298, scaling_exponent=0.025,
                         number=number,
                         template='../'+n_template,
                         structure='../'+n_gro,
                         base_name='nvt',
                         grompp_exe=grompp)
        assert dir_topo.exists()
        for i in range(number):
            assert dir_topo.joinpath('nvt{}.tpr'.format(i)).exists()
        assert get_temperatures(
            str(dir_topo.joinpath('temperatures.dat'))).shape == (2,)

    def test_multi_structure(self, pt_blank_dir, grompp):
        dir_topo = pt_blank_dir.joinpath('TOPO')
        dir_topo.mkdir()
        number = 2

# Path: paratemp/tools.py
# @contextmanager
# def cd(new_dir):
#     prev_dir = os.getcwd()
#     os.chdir(os.path.expanduser(new_dir))
#     try:
#         yield
#     finally:
#         os.chdir(prev_dir)


# Path: tests/test_sim_setup/test_para_temp_setup.py
import distutils.spawn
import errno
import os
import pathlib
import pytest
import shutil
from paratemp.tools import cd
        from paratemp.sim_setup import compile_tprs
        from paratemp.tools import get_temperatures
        from paratemp.sim_setup import compile_tprs
        from paratemp.tools import get_temperatures
        from paratemp.sim_setup import compile_tprs
        from paratemp.sim_setup import compile_tprs
        from paratemp.sim_setup import compile_tprs
        from paratemp.tools import get_temperatures
        from paratemp.sim_setup.para_temp_setup import \
            _add_cpt_to_sub_script as acpt
        from paratemp.sim_setup.para_temp_setup import \
            _add_cpt_to_sub_script as acpt
        from paratemp.sim_setup.para_temp_setup import \
            _add_cpt_to_sub_script as acpt
        from paratemp.sim_setup.para_temp_setup import \
            _add_cpt_to_sub_script as acpt
        from paratemp.sim_setup.para_temp_setup import _find_cpt_base
        from paratemp.sim_setup.para_temp_setup import _find_cpt_base

        files_present = {f.name for f in pt_blank_dir.glob('*')}
        must_contain = {n_top, n_gro, n_template, n_ndx, n_gro_o1, n_gro_o2}
        assert must_contain - files_present == set()

    def test_basic(self, pt_blank_dir, grompp):
        """

        :param pathlib.PosixPath pt_blank_dir:
        :return:
        """
        dir_topo = pt_blank_dir.joinpath('TOPO')
        dir_topo.mkdir()
        number = 2
        with cd(dir_topo):
            compile_tprs(start_temp=298, scaling_exponent=0.025,
                         number=number,
                         template='../'+n_template,
                         structure='../'+n_gro,
                         base_name='nvt',
                         grompp_exe=grompp)
        assert dir_topo.exists()
        for i in range(number):
            assert dir_topo.joinpath('nvt{}.tpr'.format(i)).exists()
        assert get_temperatures(
            str(dir_topo.joinpath('temperatures.dat'))).shape == (2,)

    def test_multi_structure(self, pt_blank_dir, grompp):
        dir_topo = pt_blank_dir.joinpath('TOPO')
        dir_topo.mkdir()
        number = 2

        with cd(dir_topo):