<commit_before># Licensed under a 3-clause BSD style license - see LICENSE.rst
import tempfile
import os
import numpy as np
import pytest

from .. import guide_stats

HAS_GS_TABLE = os.path.exists(guide_stats.TABLE_FILE)

@pytest.mark.skipif('not HAS_GS_TABLE', reason='Test requires guide stats table')
def test_read_stats():
    stats = guide_stats.get_stats()
    slot = stats[(stats['obsid'] == 5438) & (stats['slot'] == 5)][0]
    np.isclose(slot['dy_std'], 0.16008819321078668)
    np.isclose(slot['dz_std'], 0.23807435722775061)

HAS_OBSPAR_ARCHIVE = os.path.exists(
        guide_stats.mica.archive.obspar.CONFIG['data_root'])

@pytest.mark.skipif('not HAS_OBSPAR_ARCHIVE', reason='Test requires mica obspars')
def test_calc_stats():
    guide_stats.calc_stats(17210)

@pytest.mark.skipif('not HAS_OBSPAR_ARCHIVE', reason='Test requires mica obspars')
def test_calc_stats_with_bright_trans():
    s = guide_stats.calc_stats(17472)
    # Assert that the std on the slot 7 residuals are reasonable
    # even in this obsid that had a transition to BRIT
    assert s[1][7]['dr_std'] < 1

@pytest.mark.skipif('not HAS_OBSPAR_ARCHIVE', reason='Test requires mica obspars')
def test_make_gui_stats():
    """<commit_msg>Explicitly ignore warning on f_within_0.3 for now<commit_after># Licensed under a 3-clause BSD style license - see LICENSE.rst
import tempfile
import os
import numpy as np
import pytest

from .. import guide_stats

HAS_GS_TABLE = os.path.exists(guide_stats.TABLE_FILE)

@pytest.mark.skipif('not HAS_GS_TABLE', reason='Test requires guide stats table')
def test_read_stats():
    stats = guide_stats.get_stats()
    slot = stats[(stats['obsid'] == 5438) & (stats['slot'] == 5)][0]
    np.isclose(slot['dy_std'], 0.16008819321078668)
    np.isclose(slot['dz_std'], 0.23807435722775061)

HAS_OBSPAR_ARCHIVE = os.path.exists(
        guide_stats.mica.archive.obspar.CONFIG['data_root'])

@pytest.mark.skipif('not HAS_OBSPAR_ARCHIVE', reason='Test requires mica obspars')
def test_calc_stats():
    guide_stats.calc_stats(17210)

@pytest.mark.skipif('not HAS_OBSPAR_ARCHIVE', reason='Test requires mica obspars')
def test_calc_stats_with_bright_trans():
    s = guide_stats.calc_stats(17472)
    # Assert that the std on the slot 7 residuals are reasonable
    # even in this obsid that had a transition to BRIT
    assert s[1][7]['dr_std'] < 1


@pytest.mark.skipif('not HAS_OBSPAR_ARCHIVE', reason='Test requires mica obspars')
@pytest.mark.filterwarnings('ignore: object name')
def test_make_gui_stats():
    """
{'fraction_non_alphanumeric': 0.1212480252764613, 'fraction_numerical': 0.045813586097946286, 'mean_word_length': 5.238916256157635, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '231912', 'n_tokens_mistral': 973, 'n_tokens_neox': 895, 'n_words': 207}