diff options
author | Gergely Risko <gergely+context@risko.hu> | 2009-11-04 15:58:15 +0200 |
---|---|---|
committer | Gergely Risko <gergely+context@risko.hu> | 2009-11-04 15:58:15 +0200 |
commit | 85e1a7f271c389e1228151aea66a88139d9518ea (patch) | |
tree | 680304d83c2ff037e16322f96c785e3005d88fa0 | |
parent | 946119c240feb9398c13f3f4b689698b8d22d2a0 (diff) |
libcontextsubscriber/customer-tests updates for new cltool2
11 files changed, 248 insertions, 357 deletions
diff --git a/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py b/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py index e75f3276..dbf28d54 100755 --- a/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py +++ b/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py @@ -31,7 +31,7 @@ import sys import os import time import unittest -from ContextKit.cltool import CLTool +from ContextKit.cltool2 import CLTool, wanted class Asynchronous(unittest.TestCase): def testAsynchronicity(self): @@ -60,32 +60,28 @@ class Asynchronous(unittest.TestCase): # start the client provider_slow = CLTool("context-provide", "--v2", "com.nokia.slow", "int","test.slow","42") - provider_slow.expect(CLTool.STDOUT, "Setting key", 10) # wait for it + provider_slow.expect("Setting key") # wait for it provider_fast = CLTool("context-provide", "--v2", "com.nokia.fast", "int","test.fast","44") - provider_fast.expect(CLTool.STDOUT, "Setting key", 10) # wait for it + provider_fast.expect("Setting key") # wait for it context_client = CLTool("context-listen") - context_client.expect(CLTool.STDERR, "Available commands", 10) # wait for it + context_client.expect("Available commands") # wait for it provider_slow.comment("provider_slow sleep time started at" + str(time.time())) provider_slow.send("sleep 3") - provider_slow.expect(CLTool.STDOUT, "Sleeping", 3) # wait for it + provider_slow.expect("Sleeping") # wait for it context_client.send("n test.slow ; n test.fast") # check the fast property - self.assert_(context_client.expect(CLTool.STDOUT, - CLTool.wanted("test.fast", "int", "44"), - 3), # timeout == 3 seconds + self.assert_(context_client.expect(wanted("test.fast", "int", "44")), # timeout == 3 seconds "Bad value for the fast property, wanted 44") fast_time = time.time() context_client.comment("Fast property arrived with good value at: " + str(fast_time)) # check the slow property - self.assert_(context_client.expect(CLTool.STDOUT, - CLTool.wanted("test.slow", "int", "42"), - 10), # timeout == 10 seconds max, but 5 is enough usually + self.assert_(context_client.expect(wanted("test.slow", "int", "42")), # timeout == 10 seconds max, but 5 is enough usually "Bad value for the slow property, wanted 42") slow_time = time.time() context_client.comment("Slow property arrived with good value at: " + str(slow_time)) @@ -97,9 +93,9 @@ class Asynchronous(unittest.TestCase): "The arrival time of the fast and slow property is not far enough from each other") # context_client.printio() - - provider_slow.kill() - provider_fast.kill() + context_client.close() + provider_slow.close() + provider_fast.close() def runTests(): suiteInstallation = unittest.TestLoader().loadTestsFromTestCase(Asynchronous) diff --git a/libcontextsubscriber/customer-tests/asynchronicity/rapidchanges.py b/libcontextsubscriber/customer-tests/asynchronicity/rapidchanges.py index cdb6d345..3ddd5047 100755 --- a/libcontextsubscriber/customer-tests/asynchronicity/rapidchanges.py +++ b/libcontextsubscriber/customer-tests/asynchronicity/rapidchanges.py @@ -27,10 +27,11 @@ ## - resumes the client ## - verifies that the client receives only one valueChanged signal +import re import sys import os import unittest -from ContextKit.cltool import CLTool +from ContextKit.cltool2 import CLTool, wanted class RapidChanges(unittest.TestCase): def testRapidChanges(self): @@ -51,26 +52,32 @@ class RapidChanges(unittest.TestCase): provider_fast = CLTool("context-provide", "--v2", "com.nokia.fast", "int","test.fast","44") - provider_fast.expect(CLTool.STDOUT, "Setting key", 10) + provider_fast.expect("Setting key") context_client = CLTool("context-listen", "test.fast") - self.assert_(context_client.expect(CLTool.STDOUT, - CLTool.wanted("test.fast", "int", "44"), - 3), # timeout == 3 seconds + self.assert_(context_client.expect(wanted("test.fast", "int", "44")), "Bad value for the fast property, wanted 44") context_client.suspend() provider_fast.send("test.fast = 34") - provider_fast.expect(CLTool.STDOUT, "Setting key", 10) + provider_fast.expect("Setting key") provider_fast.send("test.fast = 54") - provider_fast.expect(CLTool.STDOUT, "Setting key", 10) + provider_fast.expect("Setting key") context_client.resume() - # /.^/ is a regexp that doesn't match anything - context_client.expect(CLTool.STDOUT, ".^", 3, wantdump=False) - if context_client.last_output != "test.fast = int:54\n": + + context_client.expect(wanted("test.fast", "int", "54")) + + # the two value changes can happen very close in time, so we + # have to check that beyond the good value there are no other + # value(s) + if len(re.findall("test.fast =", context_client.last_output)) != 1: context_client.printio() self.assert_(False, "expected a single valueChanged") + # not even after waiting one second + self.assertFalse(context_client.expect("test.fast =", wantdump = False, timeout=1), + "expected a single valueChanged") + provider_fast.close() context_client.close() diff --git a/libcontextsubscriber/customer-tests/commander/commander_appearing.py b/libcontextsubscriber/customer-tests/commander/commander_appearing.py index 37d662ef..695db5d0 100755 --- a/libcontextsubscriber/customer-tests/commander/commander_appearing.py +++ b/libcontextsubscriber/customer-tests/commander/commander_appearing.py @@ -35,7 +35,7 @@ import sys import os import unittest -from ContextKit.cltool import CLTool +from ContextKit.cltool2 import CLTool, wanted, wantedUnknown class CommanderAppearing(unittest.TestCase): def tearDown(self): @@ -44,43 +44,33 @@ class CommanderAppearing(unittest.TestCase): def testCommanderFunctionality(self): provider = CLTool("context-provide", "--v2", "com.nokia.test", "int", "test.int", "42") provider.send("dump") - provider.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + provider.expect("Wrote") # wait for it listen = CLTool("context-listen", "test.int") - self.assert_(listen.expect(CLTool.STDOUT, - CLTool.wanted("test.int", "int", "42"), - 10), + self.assert_(listen.expect(wanted("test.int", "int", "42")), "Bad value initially from the real provider, wanted 42") commander = CLTool("context-provide", "--v2") commander.send("add int test.int 4242") commander.send("start") - commander.expect(CLTool.STDOUT, "Added", 10) # wait for it + commander.expect("Added") # wait for it - self.assert_(listen.expect(CLTool.STDOUT, - CLTool.wanted("test.int", "int", "4242"), - 1), + self.assert_(listen.expect(wanted("test.int", "int", "4242")), "Value after commander has been started is wrong, wanted 4242") commander.send("unset test.int") listen.comment("commander commanded test.int to unknown") - self.assert_(listen.expect(CLTool.STDOUT, - CLTool.wantedUnknown("test.int"), - 1), + self.assert_(listen.expect(wantedUnknown("test.int")), "Value after commander has changed it to unknown is wrong") commander.send("test.int = 1235") - self.assert_(listen.expect(CLTool.STDOUT, - CLTool.wanted("test.int", "int", "1235"), - 1), + self.assert_(listen.expect(wanted("test.int", "int", "1235")), "Value after commander has changed it is wrong, wanted 1235") - commander.kill() + commander.close() listen.comment("Commander killed") - self.assert_(listen.expect(CLTool.STDOUT, - CLTool.wanted("test.int", "int", "42"), - 1), + self.assert_(listen.expect(wanted("test.int", "int", "42")), "Value after killing the commander is wrong, wanted 42") def runTests(): diff --git a/libcontextsubscriber/customer-tests/commander/commander_disabled.py b/libcontextsubscriber/customer-tests/commander/commander_disabled.py index 0fffd634..a088e93f 100755 --- a/libcontextsubscriber/customer-tests/commander/commander_disabled.py +++ b/libcontextsubscriber/customer-tests/commander/commander_disabled.py @@ -30,7 +30,7 @@ import sys import os import unittest -from ContextKit.cltool import CLTool +from ContextKit.cltool2 import CLTool, wanted class CommanderDisabled(unittest.TestCase): def tearDown(self): @@ -39,17 +39,14 @@ class CommanderDisabled(unittest.TestCase): def testCommanderFunctionality(self): provider = CLTool("context-provide", "--v2", "contextkit.test", "int", "test.int", "42") provider.send("dump") - provider.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + provider.expect("Wrote") # wait for it commander = CLTool("context-provide", "--v2") commander.send("add int test.int 4242") commander.send("start") - commander.expect(CLTool.STDOUT, "Added", 10) # wait for it + commander.expect("Added") # wait for it os.environ["CONTEXT_CLI_IGNORE_COMMANDER"] = "" listen = CLTool("context-listen", "test.int") - listen.expect(CLTool.STDERR, "Available commands", 10) # wait for it - self.assert_(listen.expect(CLTool.STDOUT, - CLTool.wanted("test.int", "int", "42"), - 3), + self.assert_(listen.expect(wanted("test.int", "int", "42")), "Provider provided value is wrong") def runTests(): diff --git a/libcontextsubscriber/customer-tests/commander/commander_nonexistent.py b/libcontextsubscriber/customer-tests/commander/commander_nonexistent.py index 6bdb8295..e6cb44f0 100755 --- a/libcontextsubscriber/customer-tests/commander/commander_nonexistent.py +++ b/libcontextsubscriber/customer-tests/commander/commander_nonexistent.py @@ -33,7 +33,7 @@ import sys import os import unittest -from ContextKit.cltool import CLTool +from ContextKit.cltool2 import CLTool, wanted class CommanderNonExistent(unittest.TestCase): def tearDown(self): @@ -42,33 +42,27 @@ class CommanderNonExistent(unittest.TestCase): def testCommanderFunctionality(self): provider = CLTool("context-provide", "--v2", "com.nokia.test", "int", "test.int", "42") provider.send("dump") - self.assert_(provider.expect(CLTool.STDOUT, "Wrote", 10)) # wait for it + self.assert_(provider.expect("Wrote")) # wait for it listen = CLTool("context-listen", "test.int", "test.string") - listen.expect(CLTool.STDERR, "Available commands", 10) # wait for starting + listen.expect("Available commands") # wait for starting commander = CLTool("context-provide", "--v2") - commander.send("add string test.int foobar") - commander.send("add string test.string barfoo") - commander.send("start") - commander.expect(CLTool.STDOUT, "Added", 10) # wait for it - commander.expect(CLTool.STDOUT, "Added", 10) # wait for it - self.assert_(listen.expect(CLTool.STDERR, - 'Provider error, bad type for "test.int" wanted: "INT" got: QString', - 1), + # check type-check + commander.send("add string test.int foobar") + commander.expect("Added key: test.int") + self.assert_(listen.expect('Provider error, bad type for "test.int" wanted: "INT" got: QString'), "Type check didn't work") # check the non-existent property - self.assert_(listen.expect(CLTool.STDOUT, - CLTool.wanted("test.string", "QString", "barfoo"), - 1), - "Non-existent property couldn't be commanded") + commander.send("add string test.string barfoo") + commander.expect("Added key: test.string") + self.assert_(listen.expect(wanted("test.string", "QString", "barfoo")), + "Non-existent property couldn't be commanded") # change the type of the non-existent property commander.send("add int test.string 42") - self.assert_(listen.expect(CLTool.STDOUT, - CLTool.wanted("test.string", "int", "42"), - 1), + self.assert_(listen.expect(wanted("test.string", "int", "42")), "Non-existent property's type couldn't be overwritten") def runTests(): diff --git a/libcontextsubscriber/customer-tests/env.sh b/libcontextsubscriber/customer-tests/env.sh index a9c9c5c8..d780b712 100644 --- a/libcontextsubscriber/customer-tests/env.sh +++ b/libcontextsubscriber/customer-tests/env.sh @@ -2,5 +2,6 @@ export PYTHONPATH=$PYTHONPATH:../../../python export CONTEXT_PROVIDERS=. +export CONTEXT_CORE_DECLARATIONS=../../../spec/core.context export LD_LIBRARY_PATH=../../src/.libs:../../../libcontextprovider/src/.libs export PATH=../../../python:../../../libcontextprovider/context-provide:../../cli:../../cls:$PATH diff --git a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py index b4e569a5..f663a52f 100755 --- a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py +++ b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py @@ -26,7 +26,7 @@ import sys import unittest import os -from ContextKit.cltool import CLTool +from ContextKit.cltool2 import CLTool class Subscription(unittest.TestCase): def tearDown(self): @@ -46,7 +46,7 @@ class Subscription(unittest.TestCase): self.assert_(False, "Couldn't find the test time plugins") self.context_client = CLTool("context-listen", "Test.Time") - self.context_client.expect(CLTool.STDERR, "Available commands", 10) # wait for it + self.context_client.expect("Available commands") # wait for it # Copy the declaration file, declaring libcontextsubscribertime1 plugin. os.system('cp time1.context.temp time.context.temp') @@ -54,14 +54,14 @@ class Subscription(unittest.TestCase): #print "now reading" # Expect value coming from plugin libcontextsubscribertime1 - self.assert_(self.context_client.expect(CLTool.STDOUT, "Test.Time = QString:Time1:", 10)) + self.assert_(self.context_client.expect("Test.Time = QString:Time1:")) # Modify the registry so that the key is now provided by libcontextsubscribertime2 os.system('cp time2.context.temp time.context.temp') os.system('mv time.context.temp time.context') # Expect value coming from plugin libcontextsubscribertime2 - self.assert_(self.context_client.expect(CLTool.STDOUT, "Test.Time = QString:Time2:", 10)) + self.assert_(self.context_client.expect("Test.Time = QString:Time2:")) if __name__ == "__main__": sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) diff --git a/libcontextsubscriber/customer-tests/registry/registry.py b/libcontextsubscriber/customer-tests/registry/registry.py index 12dbfbe0..8aaad7b7 100755 --- a/libcontextsubscriber/customer-tests/registry/registry.py +++ b/libcontextsubscriber/customer-tests/registry/registry.py @@ -24,7 +24,7 @@ import sys import os import unittest -from ContextKit.cltool import CLTool +from ContextKit.cltool2 import CLTool class PrintInfoRunning(unittest.TestCase): def tearDown(self): @@ -37,12 +37,12 @@ class PrintInfoRunning(unittest.TestCase): "double", "test.double", "4.231", "truth", "test.truth", "False") provider.send("dump") - self.assert_(provider.expect(CLTool.STDOUT, "Wrote ./context-provide.context", 10)) # wait for it + self.assert_(provider.expect("Wrote ./context-provide.context")) # wait for it info_client = CLTool("context-ls","test.*") returnValue = info_client.wait() self.assertEqual(returnValue, 0, "context-ls exited with return value != 0") - provider.kill() + provider.close() class PrintingProperties(unittest.TestCase): def tearDown(self): @@ -55,21 +55,19 @@ class PrintingProperties(unittest.TestCase): "double", "test.double", "4.231", "truth", "test.truth", "False") provider.send("dump") - self.assert_(provider.expect(CLTool.STDOUT, "Wrote ./context-provide.context", 10), + self.assert_(provider.expect("Wrote ./context-provide.context"), "context-provide.context couldn't been written by context-provide") info_client = CLTool("context-ls","-l","-d","test.*") - expected_results = ["\ntest.int\tINT\tcontextkit-dbus\tsession:com.nokia.test\n", - "\ntest.double\tDOUBLE\tcontextkit-dbus\tsession:com.nokia.test\n", - "\ntest.truth\tTRUTH\tcontextkit-dbus\tsession:com.nokia.test\n", - "\ntest.string\tSTRING\tcontextkit-dbus\tsession:com.nokia.test\n", - "\nDocumentation: A phony but very flexible property.\n"] - - self.assert_(info_client.expectAll(CLTool.STDOUT, - expected_results, - 10), + self.assert_(info_client.expect(["^test.int\tINT\tcontextkit-dbus\tsession:com.nokia.test$", + "^test.double\tDOUBLE\tcontextkit-dbus\tsession:com.nokia.test$", + "^test.truth\tTRUTH\tcontextkit-dbus\tsession:com.nokia.test$", + "^test.string\tSTRING\tcontextkit-dbus\tsession:com.nokia.test$", + "^Documentation: A phony but very flexible property.$"]), "Bad introspection result from context-ls") + provider.close() + def runTests(): suitePrintInfoRunning = unittest.TestLoader().loadTestsFromTestCase(PrintInfoRunning) suiteProperties = unittest.TestLoader().loadTestsFromTestCase(PrintingProperties) diff --git a/libcontextsubscriber/customer-tests/subscription/multiprovider.py b/libcontextsubscriber/customer-tests/subscription/multiprovider.py index 02013797..496d2c2e 100755 --- a/libcontextsubscriber/customer-tests/subscription/multiprovider.py +++ b/libcontextsubscriber/customer-tests/subscription/multiprovider.py @@ -21,73 +21,61 @@ import sys import os import unittest -from ContextKit.cltool import CLTool +from ContextKit.cltool2 import CLTool, wanted, wantedUnknown class MultiProvider(unittest.TestCase): def testMultipleProviders(self): """ Description - This test verifies correct client behavior in the presence of - multiple providers. + This test verifies correct client behavior in the presence of + multiple providers. Steps 1. starts up a client 2. starts two providers (X and Y) providing the same P property 3. X sets P to V1 and verifies that the client got it - 4. Y sets P to V2 and likewise verifies in the client - 5. Y sets P to NULL, the client verifies that P goes back to V1 - 6. Y sets P to V3, the client verifies P == V3 - 7. Y is removed from the registry, client verifies that P == V1 - 8. X is removed from the registry, client verifies that P == NULL + 4. Y sets P to V2 and likewise verifies in the client + 5. Y sets P to NULL, the client verifies that P goes back to V1 + 6. Y sets P to V3, the client verifies P == V3 + 7. Y is removed from the registry, client verifies that P == V1 + 8. X is removed from the registry, client verifies that P == NULL """ client = CLTool("context-listen", "test.prop") - client.expect(CLTool.STDERR, "Available commands", 3) + client.expect("Available commands") provider_x = CLTool("context-provide", "--v2", "test.X", - "int", "test.prop", "44") - provider_x.send("dump x.context") - provider_x.expect(CLTool.STDOUT, "Wrote", 10) + "int", "test.prop", "44") + provider_x.send("dump x.context") + provider_x.expect("Wrote") provider_y = CLTool("context-provide", "--v2", "test.Y", - "int", "test.prop", "22") - provider_y.send("dump y.context") - provider_y.expect(CLTool.STDOUT, "Wrote", 10) + "int", "test.prop", "22") + provider_y.send("dump y.context") + provider_y.expect("Wrote") - provider_x.send("test.prop = 55"); - provider_x.expect(CLTool.STDOUT, "Setting key", 10) - self.assert_(client.expect(CLTool.STDOUT, - CLTool.wanted("test.prop", "int", "55"), - 3)) + provider_x.send("test.prop = 55"); + provider_x.expect("Setting key") + self.assert_(client.expect(wanted("test.prop", "int", "55"))) - provider_y.send("test.prop = 77"); - provider_y.expect(CLTool.STDOUT, "Setting key", 10) - self.assert_(client.expect(CLTool.STDOUT, - CLTool.wanted("test.prop", "int", "77"), - 3)) + provider_y.send("test.prop = 77"); + provider_y.expect("Setting key") + self.assert_(client.expect(wanted("test.prop", "int", "77"))) - provider_y.send("unset test.prop"); - provider_y.expect(CLTool.STDOUT, "Setting key", 10) - self.assert_(client.expect(CLTool.STDOUT, - CLTool.wanted("test.prop", "int", "55"), - 3)) + provider_y.send("unset test.prop"); + provider_y.expect("Setting key") + self.assert_(client.expect(wanted("test.prop", "int", "55"))) - provider_y.send("test.prop = 99"); - provider_y.expect(CLTool.STDOUT, "Setting key", 10) - self.assert_(client.expect(CLTool.STDOUT, - CLTool.wanted("test.prop", "int", "99"), - 3)) + provider_y.send("test.prop = 99"); + provider_y.expect("Setting key") + self.assert_(client.expect(wanted("test.prop", "int", "99"))) - provider_y.close() - os.unlink("y.context") - self.assert_(client.expect(CLTool.STDOUT, - CLTool.wanted("test.prop", "int", "55"), - 3)) + provider_y.close() + os.unlink("y.context") + self.assert_(client.expect(wanted("test.prop", "int", "55"))) - provider_x.close() - os.unlink("x.context") - self.assert_(client.expect(CLTool.STDOUT, - CLTool.wantedUnknown("test.prop"), - 3)) + provider_x.close() + os.unlink("x.context") + self.assert_(client.expect(wantedUnknown("test.prop"))) client.close() def runTests(): diff --git a/libcontextsubscriber/customer-tests/subscription/multiprovider2.py b/libcontextsubscriber/customer-tests/subscription/multiprovider2.py index 385eba8e..d64dcf07 100755 --- a/libcontextsubscriber/customer-tests/subscription/multiprovider2.py +++ b/libcontextsubscriber/customer-tests/subscription/multiprovider2.py @@ -22,18 +22,18 @@ import sys import os import unittest import time -from ContextKit.cltool import CLTool +from ContextKit.cltool2 import CLTool class MultiProvider(unittest.TestCase): def tearDown(self): - try: - os.unlink("x.context") - except: - pass - try: - os.unlink("y.context") - except: - pass + try: + os.unlink("x.context") + except: + pass + try: + os.unlink("y.context") + except: + pass def testMultipleProviders2(self): """ @@ -54,25 +54,23 @@ class MultiProvider(unittest.TestCase): provider_x = CLTool("context-provide", "--v2", "test.x", "int", "test.prop", "44") provider_x.send("dump x.context") - provider_x.expect(CLTool.STDOUT, "Wrote", 10) + provider_x.expect("Wrote") provider_y = CLTool("context-provide", "--v2", "test.y", "int", "test.prop", "22") provider_y.send("dump y.context") - provider_y.expect(CLTool.STDOUT, "Wrote", 10) + provider_y.expect("Wrote") client = CLTool("context-listen") - client.expect(CLTool.STDERR, "Available commands", 3) + client.expect("Available commands") provider_x.send("sleep 2") - provider_x.expect(CLTool.STDOUT, "Sleeping", 10) + provider_x.expect("Sleeping") client.send("n test.prop") time.sleep(4) client.send("value test.prop") - self.assert_(client.expect(CLTool.STDOUT, - "\nvalue: int:22\n", - 3)) + self.assert_(client.expect("\nvalue: int:22\n")) client.close() provider_x.close() provider_y.close() diff --git a/libcontextsubscriber/customer-tests/subscription/subscription.py b/libcontextsubscriber/customer-tests/subscription/subscription.py index 62b0c0c5..8f18fe57 100755 --- a/libcontextsubscriber/customer-tests/subscription/subscription.py +++ b/libcontextsubscriber/customer-tests/subscription/subscription.py @@ -27,7 +27,7 @@ import sys import unittest import os -from ContextKit.cltool import CLTool +from ContextKit.cltool2 import CLTool, wanted, wantedUnknown class Subscription(unittest.TestCase): def tearDown(self): @@ -64,54 +64,42 @@ class Subscription(unittest.TestCase): "double","test.double","2.5", "truth","test.truth","True") provider.send("dump") - provider.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + provider.expect("Wrote") # wait for it listen = CLTool("context-listen", "test.double", "test.string", "test.int", "test.truth") self.assert_( - listen.expectAll(CLTool.STDOUT, - ["\ntest.double = double:2.5\n", - "\ntest.int = int:1\n", - "\ntest.string = QString:foobar\n", - "\ntest.truth = bool:true\n"], - 10), + listen.expect(["^test.double = double:2.5$", + "^test.int = int:1$", + "^test.string = QString:foobar$", + "^test.truth = bool:true$"]), "Actual key values pairs do not match expected") provider.send("test.int = 100") - listen.expect(CLTool.STDOUT, "int:100", 10) # wait for it + listen.expect("int:100") # wait for it listen.send("value test.int") self.assert_( - listen.expect(CLTool.STDOUT, - "\nvalue: int:100\n", - 1), + listen.expect("^value: int:100$"), "Value command returned wrong value") listen.send("value test.int defaultValue") self.assert_( - listen.expect(CLTool.STDOUT, - "\nvalue: int:100\n", - 1), + listen.expect("^value: int:100$"), "Value command returned wrong value") provider.send("unset test.int") - listen.expect(CLTool.STDOUT, "Unknown", 10) # wait for it + listen.expect("Unknown") # wait for it listen.send("value test.int") self.assert_( - listen.expect(CLTool.STDOUT, - "\nvalue is Unknown\n", - 1), + listen.expect("^value is Unknown$"), "Value command returned wrong value") listen.send("value test.int defaultValue") self.assert_( - listen.expect(CLTool.STDOUT, - "\nvalue: QString:defaultValue\n", - 1), + listen.expect("^value: QString:defaultValue$"), "Value command returned wrong value") listen.send("key test.int") self.assert_( - listen.expect(CLTool.STDOUT, - "\nkey: test.int\n", - 1), + listen.expect("^key: test.int$"), "Key command returned wrong value") provider.close() @@ -142,36 +130,28 @@ class Subscription(unittest.TestCase): "string","test.string","foobar", "double","test.double","2.5", "truth","test.truth","True") - provider.expect(CLTool.STDOUT, "Setting key: test.truth", 10) # wait for it + provider.expect("Setting key: test.truth") # wait for it provider.send("dump") - provider.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + provider.expect("Wrote") # wait for it listen = CLTool("context-listen", "test.double", "test.string", "test.int", "test.truth") - listen.expectAll(CLTool.STDOUT, - ["\ntest.double = double:2.5\n", - "\ntest.int = int:1\n", - "\ntest.string = QString:foobar\n", - "\ntest.truth = bool:true\n"], - 10) # wait for it + listen.expect(["^test.double = double:2.5$", + "^test.int = int:1$", + "^test.string = QString:foobar$", + "^test.truth = bool:true$"]) # wait for it listen.send("ikey test.int") self.assert_( - listen.expect(CLTool.STDOUT, - "\nikey: test.int\n", - 1), + listen.expect("^ikey: test.int$"), "ikey didn't work") listen.send("man test.truth") self.assert_( - listen.expect(CLTool.STDOUT, - "\nman: A phony but very flexible property.\n", - 1), + listen.expect("^man: A phony but very flexible property.$"), "man didn't work") listen.send("type test.double") self.assert_( - listen.expect(CLTool.STDOUT, - "\ntype: DOUBLE\n", - 1), + listen.expect("^type: DOUBLE$"), "type didn't work") provider.close() listen.close() @@ -182,47 +162,35 @@ class Subscription(unittest.TestCase): "string","test.string","foobar", "double","test.double","2.5", "truth","test.truth","True") - provider.expect(CLTool.STDOUT, "Setting key: test.truth", 10) # wait for it + provider.expect("Setting key: test.truth") # wait for it provider.send("dump") - provider.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + provider.expect("Wrote") # wait for it listen = CLTool("context-listen", "test.double", "test.string", "test.int", "test.truth", "test.fake") - listen.expectAll(CLTool.STDOUT, - ["\ntest.double = double:2.5\n", - "\ntest.int = int:1\n", - "\ntest.string = QString:foobar\n", - "\ntest.truth = bool:true\n"], - 10) # wait for it - - # test querying the type of all properties + listen.expect(["^test.double = double:2.5$", + "^test.int = int:1$", + "^test.string = QString:foobar$", + "^test.truth = bool:true$"]) # wait for it + + # test querying the type of all properties listen.send("type test.int") self.assert_( - listen.expect(CLTool.STDOUT, - "\ntype: INT\n", - 1)) + listen.expect("^type: INT$")) listen.send("type test.double") self.assert_( - listen.expect(CLTool.STDOUT, - "\ntype: DOUBLE\n", - 1)) + listen.expect("^type: DOUBLE$")) listen.send("type test.truth") self.assert_( - listen.expect(CLTool.STDOUT, - "\ntype: TRUTH\n", - 1)) + listen.expect("^type: TRUTH$")) listen.send("type test.string") self.assert_( - listen.expect(CLTool.STDOUT, - "\ntype: STRING\n", - 1)) + listen.expect("^type: STRING$")) listen.send("type test.fake") self.assert_( - listen.expect(CLTool.STDOUT, - "\ntype:\n", - 1)) + listen.expect("^type:$")) provider.close() listen.close() @@ -233,29 +201,23 @@ class Subscription(unittest.TestCase): "string","test.string","foobar", "double","test.double","2.5", "truth","test.truth","True") - provider.expect(CLTool.STDOUT, "Setting key: test.truth", 10) # wait for it + provider.expect("Setting key: test.truth") # wait for it provider.send("dump") - provider.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + provider.expect("Wrote") # wait for it listen = CLTool("context-listen", "test.double", "test.string", "test.int", "test.truth", "test.fake") - listen.expectAll(CLTool.STDOUT, - ["\ntest.double = double:2.5\n", - "\ntest.int = int:1\n", - "\ntest.string = QString:foobar\n", - "\ntest.truth = bool:true\n"], - 10) # wait for it - - # test querying the provider(s) + listen.expect(["^test.double = double:2.5$", + "^test.int = int:1$", + "^test.string = QString:foobar$", + "^test.truth = bool:true$"]) # wait for it + + # test querying the provider(s) listen.send("providers test.int") self.assert_( - listen.expect(CLTool.STDOUT, - "\nproviders: session:com.nokia.test@contextkit-dbus\n", - 1)) + listen.expect("^providers: session:com.nokia.test@contextkit-dbus$")) listen.send("providers test.fake") self.assert_( - listen.expect(CLTool.STDOUT, - "\nproviders:\n", - 1)) + listen.expect("^providers:$")) provider.close() listen.close() @@ -284,17 +246,15 @@ class Subscription(unittest.TestCase): "string","test.string","foobar", "double","test.double","2.5", "truth","test.truth","True") - provider.expect(CLTool.STDOUT, "Setting key: test.truth", 10) # wait for it + provider.expect("Setting key: test.truth") # wait for it provider.send("dump") - provider.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + provider.expect("Wrote") # wait for it listen = CLTool("context-listen", "test.double", "test.string", "test.int", "test.truth") self.assert_( - listen.expectAll(CLTool.STDOUT, - ["\ntest.double = double:2.5\n", - "\ntest.int = int:1\n", - "\ntest.string = QString:foobar\n", - "\ntest.truth = bool:true\n"], - 10), + listen.expect(["^test.double = double:2.5$", + "^test.int = int:1$", + "^test.string = QString:foobar$", + "^test.truth = bool:true$"]), "Actual key values pairs do not match expected") provider.close() listen.close() @@ -320,30 +280,24 @@ class Subscription(unittest.TestCase): None """ provider = CLTool("context-provide", "--v2", "com.nokia.test", "truth", "test.truth", "False") - provider.expect(CLTool.STDOUT, "Setting key: test.truth", 10) # wait for it + provider.expect("Setting key: test.truth") # wait for it provider.send("dump") - provider.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + provider.expect("Wrote") # wait for it provider.send("test.truth = False") - provider.expect(CLTool.STDOUT, "Setting", 10) # wait for it + provider.expect("Setting") # wait for it listen = CLTool("context-listen", "test.truth") self.assert_( - listen.expect(CLTool.STDOUT, - "\ntest.truth = bool:false\n", - 3), + listen.expect("^test.truth = bool:false$"), "setting to false didn't work") provider.send("unset test.truth") self.assert_( - listen.expect(CLTool.STDOUT, - "\ntest.truth is Unknown\n", - 1), + listen.expect("^test.truth is Unknown$"), "setting to unknown didn't work") provider.send("test.truth = True") self.assert_( - listen.expect(CLTool.STDOUT, - "\ntest.truth = bool:true\n", - 1), + listen.expect("^test.truth = bool:true$"), "setting to true didn't work") provider.close() listen.close() @@ -369,30 +323,23 @@ class Subscription(unittest.TestCase): None """ provider = CLTool("context-provide", "--v2", "com.nokia.test", "string", "test.string", "something") - provider.expect(CLTool.STDOUT, "Setting key: test.string", 10) # wait for it + provider.expect("Setting key: test.string") # wait for it provider.send("dump") - provider.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + provider.expect("Wrote") # wait for it listen = CLTool("context-listen", "test.string") - listen.expect(CLTool.STDERR, "Available commands", 10) # wait for it self.assert_( - listen.expect(CLTool.STDOUT, - "\ntest.string = QString:something\n", - 1), + listen.expect("^test.string = QString:something$"), "setting to 'something' didn't work") provider.send('test.string = ""') self.assert_( - listen.expect(CLTool.STDOUT, - "\ntest.string = QString:\n", - 1), + listen.expect("^test.string = QString:$"), "setting to empty string didn't work") provider.send('unset test.string') self.assert_( - listen.expect(CLTool.STDOUT, - "\ntest.string is Unknown\n", - 1), + listen.expect("^test.string is Unknown$"), "setting to null didn't work") provider.close() @@ -405,20 +352,16 @@ class MultipleSubscribers(unittest.TestCase): "string","test.string","foobar", "double","test.double","2.5", "truth","test.truth","True") - self.flexiprovider.expect(CLTool.STDOUT, "Setting key: test.truth", 10) # wait for it + self.flexiprovider.expect("Setting key: test.truth") # wait for it self.flexiprovider.send("dump") - self.flexiprovider.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + self.flexiprovider.expect("Wrote") # wait for it self.context_client1 = CLTool("context-listen","test.int","test.double","test.string","test.truth") self.context_client2 = CLTool("context-listen","test.int","test.double") self.context_client3 = CLTool("context-listen","test.int","test.string","test.truth") self.context_client4 = CLTool("context-listen","test.int","test.double","test.string") - self.context_client1.expect(CLTool.STDERR, "Available commands", 10) # wait for it - self.context_client2.expect(CLTool.STDERR, "Available commands", 10) # wait for it - self.context_client3.expect(CLTool.STDERR, "Available commands", 10) # wait for it - self.context_client4.expect(CLTool.STDERR, "Available commands", 10) # wait for it def tearDown(self): - self.flexiprovider.send("exit") + self.flexiprovider.send("exit") self.flexiprovider.close() self.context_client1.close() self.context_client2.close() @@ -446,23 +389,23 @@ class MultipleSubscribers(unittest.TestCase): None """ - client1_expected = ["\ntest.double = double:2.5\n", - "\ntest.int = int:1\n", - "\ntest.string = QString:foobar\n", - "\ntest.truth = bool:true\n"] - client2_expected = ["\ntest.double = double:2.5\n", - "\ntest.int = int:1\n"] - client3_expected = ["\ntest.int = int:1\n", - "\ntest.string = QString:foobar\n", - "\ntest.truth = bool:true\n"] - client4_expected = ["\ntest.double = double:2.5\n", - "\ntest.int = int:1\n", - "\ntest.string = QString:foobar\n"] - - self.assert_(self.context_client1.expectAll(CLTool.STDOUT, client1_expected, 1), "Actual key values pairs do not match expected") - self.assert_(self.context_client2.expectAll(CLTool.STDOUT, client2_expected, 1), "Actual key values pairs do not match expected") - self.assert_(self.context_client3.expectAll(CLTool.STDOUT, client3_expected, 1), "Actual key values pairs do not match expected") - self.assert_(self.context_client4.expectAll(CLTool.STDOUT, client4_expected, 1), "Actual key values pairs do not match expected") + client1_expected = ["^test.double = double:2.5$", + "^test.int = int:1$", + "^test.string = QString:foobar$", + "^test.truth = bool:true$"] + client2_expected = ["^test.double = double:2.5$", + "^test.int = int:1$"] + client3_expected = ["^test.int = int:1$", + "^test.string = QString:foobar$", + "^test.truth = bool:true$"] + client4_expected = ["^test.double = double:2.5$", + "^test.int = int:1$", + "^test.string = QString:foobar$"] + + self.assert_(self.context_client1.expect(client1_expected), "Actual key values pairs do not match expected") + self.assert_(self.context_client2.expect(client2_expected), "Actual key values pairs do not match expected") + self.assert_(self.context_client3.expect(client3_expected), "Actual key values pairs do not match expected") + self.assert_(self.context_client4.expect(client4_expected), "Actual key values pairs do not match expected") def testValueChanged(self): """ @@ -484,45 +427,45 @@ class MultipleSubscribers(unittest.TestCase): References None """ - client1_expected = ["\ntest.double = double:2.5\n", - "\ntest.int = int:1\n", - "\ntest.string = QString:foobar\n", - "\ntest.truth = bool:true\n"] - client2_expected = ["\ntest.double = double:2.5\n", - "\ntest.int = int:1\n"] - client3_expected = ["\ntest.int = int:1\n", - "\ntest.string = QString:foobar\n", - "\ntest.truth = bool:true\n"] - client4_expected = ["\ntest.double = double:2.5\n", - "\ntest.int = int:1\n", - "\ntest.string = QString:foobar\n"] - - self.assert_(self.context_client1.expectAll(CLTool.STDOUT, client1_expected, 1), "Actual key values pairs do not match expected") - self.assert_(self.context_client2.expectAll(CLTool.STDOUT, client2_expected, 1), "Actual key values pairs do not match expected") - self.assert_(self.context_client3.expectAll(CLTool.STDOUT, client3_expected, 1), "Actual key values pairs do not match expected") - self.assert_(self.context_client4.expectAll(CLTool.STDOUT, client4_expected, 1), "Actual key values pairs do not match expected") + client1_expected = ["^test.double = double:2.5$", + "^test.int = int:1$", + "^test.string = QString:foobar$", + "^test.truth = bool:true$"] + client2_expected = ["^test.double = double:2.5$", + "^test.int = int:1$"] + client3_expected = ["^test.int = int:1$", + "^test.string = QString:foobar$", + "^test.truth = bool:true$"] + client4_expected = ["^test.double = double:2.5$", + "^test.int = int:1$", + "^test.string = QString:foobar$"] + + self.assert_(self.context_client1.expect(client1_expected), "Actual key values pairs do not match expected") + self.assert_(self.context_client2.expect(client2_expected), "Actual key values pairs do not match expected") + self.assert_(self.context_client3.expect(client3_expected), "Actual key values pairs do not match expected") + self.assert_(self.context_client4.expect(client4_expected), "Actual key values pairs do not match expected") self.flexiprovider.send("test.double = -5.3") - client1_expected = "\ntest.double = double:-5.3\n" - client2_expected = "\ntest.double = double:-5.3\n" - client4_expected = "\ntest.double = double:-5.3\n" + client1_expected = "^test.double = double:-5.3$" + client2_expected = "^test.double = double:-5.3$" + client4_expected = "^test.double = double:-5.3$" - self.assert_(self.context_client1.expect(CLTool.STDOUT, client1_expected, 1), "Actual key values pairs do not match expected") - self.assert_(self.context_client2.expect(CLTool.STDOUT, client2_expected, 1), "Actual key values pairs do not match expected") - self.assert_(self.context_client4.expect(CLTool.STDOUT, client4_expected, 1), "Actual key values pairs do not match expected") + self.assert_(self.context_client1.expect(client1_expected), "Actual key values pairs do not match expected") + self.assert_(self.context_client2.expect(client2_expected), "Actual key values pairs do not match expected") + self.assert_(self.context_client4.expect(client4_expected), "Actual key values pairs do not match expected") self.context_client3.send("type test.truth") - client3_expected = "\ntype: TRUTH\n" + client3_expected = "^type: TRUTH$" - self.assert_(self.context_client3.expect(CLTool.STDOUT, client3_expected, 1), "Actual key values pairs do not match expected") + self.assert_(self.context_client3.expect(client3_expected), "Actual key values pairs do not match expected") self.flexiprovider.send("unset test.truth") - client1_expected = "\ntest.truth is Unknown\n" - client3_expected = "\ntest.truth is Unknown\n" + client1_expected = "^test.truth is Unknown$" + client3_expected = "^test.truth is Unknown$" - self.assert_(self.context_client1.expect(CLTool.STDOUT, client1_expected, 1), "Actual key values pairs do not match expected") - self.assert_(self.context_client3.expect(CLTool.STDOUT, client3_expected, 1), "Actual key values pairs do not match expected") + self.assert_(self.context_client1.expect(client1_expected), "Actual key values pairs do not match expected") + self.assert_(self.context_client3.expect(client3_expected), "Actual key values pairs do not match expected") class MultipleProviders(unittest.TestCase): def tearDown(self): @@ -532,32 +475,28 @@ class MultipleProviders(unittest.TestCase): def testTwoProviders(self): provider1 = CLTool("context-provide", "--v2","com.nokia.test", "truth","test.truth","True") - provider1.expect(CLTool.STDOUT, "Setting key: test.truth", 10) # wait for it + provider1.expect("Setting key: test.truth") # wait for it provider1.send("dump context-provide1.context") - provider1.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + provider1.expect("Wrote") # wait for it provider2 = CLTool("context-provide", "--v2","com.nokia.test2", "int","test.int","24") - provider2.expect(CLTool.STDOUT, "Setting key: test.int", 10) # wait for it + provider2.expect("Setting key: test.int") # wait for it provider2.send("dump context-provide2.context") - provider2.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + provider2.expect("Wrote") # wait for it listen = CLTool("context-listen","test.int","test.truth") - listen.expect(CLTool.STDERR, "Available commands", 10) # wait for it + listen.expect("Available commands") # wait for it provider2.send("test.int = -68") self.assert_( - listen.expect(CLTool.STDOUT, - "\ntest.int = int:-68\n", - 1)) + listen.expect("^test.int = int:-68$")) provider1.send("test.truth = False") self.assert_( - listen.expect(CLTool.STDOUT, - "\ntest.truth = bool:false\n", - 1)) + listen.expect("^test.truth = bool:false$")) provider1.close() provider2.close() listen.close() @@ -594,42 +533,30 @@ class SubscriptionPause (unittest.TestCase): self.provider = CLTool("context-provide", "--v2","com.nokia.test", "int","test.int","1") - self.provider.expect(CLTool.STDOUT, "Setting key: test.int", 10) # wait for it + self.provider.expect("Setting key: test.int") # wait for it self.provider.send("dump") - self.provider.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + self.provider.expect("Wrote") # wait for it self.listen = CLTool("context-listen","test.int") - self.listen.expect(CLTool.STDERR, "Available commands", 10) # wait for it self.assert_( - self.listen.expect(CLTool.STDOUT, - "\ntest.int = int:1\n", - 1)) + self.listen.expect("^test.int = int:1$")) self.provider.send("test.int = -5") self.assert_( - self.listen.expect(CLTool.STDOUT, - "\ntest.int = int:-5\n", - 1)) + self.listen.expect("^test.int = int:-5$")) self.listen.send("unsubscribe test.int") self.provider.send("test.int = 3") self.assertFalse( - self.listen.expect(CLTool.STDOUT, - "\ntest.int = int:3\n", - 1, - False)) + self.listen.expect("^test.int = int:3$", wantdump = False)) self.listen.send("subscribe test.int") self.assert_( - self.listen.expect(CLTool.STDOUT, - "\ntest.int = int:3\n", - 1)) + self.listen.expect("^test.int = int:3$")) self.provider.send("test.int = 6") self.assert_( - self.listen.expect(CLTool.STDOUT, - "\ntest.int = int:6\n", - 1)) + self.listen.expect("^test.int = int:6$")) def testWaitForSubscribe(self): """ @@ -654,26 +581,23 @@ class SubscriptionPause (unittest.TestCase): """ self.provider = CLTool("context-provide", "--v2","com.nokia.test", "int","test.int","1") - self.provider.expect(CLTool.STDOUT, "Setting key: test.int", 10) # wait for it + self.provider.expect("Setting key: test.int") # wait for it self.provider.send("dump") - self.provider.expect(CLTool.STDOUT, "Wrote", 10) # wait for it + self.provider.expect("Wrote") # wait for it self.provider.send("sleep 3") - self.provider.expect(CLTool.STDOUT, "Sleep", 10) # wait for it + self.provider.expect("Sleep") # wait for it self.listen = CLTool("context-listen") self.listen.send("new test.int") self.listen.send("waitforsubscription test.int") - expected = ["\ntest.int = int:1\n", - "\nwait finished for test.int\n"] + expected = ["^test.int = int:1$", + "^wait finished for test.int$"] # I don't get it quickly self.assertFalse( - self.listen.expectAll(CLTool.STDOUT, - expected, - 1, - False)) + self.listen.expect(expected, wantdump=False, timeout=1)) # but get it after a while - self.assert_(self.listen.expectAll(CLTool.STDOUT, expected, 5)) + self.assert_(self.listen.expect(expected)) class SubscriptionWaitError (unittest.TestCase): def testWaitForSubscribeFail(self): @@ -694,9 +618,7 @@ class SubscriptionWaitError (unittest.TestCase): context_client.send("n test.nonexistent") context_client.send("w test.nonexistent") - self.assert_(context_client.expect(CLTool.STDOUT, - "wait finished for test.nonexistent", - 3), + self.assert_(context_client.expect("wait finished for test.nonexistent"), "Wait for subscription is probably in a dead state") context_client.close() |