|
28 | 28 |
|
29 | 29 | @author: Stijn De Weirdt (Ghent University) |
30 | 30 | """ |
| 31 | +import copy |
31 | 32 | import datetime |
32 | 33 | import logging |
33 | 34 | import os |
|
37 | 38 | from tempfile import NamedTemporaryFile |
38 | 39 |
|
39 | 40 | from vsc.utils import fancylogger |
40 | | -from vsc.utils.generaloption import GeneralOption, HELP_OUTPUT_FORMATS |
| 41 | +from vsc.utils.generaloption import GeneralOption, HELP_OUTPUT_FORMATS, set_columns |
41 | 42 | from vsc.utils.missing import shell_quote, shell_unquote |
42 | 43 | from vsc.utils.optcomplete import gen_cmdline |
43 | 44 | from vsc.utils.run import run_simple |
@@ -118,8 +119,14 @@ class GeneralOptionTest(TestCase): |
118 | 119 | """Tests for general option""" |
119 | 120 |
|
120 | 121 | def setUp(self): |
| 122 | + """Prepare for running test.""" |
121 | 123 | super(GeneralOptionTest, self).setUp() |
122 | 124 | self.setup = vsc_setup() |
| 125 | + self.orig_environ = copy.deepcopy(os.environ) |
| 126 | + |
| 127 | + def tearDown(self): |
| 128 | + """Clean up after running test.""" |
| 129 | + os.environ = self.orig_environ |
123 | 130 |
|
124 | 131 | def test_help_short(self): |
125 | 132 | """Generate short help message""" |
@@ -908,3 +915,26 @@ def test_option_as_value(self): |
908 | 915 | # but first error still wins |
909 | 916 | self._match_testoption1_sysexit(['--store', '--foo', '--nosuchoptiondefinedfoobar'], |
910 | 917 | "Value '--foo' starts with a '-'") |
| 918 | + |
| 919 | + def test_set_columns(self): |
| 920 | + """Test set_columns function.""" |
| 921 | + def reset_columns(): |
| 922 | + """Reset environment to run another test case for set_columns.""" |
| 923 | + if 'COLUMNS' in os.environ: |
| 924 | + del os.environ['COLUMNS'] |
| 925 | + |
| 926 | + reset_columns() |
| 927 | + set_columns() |
| 928 | + cols = os.environ.get('COLUMNS') |
| 929 | + self.assertTrue(cols is None or isinstance(cols, basestring)) |
| 930 | + |
| 931 | + set_columns(cols=10) |
| 932 | + self.assertEqual(os.environ['COLUMNS'], '10') |
| 933 | + |
| 934 | + # $COLUMNS wins |
| 935 | + set_columns(cols=99) |
| 936 | + self.assertEqual(os.environ['COLUMNS'], '10') |
| 937 | + |
| 938 | + del os.environ['COLUMNS'] |
| 939 | + set_columns(cols=99) |
| 940 | + self.assertEqual(os.environ['COLUMNS'], '99') |
0 commit comments