import re
from os.path import isfile, join

from pywincffi.core.ffi import Library
from pywincffi.core.testutil import TestCase


class TestConstantsHeader(TestCase):
    def test_file_exists(self):
        for path in Library.HEADERS:
            if path.endswith("constants.h"):
                self.assertTrue(isfile(path))

    def get_constants(self):
        with open(join(Library.HEADERS_ROOT, "constants.h"), "r") as header:
            for line in header:
                line = line.strip()
                if not line or line.startswith("//"):
                    continue

                match = re.match("^#define ([A-Z_]*) \.\.\..*$", line)
                if match is not None:
                    yield match.group(1)

    def test_library_has_attributes_defined_in_header(self):
        ffi, library = Library.load()
        for constant_name in self.get_constants():
            self.assertTrue(hasattr(library, constant_name))



@@ -37,16 +37,47 @@
 , join%0A%0A
+from six import integer_types%0A%0A
 from pyw
@@ -973,9 +973,270 @@
 name))%0A%0A
+    def test_constant_type(self):%0A        ffi, library = Library.load()%0A        valid_types = tuple(list(integer_types) + %5Bbool%5D)%0A%0A        for constant_name in self.get_constants():%0A            self.assertIsInstance(getattr(library, constant_name), valid_types)
 %0A

add type test too for constants