~ubuntu-branches/debian/jessie/bibus/jessie

« back to all changes in this revision

Viewing changes to LyX/test/test_constants.py

  • Committer: Bazaar Package Importer
  • Author(s): Jan Beyer
  • Date: 2009-10-12 22:44:05 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091012224405-edpoan0andy2kpmb
Tags: 1.5.0-1
* New upstream release
  - patch fix-BibTeXImport.patch dropped, as it is incorporated upstream
  - patch fix-finalizing-issue.patch dropped, as it is incorporated upstream
  - man-page debian/bibus.1 dropped, as it is incorporated upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: iso-8859-1 -*-
 
3
#file constants_test.py
 
4
 
 
5
"""Test functions and classes in the LyX.constants module
 
6
 
 
7
Revision History:
 
8
 
 
9
2005-02-01 G�nter Milde first version with the unittest framework
 
10
"""
 
11
 
 
12
from unittest import TestCase, main 
 
13
import os
 
14
 
 
15
from LyX import constants
 
16
from LyX.constants import *
 
17
 
 
18
 
 
19
class constantsTests(TestCase):
 
20
    """Test settings in constants.py"""
 
21
    
 
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)
 
27
    
 
28
    def test_SYSTEM_DIR(self):
 
29
        """is SYSTEM_DIR valid?
 
30
        
 
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".
 
34
        """
 
35
        self.failUnless(os.path.isdir(SYSTEM_DIR))
 
36
        self.failUnless(os.path.isfile(os.path.join(SYSTEM_DIR,
 
37
                                                    'chkconfig.ltx')),
 
38
                       "'%s' doesnot contain file chkconfig.ltx"%SYSTEM_DIR)
 
39
        
 
40
    def test_USER_DIR(self):
 
41
        """is USER_DIR valid?"""
 
42
        self.failUnless(os.path.isdir(USER_DIR))
 
43
        
 
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)
 
48
        
 
49
    def test_SERVERPIPE(self):
 
50
        """does SERVERPIPE match the system specification?
 
51
        
 
52
        Check Environment variable and LYXRC_FILE"""
 
53
        serverpipe = os.environ.get("LYXPIPE")
 
54
        if not serverpipe:
 
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)
 
59
 
 
60
    # def test_LYX_OPTIONS(self):
 
61
    #     """LYX_OPTIONS will be tested together with filter_options()"""
 
62
    #     pass
 
63
    
 
64
    def test_setup(self):
 
65
        """setup() shall load a user config file and normalize paths
 
66
        
 
67
        Write a 'mock' config file
 
68
        Set RC_FILE.
 
69
        Call setup() and see whether the settings are recognized and normalized
 
70
        """
 
71
        testsettings = ['SERVERPIPE = "~/.lyxpipe"',
 
72
                        'LYXRC_FILE = "/usr/local/lyx/preferences"'
 
73
                       ]
 
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))
 
78
        mock_rc.close()
 
79
        # call setup() to  evaluate the new RC_FILE
 
80
        setup()
 
81
        os.remove(mock_rc_name)
 
82
        # check for the new settings
 
83
        self.assertEqual(os.path.expanduser("~/.lyxpipe"),
 
84
                         constants.SERVERPIPE)
 
85
        self.assertEqual(os.path.abspath("/usr/local/lyx/preferences"),
 
86
                         constants.LYXRC_FILE)
 
87
        
 
88
 
 
89
 
 
90
if __name__ == '__main__':    #run tests if called from command-line
 
91
    main()