File: invocation.py

package info (click to toggle)
pymol 3.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 74,084 kB
  • sloc: cpp: 482,660; python: 89,328; ansic: 29,512; javascript: 6,792; sh: 84; makefile: 25
file content (51 lines) | stat: -rw-r--r-- 1,656 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import print_function

import os, sys
from pymol import cmd, testing, stored, invocation

class TestInvocation(testing.PyMOLTestCase):

    @testing.foreach.zip(('.pymolrc.py', '.pymolrc', 'pymolrc.pml', 'pymolrcextra.py'))
    @testing.requires_version('1.7.1')
    def test_get_user_config(self, basename):
        '''
        pymolrc finding test
        '''

        orig = dict((key, os.getenv(key)) for key in ['HOME', 'HOMEDRIVE', 'HOMEPATH', 'PYMOL_PATH'])

        with testing.mkdtemp() as tmpdir:
            os.chdir(tmpdir)
            os.mkdir('abc')

            pwd = os.getcwd()

            if sys.platform.startswith('win'):
                if pwd[1] != ':':
                    raise ValueError('no drive letter')
                os.environ.pop('HOME', None)
                os.environ['HOMEDRIVE'] = pwd[:2]
                os.environ['HOMEPATH'] = pwd[2:] + r'\abc'
            else:
                os.environ['HOME'] = pwd + '/abc'

            pymolrc = os.path.join(pwd, 'abc', basename) 
            with open(pymolrc, 'w') as handle:
                print('# hello', file=handle)

            a = invocation.get_user_config()
            self.assertEqual(pymolrc, os.path.normpath(a[0]))

            pymolrc = os.path.join(pwd, basename)
            with open(pymolrc, 'w') as handle:
                print('# hello', file=handle)

            a = invocation.get_user_config()
            self.assertEqual(pymolrc, os.path.normpath(a[0]))

        for key, value in orig.items():
            if value is None:
                os.environ.pop(key, None)
            else:
                os.environ[key] = value