[CalendarServer-changes] [11429] CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/ python

source_changes at macosforge.org source_changes at macosforge.org
Wed Jun 26 01:20:29 PDT 2013


Revision: 11429
          http://trac.calendarserver.org//changeset/11429
Author:   glyph at apple.com
Date:     2013-06-26 01:20:29 -0700 (Wed, 26 Jun 2013)
Log Message:
-----------
FD, bool, real; and checkin test passes.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/launchd.py
    CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/test/test_launchd.py

Modified: CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/launchd.py
===================================================================
--- CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/launchd.py	2013-06-26 08:19:30 UTC (rev 11428)
+++ CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/launchd.py	2013-06-26 08:20:29 UTC (rev 11429)
@@ -53,6 +53,9 @@
 launch_data_t launch_data_alloc(launch_data_type_t);
 launch_data_t launch_data_new_string(const char *);
 launch_data_t launch_data_new_integer(long long);
+launch_data_t launch_data_new_fd(int);
+launch_data_t launch_data_new_bool(bool);
+launch_data_t launch_data_new_real(double);
 
 launch_data_t launch_msg(const launch_data_t);
 
@@ -66,7 +69,10 @@
     void (*)(const launch_data_t, const char *, void *),
     void *);
 
+int launch_data_get_fd(const launch_data_t);
+bool launch_data_get_bool(const launch_data_t);
 const char * launch_data_get_string(const launch_data_t);
+double launch_data_get_real(const launch_data_t);
 
 size_t launch_data_array_get_count(const launch_data_t);
 launch_data_t launch_data_array_get_index(const launch_data_t, size_t);
@@ -197,7 +203,7 @@
     elif dtype == lib.LAUNCH_DATA_INTEGER:
         return lib.launch_data_get_integer(launchvalue)
     elif dtype == lib.LAUNCH_DATA_REAL:
-        raise TypeError("REALs unsupported.")
+        return lib.launch_data_get_real(launchvalue)
     elif dtype == lib.LAUNCH_DATA_BOOL:
         return lib.launch_data_get_bool(launchvalue)
     elif dtype == lib.LAUNCH_DATA_STRING:

Modified: CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/test/test_launchd.py
===================================================================
--- CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/test/test_launchd.py	2013-06-26 08:19:30 UTC (rev 11428)
+++ CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/test/test_launchd.py	2013-06-26 08:20:29 UTC (rev 11429)
@@ -35,11 +35,46 @@
 
 
 from twext.python.launchd import (lib, ffi, LaunchDictionary, LaunchArray,
-                                  _managed, constants, plainPython, checkin)
+                                  _managed, constants, plainPython, checkin,
+                                  _launchify)
 
 from twisted.trial.unittest import TestCase
 from twisted.python.filepath import FilePath
 
+
+class LaunchDataStructures(TestCase):
+    """
+    Tests for L{_launchify} converting data structures from launchd's internals
+    to Python objects.
+    """
+
+    def test_fd(self):
+        """
+        Test converting a launchd FD to an integer.
+        """
+        fd = _managed(lib.launch_data_new_fd(2))
+        self.assertEquals(_launchify(fd), 2)
+
+
+    def test_bool(self):
+        """
+        Test converting a launchd bool to a Python bool.
+        """
+        t = _managed(lib.launch_data_new_bool(True))
+        f = _managed(lib.launch_data_new_bool(False))
+        self.assertEqual(_launchify(t), True)
+        self.assertEqual(_launchify(f), False)
+
+
+    def test_real(self):
+        """
+        Test converting a launchd real to a Python float.
+        """
+        notQuitePi = _managed(lib.launch_data_new_real(3.14158))
+        self.assertEqual(_launchify(notQuitePi), 3.14158)
+
+
+
 class DictionaryTests(TestCase):
     """
     Tests for L{LaunchDictionary}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130626/8517bf20/attachment.html>


More information about the calendarserver-changes mailing list