Exemplo n.º 1
0
    def test_timestamps(self):
        '''
        Ensure that modifying a timestamp on one of the inputs has no effect.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        tmp = self.mkstemp()
        with open(tmp, 'wt') as f:
            f.write('foo bar')

        c.save(input, ['arg1', 'arg2'], [tmp], 'hello world')
        c.flush()

        # Bump the timestamps on the input.
        st = os.stat(tmp)
        os.utime(tmp, (st[stat.ST_ATIME] + 3600, st[stat.ST_MTIME] + 3600))

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [tmp])
        self.assertEqual(output, 'hello world')

        # And after a flush.
        c.flush()
        output = c.load(input, ['arg1', 'arg2'], [tmp])
        self.assertEqual(output, 'hello world')
Exemplo n.º 2
0
    def test_miss_from_missing_file2(self):
        '''
        As above, but flush the entry to disk first.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        _, tmp = tempfile.mkstemp()
        with open(tmp, 'wt') as f:
            f.write('foo bar')

        c.save(input, ['arg1', 'arg2'], [tmp], 'hello world')

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [tmp])
        self.assertEqual(output, 'hello world')

        c.flush()

        os.remove(tmp)

        # Now ensure we get a miss after removing one of its inputs.
        output = c.load(input, ['arg1', 'arg2'], [tmp])
        self.assertIsNone(output)
Exemplo n.º 3
0
    def test_timestamps(self):
        '''
        Ensure that modifying a timestamp on one of the inputs has no effect.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        tmp = self.mkstemp()
        with open(tmp, 'wt') as f:
            f.write('foo bar')

        c.save(input, ['arg1', 'arg2'], [tmp], 'hello world')
        c.flush()

        # Bump the timestamps on the input.
        st = os.stat(tmp)
        os.utime(tmp, (st[stat.ST_ATIME] + 3600, st[stat.ST_MTIME] + 3600))

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [tmp])
        self.assertEqual(output, 'hello world')

        # And after a flush.
        c.flush()
        output = c.load(input, ['arg1', 'arg2'], [tmp])
        self.assertEqual(output, 'hello world')
Exemplo n.º 4
0
    def test_miss_from_missing_file2(self):
        '''
        As above, but flush the entry to disk first.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        _, tmp = tempfile.mkstemp()
        with open(tmp, 'wt') as f:
            f.write('foo bar')

        c.save(input, ['arg1', 'arg2'], [tmp], 'hello world')

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [tmp])
        self.assertEqual(output, 'hello world')

        c.flush()

        os.remove(tmp)

        # Now ensure we get a miss after removing one of its inputs.
        output = c.load(input, ['arg1', 'arg2'], [tmp])
        self.assertIsNone(output)
Exemplo n.º 5
0
    def test_directory_creation(self):
        '''
        The cache should be capable of creating necessary subdirectories under
        its root.
        '''
        root = os.path.join(self.mkdtemp(), 'non-existent')

        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, ['arg1', 'arg2'], [], 'hello world')
        c.flush()
Exemplo n.º 6
0
    def test_directory_creation(self):
        '''
        The cache should be capable of creating necessary subdirectories under
        its root.
        '''
        root = os.path.join(self.mkdtemp(), 'non-existent')

        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, ['arg1', 'arg2'], [], 'hello world')
        c.flush()
Exemplo n.º 7
0
    def test_basic(self):
        '''
        Test we can look up something we've just saved. Note that this test
        will not actually perform an on-disk lookup.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, ['arg1', 'arg2'], [], 'hello world')

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [])

        self.assertEqual(output, 'hello world')
Exemplo n.º 8
0
    def test_no_args(self):
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, [], [], 'hello world')

        # Ensure we can find what we just saved.
        output = c.load(input, [], [])
        self.assertEqual(output, 'hello world')

        # Ensure it is preserved after a flush.
        c.flush()
        output = c.load(input, [], [])
        self.assertEqual(output, 'hello world')
Exemplo n.º 9
0
    def test_no_args(self):
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, [], [], 'hello world')

        # Ensure we can find what we just saved.
        output = c.load(input, [], [])
        self.assertEqual(output, 'hello world')

        # Ensure it is preserved after a flush.
        c.flush()
        output = c.load(input, [], [])
        self.assertEqual(output, 'hello world')
Exemplo n.º 10
0
    def test_basic(self):
        '''
        Test we can look up something we've just saved. Note that this test
        will not actually perform an on-disk lookup.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, ['arg1', 'arg2'], [], 'hello world')

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [])

        self.assertEqual(output, 'hello world')
