コード例 #1
0
 def test_set_system_vars(self):
     ts = ThreadSafe()
     with self.assertRaises(RuntimeError):
         ts.set_thread_safe("_lock")
     with self.assertRaises(RuntimeError):
         ts.set_thread_safe("_thr_safe_func")
     with self.assertRaises(RuntimeError):
         ts.set_thread_safe("_thr_safe_vars")
コード例 #2
0
 def test_set_ts_all(self):
     ts = ThreadSafe()
     items = ("var1", "var2", "var3")
     for item in items:
         setattr(ts, item, item)
         self.assertFalse(ts.is_thread_safe(item))
     ts.set_thread_safe_all(items)
     for item in items:
         self.assertTrue(ts.is_thread_safe(item))
コード例 #3
0
 def test_unsetted(self):
     ts = ThreadSafe()
     with self.assertRaises(AttributeError):
         ts.set_thread_safe("unsetted")
コード例 #4
0
 def test_func_thread_safe(self):
     ts = ThreadSafe()
     ts.func = self._setter
     ts.set_thread_safe("func")
     self.assertTrue(ts.is_thread_safe("func"))
     ts.func("value")
コード例 #5
0
 def test_func_not_thread_safe(self):
     ts = ThreadSafe()
     ts.func = self._setter
     self.assertFalse(ts.is_thread_safe("func"))
     ts.func("value")
コード例 #6
0
 def test_var_thread_safe(self):
     ts = ThreadSafe()
     ts.var = "value"
     ts.set_thread_safe("var")
     self.assertTrue(ts.is_thread_safe("var"))
     self.assertEqual(ts.var, "value")
コード例 #7
0
 def test_var_not_thread_safe(self):
     ts = ThreadSafe()
     ts.var = "value"
     self.assertFalse(ts.is_thread_safe("var"))
     self.assertEqual(ts.var, "value")