[CalendarServer-changes] [11418] CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/ python
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jun 26 01:15:25 PDT 2013
Revision: 11418
http://trac.calendarserver.org//changeset/11418
Author: glyph at apple.com
Date: 2013-06-26 01:15:25 -0700 (Wed, 26 Jun 2013)
Log Message:
-----------
Bytes, not unicode; start thinking about acutal 'checkin' function; some simple verification for subprocess checkin test harness.
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:15:07 UTC (rev 11417)
+++ CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/launchd.py 2013-06-26 08:15:25 UTC (rev 11418)
@@ -21,6 +21,8 @@
from __future__ import print_function
+import sys
+
from cffi import FFI
ffi = FFI()
@@ -183,9 +185,7 @@
cvalue = lib.launch_data_get_string(launchvalue)
if cvalue == ffi.NULL:
return None
- pybytes = ffi.string(cvalue)
- pyunicode = pybytes.decode('utf-8')
- return pyunicode
+ return ffi.string(cvalue)
elif dtype == lib.LAUNCH_DATA_OPAQUE:
return launchvalue
elif dtype == lib.LAUNCH_DATA_ERRNO:
@@ -195,8 +195,14 @@
else:
raise TypeError("Unknown Launch Data Type", dtype)
-import sys
+
+def checkin():
+ """
+ Perform a launchd checkin, returning a Pythonic wrapped data structure
+ representing the retrieved check-in plist.
+ """
+
def getLaunchDSocketFDs():
result = {}
req = lib.launch_data_new_string(lib.LAUNCH_KEY_CHECKIN)
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:15:07 UTC (rev 11417)
+++ CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/test/test_launchd.py 2013-06-26 08:15:25 UTC (rev 11418)
@@ -18,9 +18,22 @@
Tests for L{twext.python.launchd}.
"""
+import sys, os, plistlib
+
+if __name__ == '__main__':
+ import time
+ sys.stdout.write("HELLO WORLD\n")
+ sys.stderr.write("ERROR WORLD\n")
+ sys.stdout.flush()
+ sys.stderr.flush()
+ time.sleep(1)
+ sys.exit(0)
+
+
from twext.python.launchd import lib, ffi, LaunchDictionary, LaunchArray
from twisted.trial.unittest import TestCase
+from twisted.python.filepath import FilePath
class DictionaryTests(TestCase):
"""
@@ -61,7 +74,7 @@
"""
dictionary = LaunchDictionary(self.testDict)
self.assertEquals(set(dictionary.keys()),
- set([u"alpha", u"beta", u"gamma"]))
+ set([b"alpha", b"beta", b"gamma"]))
def test_launchDictionaryValues(self):
@@ -71,7 +84,7 @@
"""
dictionary = LaunchDictionary(self.testDict)
self.assertEquals(set(dictionary.values()),
- set([u"alpha-value", u"beta-value", 3]))
+ set([b"alpha-value", b"beta-value", 3]))
def test_launchDictionaryItems(self):
@@ -81,8 +94,8 @@
"""
dictionary = LaunchDictionary(self.testDict)
self.assertEquals(set(dictionary.items()),
- set([(u"alpha", u"alpha-value"),
- (u"beta", u"beta-value"), (u"gamma", 3)]))
+ set([(b"alpha", b"alpha-value"),
+ (b"beta", b"beta-value"), (b"gamma", 3)]))
class ArrayTests(TestCase):
@@ -122,8 +135,8 @@
C{LaunchArray(...)[n]} returns the n'th element in the array.
"""
array = LaunchArray(self.testArray)
- self.assertEquals(array[0], u"test-string-1")
- self.assertEquals(array[1], u"another string.")
+ self.assertEquals(array[0], b"test-string-1")
+ self.assertEquals(array[1], b"another string.")
self.assertEquals(array[2], 4321)
@@ -142,8 +155,42 @@
"""
array = LaunchArray(self.testArray)
i = iter(array)
- self.assertEquals(i.next(), u"test-string-1")
- self.assertEquals(i.next(), u"another string.")
+ self.assertEquals(i.next(), b"test-string-1")
+ self.assertEquals(i.next(), b"another string.")
self.assertEquals(i.next(), 4321)
self.assertRaises(StopIteration, i.next)
+
+
+class CheckInTests(TestCase):
+ """
+ Integration tests making sure that actual checkin with launchd results in
+ the expected values.
+ """
+
+ def setUp(self):
+ fp = FilePath(self.mktemp())
+ fp.makedirs()
+ plist = {
+ "Label": "org.calendarserver.UNIT-TESTS." + repr(os.getpid()),
+ "ProgramArguments": [sys.executable, "-m", __name__],
+ "EnvironmentVariables": dict(os.environ),
+ "KeepAlive": False,
+ "StandardOutPath": fp.child("stdout.txt").path,
+ "StandardErrorPath": fp.child("stderr.txt").path,
+ "RunAtLoad": True,
+ }
+ self.job = fp.child("job.plist")
+ self.job.setContent(plistlib.writePlistToString(plist))
+ os.spawnlp(os.P_WAIT, "launchctl", "launchctl", "load", self.job.path)
+
+
+ def test_something(self):
+ """
+ Test something.
+ """
+
+
+ def tearDown(self):
+ os.spawnlp(os.P_WAIT, "launchctl", "launchctl", "unload", self.job.path)
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130626/2a244b8b/attachment.html>
More information about the calendarserver-changes
mailing list