Exemplo n.º 11
0
    def test_basic_with_flush(self):
        '''
        Same as the basic test, but we'll flush in-between to ensure we perform
        an on-disk lookup.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, ['arg1', 'arg2'], [], 'hello world')
        c.flush()

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [])

        self.assertEqual(output, 'hello world')
Exemplo n.º 12
0
    def test_basic_with_flush(self):
        '''
        Same as the basic test, but we'll flush in-between to ensure we perform
        an on-disk lookup.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, ['arg1', 'arg2'], [], 'hello world')
        c.flush()

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [])

        self.assertEqual(output, 'hello world')
Exemplo n.º 13
0
    def test_no_inputs(self):
        '''
        Ensure we can handle an entry with no inputs.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(LiftedAST([]))

        c.save(input, ['arg1', 'arg2'], [], 'hello world')

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertEqual(output, 'hello world')

        # Ensure it is preserved after a flush.
        c.flush()
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertEqual(output, 'hello world')
Exemplo n.º 14
0
    def test_miss_in_memory2(self):
        '''
        Test that an induced cache miss while the cache entry is still in
        memory works correctly.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, ['arg1', 'arg2'], [], 'hello world')

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertEqual(output, 'hello world')

        # Induce a miss by passing different arguments.
        output = c.load(input, ['arg1', 'arg2', 'arg3'], [])
        self.assertIsNone(output)
Exemplo n.º 15
0
    def test_miss_in_memory2(self):
        '''
        Test that an induced cache miss while the cache entry is still in
        memory works correctly.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, ['arg1', 'arg2'], [], 'hello world')

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertEqual(output, 'hello world')

        # Induce a miss by passing different arguments.
        output = c.load(input, ['arg1', 'arg2', 'arg3'], [])
        self.assertIsNone(output)
Exemplo n.º 16
0
    def test_no_inputs(self):
        '''
        Ensure we can handle an entry with no inputs.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(LiftedAST([]))

        c.save(input, ['arg1', 'arg2'], [], 'hello world')

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertEqual(output, 'hello world')

        # Ensure it is preserved after a flush.
        c.flush()
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertEqual(output, 'hello world')
Exemplo n.º 17
0
    def test_miss_on_disk1(self):
        '''
        Same as the in-memory miss test except we flush the cache in-between.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, ['arg1', 'arg2'], [], 'hello world')
        c.flush()

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertEqual(output, 'hello world')

        # Now ensure we get a miss with a differing AST.
        input = prime_ast_hash(LiftedAST([]))
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertIsNone(output)
Exemplo n.º 18
0
    def test_miss_on_disk1(self):
        '''
        Same as the in-memory miss test except we flush the cache in-between.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, ['arg1', 'arg2'], [], 'hello world')
        c.flush()

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertEqual(output, 'hello world')

        # Now ensure we get a miss with a differing AST.
        input = prime_ast_hash(LiftedAST([]))
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertIsNone(output)
Exemplo n.º 19
0
    def test_miss_in_memory(self):
        '''
        Test that an induced cache miss while the cache entry is still in
        memory works correctly.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, ['arg1', 'arg2'], [], 'hello world')

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertEqual(output, 'hello world')

        # Now ensure we get a miss with a differing AST.
        input = prime_ast_hash(LiftedAST([]))
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertIsNone(output)
Exemplo n.º 20
0
    def test_miss_in_memory(self):
        '''
        Test that an induced cache miss while the cache entry is still in
        memory works correctly.
        '''
        root = self.mkdtemp()
        c = Cache(root)

        input = prime_ast_hash(dummy_ast())

        c.save(input, ['arg1', 'arg2'], [], 'hello world')

        # Ensure we can find what we just saved.
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertEqual(output, 'hello world')

        # Now ensure we get a miss with a differing AST.
        input = prime_ast_hash(LiftedAST([]))
        output = c.load(input, ['arg1', 'arg2'], [])
        self.assertIsNone(output)