# 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 pandas as pd
import pathlib
import pytest
from matplotlib.figure import Figure
from paratemp.tools import cd
    from paratemp.energy_bin_analysis import get_energies
    from paratemp.energy_bin_analysis import get_energies
    from paratemp.energy_bin_analysis import make_energy_component_plots
    from paratemp.energy_histo import make_indices
        from paratemp.energy_bin_analysis import deconvolve_energies

def test_get_energies(pt_run_dir):
    # Doesn't currently test:
    #    content of the outputs
    with cd(pt_run_dir):
        mi_df = get_energies('PT-out')
    assert len(mi_df.index.levels[0]) == 2
    assert isinstance(mi_df, pd.DataFrame)
    assert isinstance(mi_df.index, pd.MultiIndex)


@pytest.fixture
def energies_df(pt_run_dir):
    with cd(pt_run_dir):
        mi_df = get_energies('PT-out')
    return mi_df


def test_make_energy_component_plots(energies_df):
    fig = make_energy_component_plots(energies_df, 'Pressure', display=True)
    assert isinstance(fig, Figure)
    fig = make_energy_component_plots(energies_df, 'Pressure', display=False)
    assert fig is None


@pytest.fixture
def replica_temp_path(pt_run_dir: pathlib.PosixPath):
    # Doesn't currently test:
    #    content of the outputs
    #    what happens if they already exist

# 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_bin_analysis.py
import pandas as pd
import pathlib
import pytest
from matplotlib.figure import Figure
from paratemp.tools import cd
    from paratemp.energy_bin_analysis import get_energies
    from paratemp.energy_bin_analysis import get_energies
    from paratemp.energy_bin_analysis import make_energy_component_plots
    from paratemp.energy_histo import make_indices
        from paratemp.energy_bin_analysis import deconvolve_energies


def test_get_energies(pt_run_dir):
    # Doesn't currently test:
    #    content of the outputs
    with cd(pt_run_dir):
        mi_df = get_energies('PT-out')
    assert len(mi_df.index.levels[0]) == 2
    assert isinstance(mi_df, pd.DataFrame)
    assert isinstance(mi_df.index, pd.MultiIndex)


@pytest.fixture
def energies_df(pt_run_dir):
    with cd(pt_run_dir):
        mi_df = get_energies('PT-out')
    return mi_df


def test_make_energy_component_plots(energies_df):
    fig = make_energy_component_plots(energies_df, 'Pressure', display=True)
    assert isinstance(fig, Figure)
    fig = make_energy_component_plots(energies_df, 'Pressure', display=False)
    assert fig is None


@pytest.fixture
def replica_temp_path(pt_run_dir: pathlib.PosixPath):
    # Doesn't currently test:
    #    content of the outputs
    #    what happens if they already exist

    with cd(pt_run_dir):