File: test_directory_cache.py

package info (click to toggle)
pygccxml 3.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,444 kB
  • sloc: xml: 29,841; python: 13,914; cpp: 2,671; makefile: 163; ansic: 59
file content (81 lines) | stat: -rw-r--r-- 2,160 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Copyright 2014-2017 Insight Software Consortium.
# Copyright 2004-2009 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

import os
import shutil

import pytest

from . import autoconfig

from pygccxml import parser

TEST_FILES = [
    "typedefs1.hpp"
]

CACHE_DIR = os.path.join(autoconfig.data_directory, "directory_cache_test")


def set_up():
    if os.path.isdir(CACHE_DIR):
        shutil.rmtree(CACHE_DIR)
    if os.path.isfile(CACHE_DIR):
        os.remove(CACHE_DIR)


def test_directory_cache_without_compression():
    """
    Test the directory cache without compression

    """
    config = autoconfig.cxx_parsers_cfg.config.clone()
    set_up()
    # Test with compression OFF
    cache = parser.directory_cache_t(directory=CACHE_DIR)
    # Generate a cache on first read
    parser.parse(TEST_FILES, config, cache=cache)
    # Read from the cache the second time
    parser.parse(TEST_FILES, config, cache=cache)


def test_directory_cache_with_compression():
    """
    Test the directory cache wit compression

    """
    config = autoconfig.cxx_parsers_cfg.config.clone()
    set_up()
    # Test with compression ON
    cache = parser.directory_cache_t(
        directory=CACHE_DIR, compression=True)
    # Generate a cache on first read
    parser.parse(TEST_FILES, config, cache=cache)
    # Read from the cache the second time
    parser.parse(TEST_FILES, config, cache=cache)


def test_directory_cache_twice():
    """
    Setup two caches in a row.

    The second run will reload the same cache directory.
    """
    config = autoconfig.cxx_parsers_cfg.config.clone()
    set_up()
    cache = parser.directory_cache_t(directory=CACHE_DIR)
    parser.parse(TEST_FILES, config, cache=cache)
    cache = parser.directory_cache_t(directory=CACHE_DIR)
    parser.parse(TEST_FILES, config, cache=cache)


def test_directory_existing_dir():
    """
    Setup a cache when there is already a file at the cache's location.
    """
    set_up()
    open(CACHE_DIR, "a").close()
    with pytest.raises(ValueError):
        parser.directory_cache_t(directory=CACHE_DIR)