Adding the ignore file
[gc-dialer] / tests / test_startup.py
1 from __future__ import with_statement
2
3 import os
4 import time
5 import warnings
6
7 import test_utils
8
9 import sys
10 sys.path.append("../src")
11
12 import dc_glade
13
14
15 def startup(factory):
16         handle = factory()
17         with test_utils.expected(AssertionError("Attempting login before app is fully loaded")):
18                 handle.refresh_session()
19
20         for i in xrange(10):
21                 if handle._initDone:
22                         print "Completed init on iteration %d" % i
23                         break
24                 time.sleep(1)
25         assert handle._initDone
26
27         with test_utils.expected(RuntimeError("Login Failed")):
28                 handle.refresh_session()
29
30         handle._save_settings()
31
32         del handle
33
34
35 def atest_startup_with_no_data_dir_with_dummy_hildon():
36         warnings.simplefilter("always")
37         hildonPath = os.path.join(os.path.dirname(__file__), "dummy_hildon")
38         sys.path.insert(0, hildonPath)
39         import hildon
40         dc_glade.hildon = hildon
41         try:
42                 dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "notexistent_data")
43                 dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
44
45                 try:
46                         startup(dc_glade.Dialcentral)
47                 finally:
48                         try:
49                                 os.remove(dc_glade.Dialcentral._user_settings)
50                         except:
51                                 pass
52                         try:
53                                 os.removedirs(dc_glade.Dialcentral._data_path)
54                         except:
55                                 pass
56         finally:
57                 dc_glade.hildon = None
58                 sys.path.remove(hildonPath)
59                 warnings.resetwarnings()
60
61
62 def atest_startup_with_no_data_dir():
63         warnings.simplefilter("always")
64         dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "notexistent_data")
65         dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
66
67         try:
68                 startup(dc_glade.Dialcentral)
69         finally:
70                 try:
71                         os.remove(dc_glade.Dialcentral._user_settings)
72                 except:
73                         pass
74                 try:
75                         os.removedirs(dc_glade.Dialcentral._data_path)
76                 except:
77                         pass
78                 warnings.resetwarnings()
79
80
81 def atest_startup_with_empty_data_dir():
82         warnings.simplefilter("always")
83         dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "empty_data")
84         dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
85
86         try:
87                 startup(dc_glade.Dialcentral)
88         finally:
89                 try:
90                         os.remove(dc_glade.Dialcentral._user_settings)
91                 except:
92                         pass
93                 try:
94                         os.removedirs(dc_glade.Dialcentral._data_path)
95                 except:
96                         pass
97                 warnings.resetwarnings()
98
99
100 def atest_startup_with_basic_data_dir():
101         warnings.simplefilter("always")
102         try:
103                 dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "basic_data")
104                 dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
105
106                 startup(dc_glade.Dialcentral)
107         finally:
108                 warnings.resetwarnings()