File: test_commontypes.py

package info (click to toggle)
python-cffi 2.0.0~b1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,796 kB
  • sloc: python: 28,456; ansic: 15,272; asm: 116; makefile: 97; sh: 14
file content (35 lines) | stat: -rw-r--r-- 927 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
import os, cffi, re
import pytest
import _cffi_backend


def getlines():
    try:
        f = open(os.path.join(os.path.dirname(cffi.__file__),
                              '..', 'c', 'commontypes.c'))
    except IOError:
        pytest.skip("cannot find ../c/commontypes.c")
    lines = [line for line in f.readlines() if line.strip().startswith('EQ(')]
    f.close()
    return lines

def test_alphabetical_order():
    lines = getlines()
    assert lines == sorted(lines)

def test_dependencies():
    r = re.compile(r'EQ[(]"([^"]+)",(?:\s*"([A-Z0-9_]+)\s*[*]*"[)])?')
    lines = getlines()
    d = {}
    for line in lines:
        match = r.search(line)
        if match is not None:
            d[match.group(1)] = match.group(2)
    for value in d.values():
        if value:
            assert value in d

def test_get_common_types():
    d = {}
    _cffi_backend._get_common_types(d)
    assert d["bool"] == "_Bool"