<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
# Cached file-system utility library
# (C) 2016 VRT Systems
#
# vim: set ts=4 sts=4 et tw=78 sw=4:

from nose.plugins.skip import SkipTest
import cachefs
import os
import weakref
import tempfile
import stat
import time

from .utils import TempDirTestCase, compare_walk

class TestNode(TempDirTestCase):
    def test_stat_cache(self):
        cache = cachefs.CacheFs(cache_expiry=2.0, stat_expiry=1.0)

        # Get a reference to one of the files.
        node = cache[self.temp_dir.file_a]

        # Get its size.
        size_1 = node.stat.st_size

        # Make a change to that file.
        open(self.temp_dir.file_a,'a').write(' -- some data')

        # Get its size.  It should not have changed.
        size_2 = node.stat.st_size
        assert size_1 == size_2, 'Cached data refreshed.'

        # Wait for expiry.
        time.sleep(1.5)

        # Get it again.
        size_3 = node.stat.st_size

        assert size_1 < size_3, 'Cached data not refreshed.'

    def test_find_all(self):
        cache = cachefs.CacheFs(cache_expiry=2.0, stat_expiry=1.0)
        found_names = set([found.abs_path for found in
                cache.find(self.temp_dir.tempdir)])

        assert found_names == self.temp_dir.all_files, 'A file was missed'

    def test_find_all_link(self):
        if not hasattr(os, 'symlink'):
            raise SkipTest
        cache = cachefs.CacheFs(cache_expiry=2.0, stat_expiry=1.0)
        found_names = set([found.abs_path for found in
                cache.find(self.temp_dir.link_top)])

        assert found_names == self.temp_dir.all_files, 'A file was missed'

    def test_find_file(self):
        cache = cachefs.CacheFs(cache_expiry=2.0, stat_expiry=1.0)
        found_names = set([found.abs_path for found in
                cache.find(self.temp_dir.file_a)])

        assert found_names == set([self.temp_dir.file_a]), \
                'Mismatch in expected list'<commit_msg>node tests: Add test cases for path attributes/methods.<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
# Cached file-system utility library
# (C) 2016 VRT Systems
#
# vim: set ts=4 sts=4 et tw=78 sw=4:

from nose.plugins.skip import SkipTest
import cachefs
import os
import weakref
import tempfile
import stat
import time

from .utils import TempDirTestCase, compare_walk

class TestNode(TempDirTestCase):
    def test_stat_cache(self):
        cache = cachefs.CacheFs(cache_expiry=2.0, stat_expiry=1.0)

        # Get a reference to one of the files.
        node = cache[self.temp_dir.file_a]

        # Get its size.
        size_1 = node.stat.st_size

        # Make a change to that file.
        open(self.temp_dir.file_a,'a').write(' -- some data')

        # Get its size.  It should not have changed.
        size_2 = node.stat.st_size
        assert size_1 == size_2, 'Cached data refreshed.'

        # Wait for expiry.
        time.sleep(1.5)

        # Get it again.
        size_3 = node.stat.st_size

        assert size_1 < size_3, 'Cached data not refreshed.'

    def test_find_all(self):
        cache = cachefs.CacheFs(cache_expiry=2.0, stat_expiry=1.0)
        found_names = set([found.abs_path for found in
                cache.find(self.temp_dir.tempdir)])

        assert found_names == self.temp_dir.all_files, 'A file was missed'

    def test_find_all_link(self):
        if not hasattr(os, 'symlink'):
            raise SkipTest
        cache = cachefs.CacheFs(cache_expiry=2.0, stat_expiry=1.0)
        found_names = set([found.abs_path for found in
                cache.find(self.temp_dir.link_top)])

        assert found_names == self.temp_dir.all_files, 'A file was missed'

    def test_find_file(self):
        cache = cachefs.CacheFs(cache_expiry=2.0, stat_expiry=1.0)
        found_names = set([found.abs_path for found in
                cache.find(self.temp_dir.file_a)])

        assert found_names == set([self.temp_dir.file_a]), \
                'Mismatch in expected list'

    def test_node_base_name(self):
        cache = cachefs.CacheFs(cache_expiry=2.0, stat_expiry=1.0)

        # Get a reference to one of the files.
        node = cache[self.temp_dir.file_a]
        assert node.base_name == os.path.basename(self.temp_dir.file_a), \
                'Base name does not match'

    def test_node_dir_name(self):
        cache = cachefs.CacheFs(cache_expiry=2.0, stat_expiry=1.0)

        # Get a reference to one of the files.
        node = cache[self.temp_dir.file_a]
        assert node.dir_name == os.path.dirname(self.temp_dir.file_a), \
                'Directory name does not match'

    def test_node_join(self):
        cache = cachefs.CacheFs(cache_expiry=2.0, stat_expiry=1.0)

        # Get a reference to one of the files.
        node = cache[self.temp_dir.tempdir]
        assert node.join('abcd', 'efgh') == \
                os.path.join(self.temp_dir.tempdir, 'abcd', 'efgh'), \
                'Path does not match'
{'fraction_non_alphanumeric': 0.10540052198353744, 'fraction_numerical': 0.016462557719333467, 'mean_word_length': 2.4406077348066297, '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': '4184899', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1639, 'n_words': 401}