<commit_before>import os

from dvc.cache import Cache

from tests.basic_env import TestDvc


class TestCache(TestDvc):
    def setUp(self):
        super(TestCache, self).setUp()
        self.cache1 = os.path.join(self.dvc.cache.cache_dir, '1')
        self.cache2 = os.path.join(self.dvc.cache.cache_dir, '2')
        self.create(self.cache1, '1')
        self.create(self.cache2, '2')

    def test_all(self):
        flist = Cache(self.dvc.dvc_dir).all()
        self.assertEquals(len(flist), 2)
        self.assertTrue(self.cache1 in flist)
        self.assertTrue(self.cache2 in flist)

    def test_get(self):
        cache = Cache(self.dvc.dvc_dir).get(os.path.basename(self.cache1))
        self.assertEquals(cache, self.cache1)<commit_msg>test: add test for Cache.find_cache()<commit_after>import os

from dvc.cache import Cache
from dvc.system import System

from tests.basic_env import TestDvc


class TestCache(TestDvc):
    def setUp(self):
        super(TestCache, self).setUp()
        self.cache1 = os.path.join(self.dvc.cache.cache_dir, '1')
        self.cache2 = os.path.join(self.dvc.cache.cache_dir, '2')
        self.create(self.cache1, '1')
        self.create(self.cache2, '2')

    def test_all(self):
        flist = Cache(self.dvc.dvc_dir).all()
        self.assertEquals(len(flist), 2)
        self.assertTrue(self.cache1 in flist)
        self.assertTrue(self.cache2 in flist)

    def test_get(self):
        cache = Cache(self.dvc.dvc_dir).get(os.path.basename(self.cache1))
        self.assertEquals(cache, self.cache1)

    def test_find_cache(self):
        fname1 = os.path.basename(self.cache1)
        fname1_md5 = fname1
        fname2 = os.path.basename(self.cache2)
        fname2_md5 = fname2
        fname3 = 'non_existing'

        System.hardlink(self.cache1, fname1)
        System.hardlink(self.cache2, fname2)

        cache = Cache(self.dvc.dvc_dir).find_cache([fname1, fname2, fname3])

        expected = {fname1: fname1_md5, fname2: fname2_md5}

        self.assertEqual(len(cache), 2)
        self.assertEqual(cache, expected)
{'fraction_non_alphanumeric': 0.12758786711603273, 'fraction_numerical': 0.02455464612421762, 'mean_word_length': 2.8841121495327102, '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': '6028995', 'n_tokens_mistral': 756, 'n_tokens_neox': 744, 'n_words': 124}