Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sage
Path: blob/develop/build/test/test_config.py
4052 views
1
# -*- coding: utf-8 -*-
2
3
# ****************************************************************************
4
# Copyright (C) 2015 Volker Braun <[email protected]>
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 2 of the License, or
9
# (at your option) any later version.
10
# https://www.gnu.org/licenses/
11
# ****************************************************************************
12
13
14
import unittest
15
from sage_bootstrap.config import Configuration, LOG_LEVELS
16
from .runnable import run_config_with
17
18
19
class ConfigurationTestCase(unittest.TestCase):
20
21
def test_default(self):
22
"""
23
Test the default configuration
24
"""
25
config = Configuration()
26
self.assertEqual(config.log, 'info')
27
self.assertTrue(config.interactive)
28
29
def test_example(self):
30
"""
31
Test all ``SAGE_BOOTSTRAP`` settings
32
"""
33
SAGE_BOOTSTRAP = ' loG:CrItIcAl, interactive:TRUE'
34
result = run_config_with(SAGE_BOOTSTRAP)
35
self.assertEqual(len(result), 4)
36
self.assertEqual(result['log'], u'critical')
37
self.assertTrue(result['interactive'])
38
self.assertEqual(result['stdout'], 'default stdout')
39
self.assertEqual(result['stderr'], 'default stderr')
40
41
def test_logging(self):
42
"""
43
Test that the different log levels are understood
44
"""
45
for level in LOG_LEVELS:
46
self.assertEqual(
47
run_config_with('LOG:{0}'.format(level.upper()))['log'],
48
level)
49
50
def test_overriding(self):
51
"""
52
Test that overriding the isatty detection works
53
"""
54
interactive = run_config_with('interactive:true')
55
self.assertTrue(interactive['interactive'])
56
self.assertEqual(interactive['stdout'], 'default stdout')
57
self.assertEqual(interactive['stderr'], 'default stderr')
58
in_pipe = run_config_with('interactive:false')
59
self.assertFalse(in_pipe['interactive'])
60
self.assertEqual(in_pipe['stdout'],
61
u"<class 'sage_bootstrap.stdio.UnbufferedStream'>")
62
self.assertEqual(in_pipe['stderr'], 'default stderr')
63
64