Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sage
Path: blob/develop/build/test/runnable.py
4052 views
1
#!/usr/bin/env sage-bootstrap-python
2
# -*- coding: utf-8 -*-
3
"""
4
Utility to test running with different values for ``SAGE_BOOTSTRAP``
5
"""
6
7
# ****************************************************************************
8
# Copyright (C) 2015 Volker Braun <[email protected]>
9
#
10
# This program is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation, either version 2 of the License, or
13
# (at your option) any later version.
14
# https://www.gnu.org/licenses/
15
# ****************************************************************************
16
17
18
# This function's line numbers are in unit tests, try to not move it
19
# up or down. This is why it is up here at the beginning.
20
def print_log():
21
import logging
22
log = logging.getLogger()
23
log.debug('This is the debug log level')
24
log.info('This is the info log level')
25
log.warning('This is the warning log level')
26
log.critical('This is the critical log level')
27
log.error('This is the error log level')
28
print('This is printed')
29
30
# From here on the line number does not matter
31
32
import sys
33
import os
34
import json
35
import subprocess
36
37
38
def run_with(command, SAGE_BOOTSTRAP):
39
env = dict(os.environ)
40
env['SAGE_BOOTSTRAP'] = SAGE_BOOTSTRAP
41
proc = subprocess.Popen(
42
[sys.executable, __file__, command],
43
env=env,
44
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
45
)
46
out, err = proc.communicate()
47
return out.decode('ascii'), err.decode('ascii')
48
49
50
def run_config_with(SAGE_BOOTSTRAP):
51
out, err = run_with('print_config', SAGE_BOOTSTRAP)
52
assert not err, err
53
return json.loads(out)
54
55
56
def print_config():
57
from sage_bootstrap.config import Configuration
58
from sage_bootstrap.stdio import REAL_STDOUT, REAL_STDERR
59
config = Configuration()
60
result = dict(
61
log=config.log,
62
interactive=config.interactive,
63
stdout='default stdout' if sys.stdout == REAL_STDOUT else str(type(sys.stdout)),
64
stderr='default stderr' if sys.stderr == REAL_STDERR else str(type(sys.stderr)),
65
)
66
print(json.dumps(result))
67
68
69
def run_log_with(SAGE_BOOTSTRAP):
70
return run_with('print_log', SAGE_BOOTSTRAP)
71
72
73
commands = dict(
74
print_config=print_config,
75
print_log=print_log,
76
)
77
78
79
if __name__ == '__main__':
80
sys.path.insert(0,
81
os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
82
import sage_bootstrap
83
commands[sys.argv[1]]()
84
85