Coverage for core\test_leoApp.py : 98%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2#@+leo-ver=5-thin
3#@+node:ekr.20210901170451.1: * @file ../unittests/core/test_leoApp.py
4#@@first
5"""Tests of leoApp.py"""
6import os
7import zipfile
8from leo.core import leoGlobals as g
9from leo.core.leoTest2 import LeoUnitTest
10#@+others
11#@+node:ekr.20210901170531.1: ** class TestApp(LeoUnitTest)
12class TestApp(LeoUnitTest):
13 """Test cases for leoApp.py"""
14 #@+others
15 #@+node:ekr.20210901140645.11: *3* TestApp.test_official_g_app_directories
16 def test_official_g_app_directories(self):
17 ivars = ('extensionsDir', 'globalConfigDir', 'loadDir', 'testDir')
18 for ivar in ivars:
19 assert hasattr(g.app, ivar), 'missing g.app directory: %s' % ivar
20 val = getattr(g.app, ivar)
21 assert val is not None, 'null g.app directory: %s' % ivar
22 assert g.os_path_exists(g.os_path_abspath(val)), 'non-existent g.app directory: %s' % ivar
23 assert hasattr(g.app, 'homeDir') # May well be None.
24 #@+node:ekr.20210901140645.12: *3* TestApp.test_official_g_app_ivars
25 def test_official_g_app_ivars(self):
26 ivars = (
27 # Global managers.
28 'config',
29 # 'externalFilesController',
30 'loadManager', 'pluginsController', 'recentFilesManager',
31 # Official ivars.
32 'gui',
33 'initing', 'killed', 'quitting',
34 'leoID',
35 'log', 'logIsLocked', 'logWaiting',
36 'nodeIndices',
37 'windowList',
38 # Less-official and might be removed...
39 'batchMode',
40 # 'debugSwitch',
41 'disableSave',
42 'hookError', 'hookFunction',
43 'numberOfUntitledWindows',
44 'realMenuNameDict',
45 # 'searchDict',
46 'scriptDict',
47 )
48 for ivar in ivars:
49 self.assertTrue(hasattr(g.app, ivar))
51 #@+node:ekr.20210909194336.2: *3* TestApp.test_consistency_of_leoApp_tables
52 def test_consistency_of_leoApp_tables(self):
53 delims_d = g.app.language_delims_dict
54 lang_d = g.app.language_extension_dict
55 ext_d = g.app.extension_dict
56 for lang in lang_d:
57 ext = lang_d.get(lang)
58 assert lang in delims_d, lang
59 assert ext in ext_d, ext
60 for ext in ext_d:
61 lang = ext_d.get(ext)
62 assert lang in lang_d, lang
63 #@+node:ekr.20210909194336.3: *3* TestApp.test_lm_openAnyLeoFile
64 def test_lm_openAnyLeoFile(self):
65 lm = g.app.loadManager
66 # Create a zip file for testing.
67 s = 'this is a test file'
68 testDir = g.os_path_join(g.app.loadDir, '..', 'test')
69 assert g.os_path_exists(testDir), testDir
70 path = g.os_path_finalize_join(testDir, 'testzip.zip')
71 if os.path.exists(path):
72 os.remove(path)
73 f = zipfile.ZipFile(path, 'x')
74 assert f, path
75 try:
76 f.writestr('leo-zip-file', s)
77 f.close()
78 # Open the file, and get the contents.
79 f = lm.openAnyLeoFile(path)
80 s2 = f.read()
81 f.close()
82 finally:
83 os.remove(path)
84 self.assertEqual(s, s2)
85 #@+node:ekr.20210909194336.4: *3* TestApp.test_rfm_writeRecentFilesFileHelper
86 def test_rfm_writeRecentFilesFileHelper(self):
87 fn = 'ффф.leo'
88 g.app.recentFilesManager.writeRecentFilesFileHelper(fn)
89 assert g.os_path_exists(fn), fn
90 os.remove(fn)
91 assert not g.os_path_exists(fn), fn
92 #@-others
93#@-others
94#@-leo