Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/dev/test/config.py
8815 views
1
r"""
2
Configuration wrapper for doctesting
3
4
This module provides a wrapper for ``devrc`` which can be used for doctesting
5
without tampering with the user's ``devrc`` file.
6
7
AUTHORS:
8
9
- Julian Rueth: initial version
10
11
"""
12
#*****************************************************************************
13
# Copyright (C) 2013 Julian Rueth <[email protected]>
14
#
15
# Distributed under the terms of the GNU General Public License (GPL)
16
# as published by the Free Software Foundation; either version 2 of
17
# the License, or (at your option) any later version.
18
# http://www.gnu.org/licenses/
19
#*****************************************************************************
20
21
import os
22
import sage.dev.config
23
24
25
class DoctestConfig(sage.dev.config.Config):
26
r"""
27
A :class:`sage.dev.config.Config` which lives in a temporary file and sets
28
some sensible defaults for doctesting.
29
30
This also initializes an empty git repository in a temporary directory.
31
32
INPUT:
33
34
- ``trac_username`` -- a string (default: ``'doctest'``), a (fake)
35
username on trac
36
37
- ``repository`` - a string or ``None`` (default: ``None``), a
38
remote repository to push to and pull from
39
40
EXAMPLES::
41
42
sage: from sage.dev.test.config import DoctestConfig
43
sage: DoctestConfig()
44
Config('''
45
[trac]
46
username = doctest
47
ticket_cache = ...
48
[UI]
49
log_level = 1
50
[git]
51
ssh_key_set = True
52
repository_anonymous = remote_repository_undefined
53
repository = remote_repository_undefined
54
src = ...
55
dot_git = ...
56
[sagedev]
57
''')
58
"""
59
def __init__(self, trac_username="doctest", repository=None):
60
r"""
61
Initialization.
62
63
TESTS::
64
65
sage: from sage.dev.test.config import DoctestConfig
66
sage: config = DoctestConfig()
67
sage: type(config)
68
<class 'sage.dev.test.config.DoctestConfig'>
69
"""
70
from sage.dev.misc import tmp_dir, tmp_filename
71
self._tmp_dir = tmp_dir()
72
devrc = os.path.join(self._tmp_dir, 'devrc')
73
sage.dev.config.Config.__init__(self, devrc=devrc)
74
75
self['trac'] = {'username': trac_username}
76
77
# Note: ConfigParser allows only string values
78
from sage.dev.user_interface import INFO
79
self['UI'] = {'log_level': str(INFO)}
80
81
self['git'] = {'ssh_key_set': "True"}
82
self['sagedev'] = {}
83
84
self['git']['repository_anonymous'] = \
85
self['git']['repository'] = \
86
repository if repository else "remote_repository_undefined"
87
88
self['trac']['ticket_cache'] = os.path.join(self._tmp_dir, "ticket_cache")
89
repo = os.path.join(self._tmp_dir, 'repo')
90
self['git']['src'] = repo
91
self['git']['dot_git'] = os.path.join(repo, ".git")
92
os.makedirs(self['git']['dot_git'])
93
94
self['git']['user.name'] = trac_username
95
self['git']['user.email'] = '[email protected]'
96
97
from sage.dev.git_interface import GitInterface
98
from sage.dev.test.user_interface import DoctestUserInterface
99
old_cwd = os.getcwd()
100
os.chdir(self['git']['src'])
101
try:
102
GitInterface(
103
self['git'],
104
DoctestUserInterface(self["UI"])
105
).silent.init(self['git']['src'])
106
finally:
107
os.chdir(old_cwd)
108
109