<commit_before>import gc
import os.path

from mock import Mock
from fixture import TempIO
from nose.tools import assert_equal, assert_raises

from pythoscope.store import CodeTree, CodeTreeNotFound, \
    FilesystemCodeTreesManager, Module

from helper import assert_length


class TestFilesystemCodeTreesManager:
    def setUp(self):
        self.manager = FilesystemCodeTreesManager(TempIO())

    def assert_empty_cache(self):
        assert_equal(None, self.manager._cached_code_tree)

    def assert_cache(self, module_subpath):
        assert_equal(module_subpath, self.manager._cached_code_tree[0])

    def assert_recalled_tree(self, module_subpath, code):
        assert_equal(code, self.manager.recall_code_tree(module_subpath).code)

    def assert_code_tree_saved(self, module_subpath, saved=True):
        path = self.manager._code_tree_path(module_subpath)
        assert_equal(saved, os.path.exists(path))

    def assert_code_tree_not_saved(self, module_subpath):
        self.assert_code_tree_saved(module_subpath, saved=False)

    def assert_calls_once(self, mock, callback):
        """Assert that given callback calls given Mock object exactly once.
        """
        before_count = mock.call_count
        callback()
        assert_equal(before_count + 1, mock.call_count)

    def test_remembered_code_trees_can_be_recalled(self):<commit_msg>  Don't use fixture.io in TestFilesystemCodeTreesManager.<commit_after>import gc
import os.path

from mock import Mock
from nose.tools import assert_equal, assert_raises

from pythoscope.store import CodeTree, CodeTreeNotFound, \
    FilesystemCodeTreesManager, Module

from helper import assert_length, TempDirectory


class TestFilesystemCodeTreesManager(TempDirectory):
    def setUp(self):
        super(TestFilesystemCodeTreesManager, self).setUp()
        self.manager = FilesystemCodeTreesManager(self.tmpdir)

    def assert_empty_cache(self):
        assert_equal(None, self.manager._cached_code_tree)

    def assert_cache(self, module_subpath):
        assert_equal(module_subpath, self.manager._cached_code_tree[0])

    def assert_recalled_tree(self, module_subpath, code):
        assert_equal(code, self.manager.recall_code_tree(module_subpath).code)

    def assert_code_tree_saved(self, module_subpath, saved=True):
        path = self.manager._code_tree_path(module_subpath)
        assert_equal(saved, os.path.exists(path))

    def assert_code_tree_not_saved(self, module_subpath):
        self.assert_code_tree_saved(module_subpath, saved=False)

    def assert_calls_once(self, mock, callback):
        """Assert that given callback calls given Mock object exactly once.
        """
        before_count = mock.call_count
        callback()
        assert_equal(before_count + 1, mock.call_count)

    def test_remembered_code_trees_can_be_recalled(self):
{'fraction_non_alphanumeric': 0.0770042194092827, 'fraction_numerical': 0.0014064697609001407, 'mean_word_length': 4.429389312977099, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3929063', 'n_tokens_mistral': 873, 'n_tokens_neox': 851, 'n_words': 171}