<commit_before>import pandas as pd

from yandextank.plugins.Phantom.reader import PhantomReader, PhantomStatsReader


class TestPhantomReader(object):
    def test_read_all(self):
        reader = PhantomReader(
            'yandextank/plugins/Phantom/tests/phout.dat', cache_size=1024)
        df = pd.DataFrame()
        for chunk in reader:
            if chunk is None:
                reader.close()
            else:
                df = df.append(chunk)
        assert (len(df) == 200)
        assert (df['interval_real'].mean() == 11000714.0)

    def test_reader_closed(self):
        reader = PhantomReader('yandextank/plugins/Phantom/tests/phout.dat', cache_size=64)
        reader.close()
        frames = [i for i in reader]
        result = pd.concat(frames)
        assert len(result) == 200
        assert (result['interval_real'].mean() == 11000714.0)


class MockInfo(object):
    def __init__(self, steps):
        self.steps = steps


class TestStatsReader(object):

    def test_closed(self):
        STEPS = [[1.0, 1], [1.0, 1], [1.0, 1], [2.0, 1], [2.0, 1], [2.0, 1], [2.0, 1], [2.0, 1], [3.0, 1], [3.0, 1],
                 [3.0, 1], [3.0, 1], [3.0, 1], [4.0, 1], [4.0, 1], [4.0, 1], [4.0, 1], [4.0, 1], [5.0, 1], [5.0, 1],
                 [5.0, 1]]
        reader = PhantomStatsReader('yandextank/plugins/Phantom/tests/phantom_stat.dat',
                                    MockInfo(STEPS), cache_size=1024*10)
        reader.close()<commit_msg>pep8 correction<commit_after>import pandas as pd

from yandextank.plugins.Phantom.reader import PhantomReader, PhantomStatsReader


class TestPhantomReader(object):
    def test_read_all(self):
        reader = PhantomReader(
            'yandextank/plugins/Phantom/tests/phout.dat', cache_size=1024)
        df = pd.DataFrame()
        for chunk in reader:
            if chunk is None:
                reader.close()
            else:
                df = df.append(chunk)
        assert (len(df) == 200)
        assert (df['interval_real'].mean() == 11000714.0)

    def test_reader_closed(self):
        reader = PhantomReader('yandextank/plugins/Phantom/tests/phout.dat', cache_size=64)
        reader.close()
        frames = [i for i in reader]
        result = pd.concat(frames)
        assert len(result) == 200
        assert (result['interval_real'].mean() == 11000714.0)


class MockInfo(object):
    def __init__(self, steps):
        self.steps = steps


class TestStatsReader(object):

    def test_closed(self):
        STEPS = [[1.0, 1], [1.0, 1], [1.0, 1], [2.0, 1], [2.0, 1], [2.0, 1], [2.0, 1], [2.0, 1], [3.0, 1], [3.0, 1],
                 [3.0, 1], [3.0, 1], [3.0, 1], [4.0, 1], [4.0, 1], [4.0, 1], [4.0, 1], [4.0, 1], [5.0, 1], [5.0, 1],
                 [5.0, 1]]
        reader = PhantomStatsReader('yandextank/plugins/Phantom/tests/phantom_stat.dat',
                                    MockInfo(STEPS), cache_size=1024 * 10)
        reader.close()
{'fraction_non_alphanumeric': 0.16225390359809913, 'fraction_numerical': 0.06754921928038017, 'mean_word_length': 2.1825053995680346, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2551677', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1021, 'n_words': 233}