Skip to content

Commit 03b15fb

Browse files
author
Jussi Kukkonen
committed
tests: Configure logging for all test files
all test_*.py files now accept zero or more '-v' to increase tuf logging level. The default is now ERROR. default: ERROR "-v": ERROR, but unittest prints test names "-vv": WARNING "-vvv": INFO "-vvvv": DEBUG Example to run a single test with DEBUG level: python3 test_updater.py -vvvv TestUpdater.test_4_refresh Also make test_log.py restore the log level it modifies during test. Fixes #1093 Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent aad3bd4 commit 03b15fb

27 files changed

+105
-2
lines changed

tests/test_api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from datetime import datetime, timedelta
1818
from dateutil.relativedelta import relativedelta
1919

20+
import utils
21+
2022
# TODO: Remove case handling when fully dropping support for versions >= 3.6
2123
IS_PY_VERSION_SUPPORTED = sys.version_info >= (3, 6)
2224

@@ -258,4 +260,5 @@ def test_metadata_timestamp(self):
258260

259261
# Run unit test.
260262
if __name__ == '__main__':
263+
utils.configure_test_logging(sys.argv)
261264
unittest.main()

tests/test_arbitrary_package_attack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import subprocess
4545
import logging
4646
import unittest
47+
import sys
4748

4849
import tuf
4950
import tuf.formats
@@ -302,4 +303,5 @@ def test_with_tuf_and_metadata_tampering(self):
302303

303304

304305
if __name__ == '__main__':
306+
utils.configure_test_logging(sys.argv)
305307
unittest.main()

tests/test_developer_tool.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import logging
2727
import tempfile
2828
import shutil
29+
import sys
2930

3031
import tuf
3132
import tuf.log
@@ -40,6 +41,8 @@
4041
from tuf.developer_tool import METADATA_DIRECTORY_NAME
4142
from tuf.developer_tool import TARGETS_DIRECTORY_NAME
4243

44+
import utils
45+
4346
logger = logging.getLogger(__name__)
4447

4548
developer_tool.disable_console_log_messages()
@@ -423,4 +426,5 @@ def test_write(self):
423426

424427

425428
if __name__ == '__main__':
429+
utils.configure_test_logging(sys.argv)
426430
unittest.main()

tests/test_download.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,5 @@ def popen_python(command_arg_list):
391391

392392
# Run unit test.
393393
if __name__ == '__main__':
394+
utils.configure_test_logging(sys.argv)
394395
unittest.main()

tests/test_endless_data_attack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import subprocess
4848
import logging
4949
import unittest
50+
import sys
5051

5152
import tuf
5253
import tuf.formats
@@ -290,4 +291,5 @@ def test_with_tuf(self):
290291

291292

292293
if __name__ == '__main__':
294+
utils.configure_test_logging(sys.argv)
293295
unittest.main()

tests/test_extraneous_dependencies_attack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import subprocess
5151
import logging
5252
import unittest
53+
import sys
5354

5455
import tuf.formats
5556
import tuf.log
@@ -234,4 +235,5 @@ def test_with_tuf(self):
234235

235236

236237
if __name__ == '__main__':
238+
utils.configure_test_logging(sys.argv)
237239
unittest.main()

tests/test_formats.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@
3030

3131
import unittest
3232
import datetime
33+
import sys
3334

3435
import tuf
3536
import tuf.formats
3637

38+
import utils
39+
3740
import securesystemslib
3841
import six
3942

@@ -968,4 +971,5 @@ def test_encode_canonical(self):
968971

969972
# Run unit test.
970973
if __name__ == '__main__':
974+
utils.configure_test_logging(sys.argv)
971975
unittest.main()

tests/test_indefinite_freeze_attack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import subprocess
5454
import logging
5555
import unittest
56+
import sys
5657

5758
import tuf.formats
5859
import tuf.log
@@ -504,4 +505,5 @@ def test_with_tuf(self):
504505

505506

506507
if __name__ == '__main__':
508+
utils.configure_test_logging(sys.argv)
507509
unittest.main()

tests/test_key_revocation_integration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import random
4545
import subprocess
4646
import unittest
47+
import sys
4748

4849
import tuf
4950
import tuf.log
@@ -514,4 +515,5 @@ def _load_role_keys(keystore_directory):
514515

515516

516517
if __name__ == '__main__':
518+
utils.configure_test_logging(sys.argv)
517519
unittest.main()

tests/test_keydb.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import unittest
3232
import logging
33+
import sys
3334

3435
import tuf
3536
import tuf.formats
@@ -38,6 +39,8 @@
3839
import tuf.keydb
3940
import tuf.log
4041

42+
import utils
43+
4144
logger = logging.getLogger(__name__)
4245

4346

@@ -408,4 +411,5 @@ def test_create_keydb_from_root_metadata(self):
408411

409412
# Run unit test.
410413
if __name__ == '__main__':
414+
utils.configure_test_logging(sys.argv)
411415
unittest.main()

tests/test_log.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import unittest
2525
import os
2626
import shutil
27+
import sys
2728

2829
import tuf
2930
import tuf.log
@@ -32,6 +33,8 @@
3233
import securesystemslib
3334
import securesystemslib.util
3435

36+
import utils
37+
3538
from six.moves import reload_module
3639

3740
# We explicitly create a logger which is a child of the tuf hierarchy,
@@ -46,10 +49,15 @@
4649

4750
class TestLog(unittest.TestCase):
4851

52+
def setUp(self):
53+
# store the current log level so it can be restored after the test
54+
self._initial_level = logging.getLogger('tuf').level
4955

