2
# -*- coding: iso-8859-1 -*-
3
#file constants_test.py
5
"""Test functions and classes in the LyX.constants module
9
2005-02-01 G�nter Milde first version with the unittest framework
12
from unittest import TestCase, main
15
from LyX import constants
16
from LyX.constants import *
19
class constantsTests(TestCase):
20
"""Test settings in constants.py"""
22
def test_LYXCMD(self):
23
"""is LYXCMD on the system path?"""
24
cmd = LYXCMD.split()[0]
25
self.assertEqual(0, os.system("which %s"%(cmd)),
26
"'%s' not on path"%LYXCMD)
28
def test_SYSTEM_DIR(self):
29
"""is SYSTEM_DIR valid?
31
`man lyx` says: The system directory is determined by searching
32
for the file "chkconfig.ltx": We first test whether the specified
33
dir exists and second whether it contains "chkconfig.ltx".
35
self.failUnless(os.path.isdir(SYSTEM_DIR))
36
self.failUnless(os.path.isfile(os.path.join(SYSTEM_DIR,
38
"'%s' doesnot contain file chkconfig.ltx"%SYSTEM_DIR)
40
def test_USER_DIR(self):
41
"""is USER_DIR valid?"""
42
self.failUnless(os.path.isdir(USER_DIR))
44
def test_LYXRC_FILE(self):
45
"""is LYXRC_FILE present?"""
46
self.failUnless(os.path.isfile(LYXRC_FILE),
47
"LYXRC_FILE '%s' not found"%LYXRC_FILE)
49
def test_SERVERPIPE(self):
50
"""does SERVERPIPE match the system specification?
52
Check Environment variable and LYXRC_FILE"""
53
serverpipe = os.environ.get("LYXPIPE")
55
for line in file(LYXRC_FILE):
56
if line.startswith(r'\serverpipe'):
57
serverpipe = line.split()[1].strip("\"' \n")
58
self.assertEqual(serverpipe, SERVERPIPE)
60
# def test_LYX_OPTIONS(self):
61
# """LYX_OPTIONS will be tested together with filter_options()"""
65
"""setup() shall load a user config file and normalize paths
67
Write a 'mock' config file
69
Call setup() and see whether the settings are recognized and normalized
71
testsettings = ['SERVERPIPE = "~/.lyxpipe"',
72
'LYXRC_FILE = "/usr/local/lyx/preferences"'
74
mock_rc_name = os.tempnam(None, 'lyxtest')
75
constants.RC_FILE = mock_rc_name
76
mock_rc = file(mock_rc_name, 'w')
77
mock_rc.write("\n".join(testsettings))
79
# call setup() to evaluate the new RC_FILE
81
os.remove(mock_rc_name)
82
# check for the new settings
83
self.assertEqual(os.path.expanduser("~/.lyxpipe"),
85
self.assertEqual(os.path.abspath("/usr/local/lyx/preferences"),
90
if __name__ == '__main__': #run tests if called from command-line