<commit_before>
import gc
import os
import sys
import unittest
import weakref

import pympler.asizeof as asizeof

from inspect import stack


class Foo(object):
    def __init__(self, content):
        self.data = content

    def __repr__(self):
        return 'Foo'


class ThinFoo(object):
    __slots__ = ('tdata',)
    def __init__(self, content):
        self.tdata = content


class OldFoo:
    def __init__(self, content):
        self.odata = content


class PseudoDict(object):
    '''Dict-like object for inferring dictionaries.'''

    def __len__(self):
        return 0

    def get(self, *args, **kwargs):
        return None

    def has_key(self, *args, **kwargs):
        return False

    def items(self):
        return []

    def keys(self):
        return []

    def values(self):
        return []


class TypesTest(unittest.TestCase):

    def test_generator(self):
        '''Test integrity of sized generator
        '''
        def infinite_gen():
            i = 1
            while True:
                yield i
                i += 1

        gen = infinite_gen()
        s1 = asizeof.asizeof(gen, code=True)
        for i in gen:
            self.assertEqual(i, 1)
            break
        for i in gen:
            self.assertEqual(i, 2)
            break
        s2 = asizeof.asizeof(gen, code=True)
        s3 = asizeof.asizeof(gen, code=False)
        for i in gen:
            self.assertEqual(i, 3)
            break
        self.assertEqual(s1, s2)
        self.assertNotEqual(s3, 0)

    def test_methods(self):
        '''Test sizing methods and functions
        '''
        def foo():
            pass

        s1 = asizeof.asizeof(self.test_methods, code=True)
        s2 = asizeof.asizeof(TypesTest.test_methods, code=True)
        s3 = asizeof.asizeof(foo, code=True)
        # TODO asserts?

    def test_classes(self):
        '''Test sizing class objects and instances
        '''
        self.assertTrue(asizeof.asizeof(Foo, code=True) > 0)<commit_msg>Fix generator test on Python 3.8<commit_after>
import gc
import os
import sys
import unittest
import weakref

import pympler.asizeof as asizeof

from inspect import stack


class Foo(object):
    def __init__(self, content):
        self.data = content

    def __repr__(self):
        return 'Foo'


class ThinFoo(object):
    __slots__ = ('tdata',)
    def __init__(self, content):
        self.tdata = content


class OldFoo:
    def __init__(self, content):
        self.odata = content


class PseudoDict(object):
    '''Dict-like object for inferring dictionaries.'''

    def __len__(self):
        return 0

    def get(self, *args, **kwargs):
        return None

    def has_key(self, *args, **kwargs):
        return False

    def items(self):
        return []

    def keys(self):
        return []

    def values(self):
        return []


class TypesTest(unittest.TestCase):

    def test_generator(self):
        '''Test integrity of sized generator
        '''
        def infinite_gen():
            i = 1
            while True:
                yield i
                i += 1

        gen = infinite_gen()
        asizeof.asizeof(gen, code=True)
        self.assertEqual(next(gen), 1)
        s1 = asizeof.asizeof(gen, code=True)
        self.assertEqual(next(gen), 2)
        s2 = asizeof.asizeof(gen, code=True)
        s3 = asizeof.asizeof(gen, code=False)
        self.assertEqual(next(gen), 3)
        self.assertEqual(s1, s2)
        self.assertNotEqual(s3, 0)

    def test_methods(self):
        '''Test sizing methods and functions
        '''
        def foo():
            pass

        s1 = asizeof.asizeof(self.test_methods, code=True)
        s2 = asizeof.asizeof(TypesTest.test_methods, code=True)
        s3 = asizeof.asizeof(foo, code=True)
        # TODO asserts?

    def test_classes(self):
        '''Test sizing class objects and instances
        '''
        self.assertTrue(asizeof.asizeof(Foo, code=True) > 0)
{'fraction_non_alphanumeric': 0.10381409446830007, 'fraction_numerical': 0.009093205354887599, 'mean_word_length': 2.0344827586206895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3075417', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1210, 'n_words': 321}