Commits

Georg Bauer  committed 8a893c4

added more tests and fixed some problems

  • Participants
  • Parent commits 567a45e

Comments (0)

Files changed (2)

File dynscope/fluids.py

         """
         self._parent = parent
 
-    def _update(self, **kw):
+    def _update(self, items):
         """
         Load a whole dict of variables into the environment.
         Variables starting with _ are not allowed to prevent
         overloading internal controls.
         """
-        keys = [k for k in kw.iterkeys() if not k.startswith('_')]
-        if len(keys) != len(kw):
+        keys = [k for k in items.iterkeys() if not k.startswith('_')]
+        if len(keys) != len(items):
             raise ValueError("dynamic variables must not start with an underscore")
-        self.__dict__.update((k,kw[k]) for k in keys)
+        self.__dict__.update((k,items[k]) for k in keys)
 
     def _find_env(self, attr):
         """

File dynscope/tests.py

         from dynscope import fluid
         fluid.anton = 5
         self.assertEqual(fluid.anton, 5)
+        self.assertRaises(AttributeError, getattr, fluid, 'berta')
 
+    def testStacked(self):
+        from dynscope import fluid, flet
+        fluid.anton = 5
+        with flet(berta=7):
+            self.assertEqual(fluid.anton, 5)
+            self.assertEqual(fluid.berta, 7)
+            with flet(anton=3, berta=2):
+                self.assertEqual(fluid.anton, 3)
+                self.assertEqual(fluid.berta, 2)
+            self.assertEqual(fluid.anton, 5)
+            self.assertEqual(fluid.berta, 7)
+        self.assertEqual(fluid.anton, 5)
+        self.assertRaises(AttributeError, getattr, fluid, 'berta')
+
+class TestCase010Threaded(unittest.TestCase):
+
+    def testThreaded(self):
+        from dynscope import fluid, flet
+        from threading import Thread
+        import time
+
+        fluid.anton = 5
+
+        with flet(anton=7):
+
+            def worker():
+                fluid.anton = 9
+                fluid.berta = 10
+                self.assertEqual(fluid.anton, 9)
+                self.assertEqual(fluid.berta, 10)
+                time.sleep(2)
+
+            t = Thread(target=worker)
+            t.start()
+            self.assertEqual(fluid.anton, 7)
+            t.join()
+
+        self.assertEqual(fluid.anton, 5)
+        self.assertRaises(AttributeError, getattr, fluid, 'berta')
+