~ubuntu-branches/ubuntu/natty/pyside/natty

« back to all changes in this revision

Viewing changes to tests/QtGui/pyside_reload_test.py

  • Committer: Bazaar Package Importer
  • Author(s): Didier Raboud
  • Date: 2011-02-18 18:01:00 UTC
  • mfrom: (1.1.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110218180100-y8aqmcdbcbd6gpeh
Tags: upstream-1.0.0~rc1
ImportĀ upstreamĀ versionĀ 1.0.0~rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import sys
 
3
import shutil
 
4
import unittest
 
5
 
 
6
orig_path = os.path.join(os.path.dirname(__file__))
 
7
workdir = os.getcwd()
 
8
src = os.path.join(orig_path, 'test_module_template.py')
 
9
dst = os.path.join(workdir, 'test_module.py')
 
10
shutil.copyfile(src, dst)
 
11
sys.path.append(workdir)
 
12
 
 
13
def increment_module_value():
 
14
    modfile = open(dst, 'a')
 
15
    modfile.write('MyQWidget.value += 1' + os.linesep)
 
16
    modfile.flush()
 
17
    modfile.close()
 
18
    os.remove(dst + 'c')
 
19
 
 
20
class TestModuleReloading(unittest.TestCase):
 
21
 
 
22
    def testModuleReloading(self):
 
23
        '''Test module reloading with on-the-fly modifications.'''
 
24
 
 
25
        import test_module
 
26
        self.assertEqual(test_module.MyQWidget.value, 10)
 
27
 
 
28
        increment_module_value()
 
29
        reload(sys.modules['test_module'])
 
30
        self.assertEqual(test_module.MyQWidget.value, 11)
 
31
 
 
32
        reload(sys.modules['test_module'])
 
33
        self.assertEqual(test_module.MyQWidget.value, 11)
 
34
 
 
35
        increment_module_value()
 
36
        reload(sys.modules['test_module'])
 
37
        self.assertEqual(test_module.MyQWidget.value, 12)
 
38
 
 
39
if __name__ == "__main__":
 
40
    unittest.main()
 
41
 
 
42