Commits

larry  committed 9f3043d

Started working towards coverage. If you include the example clinic
blocks in */*.c, currently at 92%.

  • Participants
  • Parent commits b3b844c

Comments (0)

Files changed (11)

File Modules/_cursesmodule.c

 "Paint character ch at (y, x) with attributes attr.\n"
 "\n"
 "curses.window.addch([x, y,] ch, [attr])\n"
-"\n"
 "  x\n"
 "    X-coordinate.\n"
 "  y\n"
 "  attr\n"
 "    Attributes for the character.\n"
 "\n"
-"\n"
 "Paint character ch at (y, x) with attributes attr,\n"
 "overwriting any character previously painter at that location.\n"
 "By default, the character position and attributes are the\n"
 
 static PyObject *
 curses_window_addch_impl(PyObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr)
-/*[clinic checksum: d8356bece150cf73bc9fb2232bbc2d82e4ac663e]*/
+/*[clinic checksum: 8e50f068905f617976f825527a335c856de256bb]*/
 {
     PyCursesWindowObject *cwself = (PyCursesWindowObject *)self;
     int coordinates_group = group_left_1;

File Modules/_datetimemodule.c

 "Returns new datetime object representing current time local to tz.\n"
 "\n"
 "datetime.now(tz=None)\n"
-"\n"
 "  tz\n"
 "    Timezone object.\n"
 "\n"
-"\n"
 "If no tz is specified, uses local timezone.");
 
 #define DATETIME_NOW_METHODDEF    \
 
 static PyObject *
 datetime_now_impl(PyObject *cls, PyObject *tz)
-/*[clinic checksum: 142b298db95cfe6c91aa12a40ce5210f1512bf5c]*/
+/*[clinic checksum: 801e442c9a6dab8eca095ba4d4c6bfeff49b6d8e]*/
 {
     PyObject *self;
 

File Modules/_dbmmodule.c

 
 PyDoc_STRVAR(dbmopen__doc__,
 "Returns a database object.\n"
+"\n"
 "dbm.open(filename, flags=\'r\', mode=0o666)\n"
-"\n"
 "  filename\n"
 "    The filename to open.\n"
 "  flags\n"
 "    How to open the file.  \"r\" for reading, \"w\" for writing, etc.\n"
 "  mode\n"
 "    If creating a new file, the mode bits for the new file\n"
-"    (e.g. os.O_RDWR).\n"
-"\n"
-"");
+"    (e.g. os.O_RDWR).");
 
 #define DBMOPEN_METHODDEF    \
     {"open", (PyCFunction)dbmopen, METH_VARARGS|METH_KEYWORDS, dbmopen__doc__}
 
 static PyObject *
 dbmopen_impl(PyObject *self, const char *filename, const char *flags, int mode)
-/*[clinic checksum: 820765984f1df874d2849a235beabe88203f46b3]*/
+/*[clinic checksum: 4244155a4add21474fa6aabdb642288e1b33a24a]*/
 {
     int iflags;
 

File Modules/_weakref.c

 
 PyDoc_STRVAR(_weakref_getweakrefcount__doc__,
 "Return the number of weak references to \'object\'.\n"
-"_weakref.getweakrefcount(object)\n"
 "\n"
-"\n"
-"");
+"_weakref.getweakrefcount(object)");
 
 #define _WEAKREF_GETWEAKREFCOUNT_METHODDEF    \
     {"getweakrefcount", (PyCFunction)_weakref_getweakrefcount, METH_VARARGS|METH_KEYWORDS, _weakref_getweakrefcount__doc__}
 
 static Py_ssize_t
 _weakref_getweakrefcount_impl(PyObject *self, PyObject *object)
