# 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 numpy as np
import pathlib
import re
from paratemp.tools import cd
    from paratemp.energy_histo import find_energies
    from paratemp.energy_histo import make_indices
        from paratemp.energy_histo import import_energies, find_energies
def test_find_energies(pt_run_dir: pathlib.PosixPath):
    # Doesn't currently test:
    #    content of the outputs
    #    what happens if they already exist
    with cd(pt_run_dir):
        l_xvgs = find_energies()
    for xvg in l_xvgs:
        assert pt_run_dir.joinpath(xvg).exists()
        assert re.match(r'energy[01].xvg', xvg)
    assert len(l_xvgs) == 2


def test_make_indices(pt_run_dir: pathlib.PosixPath):
    # Doesn't currently test:
    #    content of the outputs
    #    what happens if they already exist
    with cd(pt_run_dir):
        make_indices('PT-out0.log')
    assert pt_run_dir.joinpath('replica_temp.xvg').exists()
    assert pt_run_dir.joinpath('replica_index.xvg').exists()
    assert pt_run_dir.joinpath('demux.pl.log').exists()


class TestImportEnergies(object):
    # Doesn't currently test:
    #    content of the outputs
    #    what happens if they don't exist
    #    any modes of failure
    #    return_lengths=True
    def test_import_energies(self, pt_run_dir: pathlib.PosixPath):

# 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_energy_histo.py
import numpy as np
import pathlib
import re
from paratemp.tools import cd
    from paratemp.energy_histo import find_energies
    from paratemp.energy_histo import make_indices
        from paratemp.energy_histo import import_energies, find_energies

def test_find_energies(pt_run_dir: pathlib.PosixPath):
    # Doesn't currently test:
    #    content of the outputs
    #    what happens if they already exist
    with cd(pt_run_dir):
        l_xvgs = find_energies()
    for xvg in l_xvgs:
        assert pt_run_dir.joinpath(xvg).exists()
        assert re.match(r'energy[01].xvg', xvg)
    assert len(l_xvgs) == 2


def test_make_indices(pt_run_dir: pathlib.PosixPath):
    # Doesn't currently test:
    #    content of the outputs
    #    what happens if they already exist
    with cd(pt_run_dir):
        make_indices('PT-out0.log')
    assert pt_run_dir.joinpath('replica_temp.xvg').exists()
    assert pt_run_dir.joinpath('replica_index.xvg').exists()
    assert pt_run_dir.joinpath('demux.pl.log').exists()


class TestImportEnergies(object):
    # Doesn't currently test:
    #    content of the outputs
    #    what happens if they don't exist
    #    any modes of failure
    #    return_lengths=True
    def test_import_energies(self, pt_run_dir: pathlib.PosixPath):

        with cd(pt_run_dir):