5056
def tearDown(self):
5157
tuf.log.remove_console_handler()
5258
tuf.log.disable_file_logging()
59+
logging.getLogger('tuf').level = self._initial_level
60+
5361

5462

5563

@@ -198,4 +206,5 @@ def test_disable_file_logging(self):
198206

199207
# Run unit test.
200208
if __name__ == '__main__':
209+
utils.configure_test_logging(sys.argv)
201210
unittest.main()

tests/test_mirrors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@
2929
from __future__ import unicode_literals
3030

3131
import unittest
32+
import sys
3233

3334
import tuf.mirrors as mirrors
3435
import tuf.unittest_toolbox as unittest_toolbox
3536

37+
import utils
38+
3639
import securesystemslib
3740
import securesystemslib.util
3841
import six
@@ -111,4 +114,5 @@ def test_get_list_of_mirrors(self):
111114

112115
# Run the unittests
113116
if __name__ == '__main__':
117+
utils.configure_test_logging(sys.argv)
114118
unittest.main()

tests/test_mix_and_match_attack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import subprocess
4646
import logging
4747
import unittest
48+
import sys
4849

4950
import tuf.exceptions
5051
import tuf.log
@@ -255,4 +256,5 @@ def test_with_tuf(self):
255256

256257

257258
if __name__ == '__main__':
259+
utils.configure_test_logging(sys.argv)
258260
unittest.main()

tests/test_multiple_repositories_integration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import shutil
3838
import unittest
3939
import json
40+
import sys
4041

4142
import tuf
4243
import tuf.log
@@ -301,4 +302,5 @@ def test_repository_tool(self):
301302

302303

303304
if __name__ == '__main__':
305+
utils.configure_test_logging(sys.argv)
304306
unittest.main()

tests/test_proxy_use.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,4 +380,5 @@ def popen_python(command_arg_list):
380380

381381
# Run unit test.
382382
if __name__ == '__main__':
383+
utils.configure_test_logging(sys.argv)
383384
unittest.main()

tests/test_replay_attack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import subprocess
4747
import logging
4848
import unittest
49+
import sys
4950

5051
import tuf.formats
5152
import tuf.log
@@ -338,4 +339,5 @@ def test_with_tuf(self):
338339

339340

340341
if __name__ == '__main__':
342+
utils.configure_test_logging(sys.argv)
341343
unittest.main()

tests/test_repository_lib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import shutil
3838
import unittest
3939
import copy
40+
import sys
4041

4142
import tuf
4243
import tuf.formats
@@ -49,6 +50,8 @@
4950
import tuf.repository_lib as repo_lib
5051
import tuf.repository_tool as repo_tool
5152

53+
import utils
54+
5255
import securesystemslib
5356
import securesystemslib.exceptions
5457
import securesystemslib.rsa_keys
@@ -1057,4 +1060,5 @@ def test__remove_invalid_and_duplicate_signatures(self):
10571060

10581061
# Run the test cases.
10591062
if __name__ == '__main__':
1063+
utils.configure_test_logging(sys.argv)
10601064
unittest.main()

tests/test_repository_tool.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,19 @@
3535
import logging
3636
import tempfile
3737
import shutil
38+
import sys
3839

3940
import tuf
4041
import tuf.log
4142
import tuf.formats
4243
import tuf.roledb
4344
import tuf.keydb
44-
4545
import tuf.repository_tool as repo_tool
46-
import securesystemslib.exceptions
46+
47+
import utils
4748

4849
import securesystemslib
50+
import securesystemslib.exceptions
4951
import securesystemslib.storage
5052

5153
logger = logging.getLogger(__name__)
@@ -2194,4 +2196,5 @@ def test_append_signature(self):
21942196

21952197
# Run the test cases.
21962198
if __name__ == '__main__':
2199+
utils.configure_test_logging(sys.argv)
21972200
unittest.main()

tests/test_roledb.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@
3030

3131
import unittest
3232
import logging
33+
import sys
3334

3435
import tuf
3536
import tuf.formats
3637
import tuf.roledb
3738
import tuf.exceptions
3839
import tuf.log
3940

41+
import utils
42+
4043
import securesystemslib
4144
import securesystemslib.keys
4245

@@ -788,4 +791,5 @@ def tearDownModule():
788791

789792
# Run the unit tests.
790793
if __name__ == '__main__':
794+
utils.configure_test_logging(sys.argv)
791795
unittest.main()

tests/test_root_versioning_integration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import tempfile
3131
import shutil
3232
import unittest
33+
import sys
3334

3435
import tuf
3536
import tuf.log
@@ -39,6 +40,8 @@
3940
import tuf.keydb
4041
import tuf.repository_tool as repo_tool
4142

43+
import utils
44+
4245
import securesystemslib
4346
import securesystemslib.storage
4447

@@ -227,4 +230,5 @@ def test_root_role_versioning(self):
227230

228231

229232
if __name__ == '__main__':
233+
utils.configure_test_logging(sys.argv)
230234
unittest.main()

tests/test_sig.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import unittest
3333
import logging
3434
import copy
35+
import sys
3536

3637
import tuf
3738
import tuf.log
@@ -41,6 +42,8 @@
4142
import tuf.sig
4243
import tuf.exceptions
4344

45+
import utils
46+
4447
import securesystemslib
4548
import securesystemslib.keys
4649

@@ -547,4 +550,5 @@ def test_signable_has_invalid_format(self):
547550

548551
# Run unit test.
549552
if __name__ == '__main__':
553+
utils.configure_test_logging(sys.argv)
550554
unittest.main()

0 commit comments

Comments
 (0)