-/*[clinic checksum: cf88cba4f39d68bd91d814bf690767741697045b]*/
+/*[clinic checksum: 8ee4de5f2b16ece2d2049a97d2e433587fa09eec]*/
 {
     PyWeakReference **list;
 

File Modules/posixmodule.c

 "Perform a stat system call on the given path.\n"
 "\n"
 "os.stat(path, *, dir_fd=None, follow_symlinks=True) -> stat_result\n"
-"\n"
 "  path\n"
 "    Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
 "  dir_fd\n"
 "    If False, and the last element of the path is a symbolic link,\n"
 "    stat will examine the symbolic link itself instead of the file\n"
 "    the link points to.\n"
-"\n"
 "dir_fd and follow_symlinks may not be implemented\n"
 "  on your platform.  If they are unavailable, using them will raise a\n"
 "  NotImplementedError.\n"
 
 static PyObject *
 os_stat_impl(PyObject *self, path_t *path, int dir_fd, int follow_symlinks)
-/*[clinic checksum: eac87715d42f583d211046bee1be2a195420a135]*/
+/*[clinic checksum: e2644c5b2699399787d2d058b6196c3054afefc7]*/
 {
     return posix_do_stat("stat", path, dir_fd, follow_symlinks);
 }
 "Use the real uid/gid to test for access to a path.\n"
 "\n"
 "os.access(path, mode, *, dir_fd=None, effective_ids=False, follow_symlinks=True) -> True if granted, False otherwise\n"
-"\n"
 "  path\n"
 "    Path to be tested; can be string, bytes, or open-file-descriptor int.\n"
 "  mode\n"
 "    access will examine the symbolic link itself instead of the file\n"
 "    the link points to.\n"
 "\n"
-"\n"
 "{parameters}\n"
 "dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
 "  on your platform.  If they are unavailable, using them will raise a\n"
 
 static PyObject *
 os_access_impl(PyObject *self, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks)
-/*[clinic checksum: 94c672b78bb1318867ecc19b0f63134fcb10e4f4]*/
+/*[clinic checksum: de528a2c849ae5eb741e390d70ae79098613b4ff]*/
 {
     PyObject *return_value = NULL;
 
 
 PyDoc_STRVAR(os_ttyname__doc__,
 "Return the name of the terminal device connected to \'fd\'.\n"
+"\n"
 "os.ttyname(fd)\n"
-"\n"
 "  fd\n"
-"    Integer file descriptor handle.\n"
-"\n"
-"");
+"    Integer file descriptor handle.");
 
 #define OS_TTYNAME_METHODDEF    \
     {"ttyname", (PyCFunction)os_ttyname, METH_VARARGS|METH_KEYWORDS, os_ttyname__doc__}
 
 static char *
 os_ttyname_impl(PyObject *self, int fd)
-/*[clinic checksum: 4f9a1a8d6972d4f57ab248604b8977687228f6fb]*/
+/*[clinic checksum: 27aad3f970e74b34954ba19faaedc47a3e455e38]*/
 {
     char *ret;
 

File Modules/unicodedata.c

 "\n"
 "unicodedata.decimal(unichr, [default])\n"
 "\n"
-"\n"
-"\n"
 "Returns the decimal value assigned to the Unicode character unichr\n"
 "as integer. If no such value is defined, default is returned, or, if\n"
 "not given, ValueError is raised.");
 
 static PyObject *
 unicodedata_decimal_impl(PyObject *self, PyObject *unichr, int group_right_1, PyObject *default_value)
-/*[clinic checksum: 50e03f3d417ba06c8da629739d08f8680a608e05]*/
+/*[clinic checksum: 234412d4f64cd76a1d9cb00dd8fa32df8a2ac5fa]*/
 {
     PyUnicodeObject *v = (PyUnicodeObject *)unichr;
     int have_old = 0;

File Modules/zlibmodule.c

 "Return a string containing the decompressed version of the data.\n"
 "\n"
 "zlib.decompress(data, max_length=0)\n"
-"\n"
 "  data\n"
 "    The binary data to decompress.\n"
 "  max_length\n"
 "    Unconsumed input data will be stored in\n"
 "    the unconsumed_tail attribute.\n"
 "\n"
-"\n"
 "After calling this function, some of the input data may still be stored in\n"
 "internal buffers for later processing.\n"
 "Call the flush() method to clear these buffers.");
 
 static PyObject *
 zlib_decompress_impl(PyObject *self, Py_buffer *data, int max_length)
-/*[clinic checksum: 32fd95170ee0222e2e92ea6f575e1f0953a61200]*/
+/*[clinic checksum: 575d87baae38fa20b993252b78d19b88cb5877c6]*/
 {
     compobject *zself = (compobject *)self;
     int err;
 
 PyDoc_STRVAR(zlib_copy__doc__,
 "Return a copy of the compression object.\n"
-"zlib.copy()\n"
 "\n"
-"\n"
-"");
+"zlib.copy()");
 
 #define ZLIB_COPY_METHODDEF    \
     {"copy", (PyCFunction)zlib_copy, METH_VARARGS|METH_KEYWORDS, zlib_copy__doc__}
 
 static PyObject *
 zlib_copy_impl(PyObject *self)
-/*[clinic checksum: 33ae610e9e34545b53e02f58cf6a698ea9ce0375]*/
+/*[clinic checksum: 87e6aa7f0774ce5066d67966692922675379364a]*/
 {
     compobject *zself = (compobject *)self;
     compobject *retval = NULL;

File Objects/dictobject.c

 
 PyDoc_STRVAR(dict___contains____doc__,
 "True if D has a key k, else False\"\n"
-"dict.__contains__(key)\n"
 "\n"
-"\n"
-"");
+"dict.__contains__(key)");
 
 #define DICT___CONTAINS___METHODDEF    \
     {"__contains__", (PyCFunction)dict___contains__, METH_VARARGS|METH_KEYWORDS|METH_COEXIST, dict___contains____doc__}
 
 static PyObject *
 dict___contains___impl(PyObject *self, PyObject *key)
-/*[clinic checksum: 4dc53d27f662cd5a55c25d394aee8256a5600db3]*/
+/*[clinic checksum: 4073cc5d4fb0637c4f9afc6728fdfcc55ae01674]*/
 {
     register PyDictObject *mp = (PyDictObject *)self;
     Py_hash_t hash;

File Objects/unicodeobject.c

 "\n"
 "str.maketrans(x, y=None, z=None)\n"
 "\n"
-"\n"
-"\n"
 "If there is only one argument, it must be a dictionary mapping Unicode\n"
 "ordinals (integers) or characters to Unicode ordinals, strings or None.\n"
 "Character keys will be then converted to ordinals.\n"
 
 static PyObject *
 unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z)
-/*[clinic checksum: 67446fadf0f7fbf9373810f92987b8d5b4edb7e2]*/
+/*[clinic checksum: 77676485027ac9d2b6bb34d47ac4c1b41f2bcee2]*/
 {
     PyObject *new = NULL, *key, *value;
     Py_ssize_t i = 0;
         s = s.replace(old, new)
     return s
 
-def quoted_for_c(s):
-    add, output = text_accumulator()
-    map = { '\t': '\\\\t', '\n': '\\\\n', '\r': '\\\\r' }
-    for c in s:
-        if c in map:
-            add(map[c])
-            continue
-        if c in '\\"\'':
-            add('\\')
-        add(c)
-    return output()
+# def quoted_for_c(s):
+#     add, output = text_accumulator()
+#     map = { '\t': '\\\\t', '\n': '\\\\n', '\r': '\\\\r' }
+#     for c in s:
+#         if c in map:
+#             add(map[c])
+#             continue
+#         if c in '\\"\'':
+#             add('\\')
+#         add(c)
+#     return output()
 
 c_keywords = set("""
 asm auto break case char const continue default do double else enum

File clinic_test.py

 from clinic import DSLParser
 import collections
 import inspect
+from test import support
 import unittest
 from unittest import TestCase
 
     _module_and_class = clinic.Clinic._module_and_class
 
 
-def fail(*args):
-    text = " ".join((str(a) for a in args))
-    raise SystemExit(text)
+#def fail(*args):
+#    text = " ".join((str(a) for a in args))
+#    raise SystemExit(text)
 
 # monkeypatch Clinic failure so it doesn't print jonx on the screen
-clinic.fail = fail
+#clinic.fail = fail
 
 
 class ClinicGroupPermuterTest(TestCase):
     path: str
 This/used to break Clinic!
 """)
-        with open('/home/larry/src/python/clinic/ZZZ.txt', 'w') as f:
-            print("x", file=f)
-        sys.exit("function.docstring:", repr(function.docstring))
         self.assertEqual("os.stat(path)\n\nThis/used to break Clinic!", function.docstring)
 
     def test_c_name(self):
     Attributes for the character.
                 """.strip())
 
+    def parse_function_should_fail(self, s):
+        with support.captured_stdout() as stdout:
+            with self.assertRaises(SystemExit):
+                self.parse_function(s)
+        return stdout.getvalue()
+
     def test_disallowed_grouping__two_top_groups_on_left(self):
-        with self.assertRaises(SystemExit):
-            self.parse_function("""
+        s = self.parse_function_should_fail("""
 module foo
 foo.two_top_groups_on_left
     [
     ]
     param: int
             """)
+        self.assertEqual(s,
+            ('Error on line 0:\n'
+            'Function two_top_groups_on_left has an unsupported group configuration.\n'))
 
     def test_disallowed_grouping__two_top_groups_on_right(self):
-        with self.assertRaises(SystemExit):
-            self.parse_function("""
+        self.parse_function_should_fail("""
 module foo
 foo.two_top_groups_on_right
     param: int
             """)
 
     def test_disallowed_grouping__parameter_after_group_on_right(self):
-        with self.assertRaises(SystemExit):
-            self.parse_function("""
+        self.parse_function_should_fail("""
 module foo
 foo.parameter_after_group_on_right
     param: int
             """)
 
     def test_disallowed_grouping__group_after_parameter_on_left(self):
-        with self.assertRaises(SystemExit):
-            self.parse_function("""
+        self.parse_function_should_fail("""
 module foo
 foo.group_after_parameter_on_left
     [
             """)
 
     def test_disallowed_grouping__empty_group_on_left(self):
-        with self.assertRaises(SystemExit):
-            self.parse_function("""
+        self.parse_function_should_fail("""
 module foo
 foo.empty_group
     [
             """)
 
     def test_disallowed_grouping__empty_group_on_right(self):
-        with self.assertRaises(SystemExit):
-            self.parse_function("""
+        self.parse_function_should_fail("""
 module foo
 foo.empty_group
     param: int
         self.assertEqual(0, len(function.parameters))
 
     def test_single_star(self):
-        with self.assertRaises(SystemExit):
-            self.parse("""
+        self.parse_function_should_fail("""
 module foo
 foo.bar
     *
 """)
 
     def test_parameters_required_after_star_without_initial_parameters_or_docstring(self):
-        with self.assertRaises(SystemExit):
-            self.parse("""
+        self.parse_function_should_fail("""
 module foo
 foo.bar
     *
 """)
 
     def test_parameters_required_after_star_without_initial_parameters_with_docstring(self):
-        with self.assertRaises(SystemExit):
-            self.parse("""
+        self.parse_function_should_fail("""
 module foo
 foo.bar
     *
 """)
 
     def test_parameters_required_after_star_with_initial_parameters_without_docstring(self):
-        with self.assertRaises(SystemExit):
-            self.parse("""
+        self.parse_function_should_fail("""
 module foo
 foo.bar
     this: int
 """)
 
     def test_parameters_required_after_star_with_initial_parameters_and_docstring(self):
-        with self.assertRaises(SystemExit):
-            self.parse("""
+        self.parse_function_should_fail("""
 module foo
 foo.bar
     this: int
 """)
 
     def test_single_slash(self):
-        with self.assertRaises(SystemExit):
-            self.parse("""
+        self.parse_function_should_fail("""
 module foo
 foo.bar
     /
 """)
 
     def test_mix_star_and_slash(self):
-        with self.assertRaises(SystemExit):
-            self.parse("""
+        self.parse_function_should_fail("""
 module foo
 foo.bar
    x: int
 """)
 
     def test_parameters_not_permitted_after_slash_for_now(self):
-        with self.assertRaises(SystemExit):
-            self.parse("""
+        self.parse_function_should_fail("""
 module foo
 foo.bar
     /
         assert isinstance(s[1], clinic.Function)
         return s[1]
 
+    def test_scaffolding(self):
+        # test repr on special values
+        self.assertEqual(repr(clinic.unspecified), '<Unspecified>')
+        self.assertEqual(repr(clinic.NULL), '<Null>')
+
+        # test that fail fails
+        with support.captured_stdout() as stdout:
+            with self.assertRaises(SystemExit):
+                clinic.fail('The igloos are melting!', filename='clown.txt', line_number=69)
+        self.assertEqual(stdout.getvalue(), 'Error in file "clown.txt" on line 69:\nThe igloos are melting!\n')
+
+
 if __name__ == "__main__":
     unittest.main()