summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-01-19 11:20:29 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-01-19 17:49:30 -0300
commitdc0a3de17e9786037746cb02fb52e342f8cae34c (patch)
tree29324ddcb1a4cf8d39998f25154f7f80fcfebcfa /tests
parent4721af29a2225389528ba5984c53ab551058e690 (diff)
downloadshiboken-dc0a3de17e9786037746cb02fb52e342f8cae34c.tar.gz
shiboken-dc0a3de17e9786037746cb02fb52e342f8cae34c.tar.xz
shiboken-dc0a3de17e9786037746cb02fb52e342f8cae34c.zip
Added test for module reloading.
Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Renato Ara├║jo <renato.filho@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/samplebinding/module_reload_test.py42
-rw-r--r--tests/samplebinding/test_module_template.py10
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/samplebinding/module_reload_test.py b/tests/samplebinding/module_reload_test.py
new file mode 100644
index 00000000..1c870fc0
--- /dev/null
+++ b/tests/samplebinding/module_reload_test.py
@@ -0,0 +1,42 @@
+import os
+import sys
+import shutil
+import unittest
+
+orig_path = os.path.join(os.path.dirname(__file__))
+workdir = os.getcwd()
+src = os.path.join(orig_path, 'test_module_template.py')
+dst = os.path.join(workdir, 'test_module.py')
+shutil.copyfile(src, dst)
+sys.path.append(workdir)
+
+def increment_module_value():
+ modfile = open(dst, 'a')
+ modfile.write('MyOtherObjectType.value += 1' + os.linesep)
+ modfile.flush()
+ modfile.close()
+ os.remove(dst + 'c')
+
+class TestModuleReloading(unittest.TestCase):
+
+ def testModuleReloading(self):
+ '''Test module reloading with on-the-fly modifications.'''
+
+ import test_module
+ self.assertEqual(test_module.MyOtherObjectType.value, 10)
+
+ increment_module_value()
+ reload(sys.modules['test_module'])
+ self.assertEqual(test_module.MyOtherObjectType.value, 11)
+
+ reload(sys.modules['test_module'])
+ self.assertEqual(test_module.MyOtherObjectType.value, 11)
+
+ increment_module_value()
+ reload(sys.modules['test_module'])
+ self.assertEqual(test_module.MyOtherObjectType.value, 12)
+
+if __name__ == "__main__":
+ unittest.main()
+
+
diff --git a/tests/samplebinding/test_module_template.py b/tests/samplebinding/test_module_template.py
new file mode 100644
index 00000000..b2e917de
--- /dev/null
+++ b/tests/samplebinding/test_module_template.py
@@ -0,0 +1,10 @@
+from other import *
+from sample import *
+
+
+class MyObjectType(ObjectType):
+ pass
+
+class MyOtherObjectType(OtherObjectType):
+ value = 10
+