diff options
author | David Malcolm <dmalcolm@redhat.com> | 2009-11-13 20:23:15 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2009-11-13 20:23:15 -0500 |
commit | e736aed161f54bb5130458b88001fa2c3ff31051 (patch) | |
tree | d359e01ba4f60473c45c5c21273478ce643aaea0 | |
parent | bca47923dcb4a31b53c60afbe8ccc1b9a82eec48 (diff) | |
download | check-cpython-e736aed161f54bb5130458b88001fa2c3ff31051.tar.gz check-cpython-e736aed161f54bb5130458b88001fa2c3ff31051.tar.xz check-cpython-e736aed161f54bb5130458b88001fa2c3ff31051.zip |
Fixup some issues and start adding unit tests for validate.py
-rw-r--r-- | validate.py | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/validate.py b/validate.py index 0c6860d..3f32745 100644 --- a/validate.py +++ b/validate.py @@ -95,12 +95,15 @@ def get_types(location, strfmt): result.append('PyObject * *') elif c == 'O': # object if next == '!': - result += ['PyTypeObject * *', 'PyObject * *'] + result += ['PyTypeObject *', 'PyObject * *'] i += 1 elif next == '?': raise UnhandledCode(location, c + next) # FIXME elif next == '&': - raise UnhandledCode(location, c + next) # FIXME + # FIXME: can't really handle this case as is, fixing for fcntmodule.c + result += ['int ( PyObject * object , int * target )', # converter + 'int *'] # FIXME, anything + i += 1 else: result.append('PyObject * *') elif c == 'w': @@ -153,14 +156,18 @@ class MismatchingType(CExtensionError): def type_equality(t1, t2): if t1 == t2: return True + + # do we really care about char/const char mismatches?: if t1.startswith('const char *'): if t1 == 'const '+t2: return True if t2.startswith('const char *'): if 'const '+t1 == t2: return True + return False + def validate_types(location, format_string, actual_types): if False: print 'validate_types(%s, %s, %s)' % ( @@ -176,9 +183,33 @@ def validate_types(location, format_string, actual_types): raise MismatchingType(location, i+1, exp, actual) except CExtensionError, err: print err - if True: + if False: print 'validate_types(%s, %s, %s)' % ( repr(location), repr(format_string), repr(actual_types)) return 1 return 0 +import unittest +class TestArgParsing(unittest.TestCase): + def assert_args(self, arg_str, exp_result): + result = get_types(None, arg_str) + self.assertEquals(result, exp_result) + + def test_simple_cases(self): + self.assert_args('c', + ['char *']) + + def test_socketmodule_socket_htons(self): + self.assert_args('i:htons', + ['int *']) + + def test_fcntlmodule_fcntl_flock(self): + # FIXME: somewhat broken, we can't know what the converter callback is + self.assert_args("O&i:flock", + ['int ( PyObject * object , int * target )', + 'int *', + 'int *']) + + +if __name__ == '__main__': + unittest.main() |