Skip to content

Commit

Permalink
tests: Configure logging for all test files
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Jussi Kukkonen committed Sep 15, 2020
1 parent aad3bd4 commit 03b15fb
Show file tree
Hide file tree
Showing 27 changed files with 105 additions and 2 deletions.
3 changes: 3 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta

import utils

# TODO: Remove case handling when fully dropping support for versions >= 3.6
IS_PY_VERSION_SUPPORTED = sys.version_info >= (3, 6)

Expand Down Expand Up @@ -258,4 +260,5 @@ def test_metadata_timestamp(self):

# Run unit test.
if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
2 changes: 2 additions & 0 deletions tests/test_arbitrary_package_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import subprocess
import logging
import unittest
import sys

import tuf
import tuf.formats
Expand Down Expand Up @@ -302,4 +303,5 @@ def test_with_tuf_and_metadata_tampering(self):


if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
4 changes: 4 additions & 0 deletions tests/test_developer_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import logging
import tempfile
import shutil
import sys

import tuf
import tuf.log
Expand All @@ -40,6 +41,8 @@
from tuf.developer_tool import METADATA_DIRECTORY_NAME
from tuf.developer_tool import TARGETS_DIRECTORY_NAME

import utils

logger = logging.getLogger(__name__)

developer_tool.disable_console_log_messages()
Expand Down Expand Up @@ -423,4 +426,5 @@ def test_write(self):


if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
1 change: 1 addition & 0 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,5 @@ def popen_python(command_arg_list):

# Run unit test.
if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
2 changes: 2 additions & 0 deletions tests/test_endless_data_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import subprocess
import logging
import unittest
import sys

import tuf
import tuf.formats
Expand Down Expand Up @@ -290,4 +291,5 @@ def test_with_tuf(self):


if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
2 changes: 2 additions & 0 deletions tests/test_extraneous_dependencies_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import subprocess
import logging
import unittest
import sys

import tuf.formats
import tuf.log
Expand Down Expand Up @@ -234,4 +235,5 @@ def test_with_tuf(self):


if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
4 changes: 4 additions & 0 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@

import unittest
import datetime
import sys

import tuf
import tuf.formats

import utils

import securesystemslib
import six

Expand Down Expand Up @@ -968,4 +971,5 @@ def test_encode_canonical(self):

# Run unit test.
if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
2 changes: 2 additions & 0 deletions tests/test_indefinite_freeze_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import subprocess
import logging
import unittest
import sys

import tuf.formats
import tuf.log
Expand Down Expand Up @@ -504,4 +505,5 @@ def test_with_tuf(self):


if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
2 changes: 2 additions & 0 deletions tests/test_key_revocation_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import random
import subprocess
import unittest
import sys

import tuf
import tuf.log
Expand Down Expand Up @@ -514,4 +515,5 @@ def _load_role_keys(keystore_directory):


if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
4 changes: 4 additions & 0 deletions tests/test_keydb.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import unittest
import logging
import sys

import tuf
import tuf.formats
Expand All @@ -38,6 +39,8 @@
import tuf.keydb
import tuf.log

import utils

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -408,4 +411,5 @@ def test_create_keydb_from_root_metadata(self):

# Run unit test.
if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
9 changes: 9 additions & 0 deletions tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import unittest
import os
import shutil
import sys

import tuf
import tuf.log
Expand All @@ -32,6 +33,8 @@
import securesystemslib
import securesystemslib.util

import utils

from six.moves import reload_module

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

class TestLog(unittest.TestCase):

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

def tearDown(self):
tuf.log.remove_console_handler()
tuf.log.disable_file_logging()
logging.getLogger('tuf').level = self._initial_level




Expand Down Expand Up @@ -198,4 +206,5 @@ def test_disable_file_logging(self):

# Run unit test.
if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
4 changes: 4 additions & 0 deletions tests/test_mirrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
from __future__ import unicode_literals

import unittest
import sys

import tuf.mirrors as mirrors
import tuf.unittest_toolbox as unittest_toolbox

import utils

import securesystemslib
import securesystemslib.util
import six
Expand Down Expand Up @@ -111,4 +114,5 @@ def test_get_list_of_mirrors(self):

# Run the unittests
if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
2 changes: 2 additions & 0 deletions tests/test_mix_and_match_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import subprocess
import logging
import unittest
import sys

import tuf.exceptions
import tuf.log
Expand Down Expand Up @@ -255,4 +256,5 @@ def test_with_tuf(self):


if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
2 changes: 2 additions & 0 deletions tests/test_multiple_repositories_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import shutil
import unittest
import json
import sys

import tuf
import tuf.log
Expand Down Expand Up @@ -301,4 +302,5 @@ def test_repository_tool(self):


if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
1 change: 1 addition & 0 deletions tests/test_proxy_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,5 @@ def popen_python(command_arg_list):

# Run unit test.
if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
2 changes: 2 additions & 0 deletions tests/test_replay_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import subprocess
import logging
import unittest
import sys

import tuf.formats
import tuf.log
Expand Down Expand Up @@ -338,4 +339,5 @@ def test_with_tuf(self):


if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
4 changes: 4 additions & 0 deletions tests/test_repository_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import shutil
import unittest
import copy
import sys

import tuf
import tuf.formats
Expand All @@ -49,6 +50,8 @@
import tuf.repository_lib as repo_lib
import tuf.repository_tool as repo_tool

import utils

import securesystemslib
import securesystemslib.exceptions
import securesystemslib.rsa_keys
Expand Down Expand Up @@ -1057,4 +1060,5 @@ def test__remove_invalid_and_duplicate_signatures(self):

# Run the test cases.
if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
7 changes: 5 additions & 2 deletions tests/test_repository_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@
import logging
import tempfile
import shutil
import sys

import tuf
import tuf.log
import tuf.formats
import tuf.roledb
import tuf.keydb

import tuf.repository_tool as repo_tool
import securesystemslib.exceptions

import utils

import securesystemslib
import securesystemslib.exceptions
import securesystemslib.storage

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

# Run the test cases.
if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
4 changes: 4 additions & 0 deletions tests/test_roledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@

import unittest
import logging
import sys

import tuf
import tuf.formats
import tuf.roledb
import tuf.exceptions
import tuf.log

import utils

import securesystemslib
import securesystemslib.keys

Expand Down Expand Up @@ -788,4 +791,5 @@ def tearDownModule():

# Run the unit tests.
if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
4 changes: 4 additions & 0 deletions tests/test_root_versioning_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import tempfile
import shutil
import unittest
import sys

import tuf
import tuf.log
Expand All @@ -39,6 +40,8 @@
import tuf.keydb
import tuf.repository_tool as repo_tool

import utils

import securesystemslib
import securesystemslib.storage

Expand Down Expand Up @@ -227,4 +230,5 @@ def test_root_role_versioning(self):


if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
4 changes: 4 additions & 0 deletions tests/test_sig.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import unittest
import logging
import copy
import sys

import tuf
import tuf.log
Expand All @@ -41,6 +42,8 @@
import tuf.sig
import tuf.exceptions

import utils

import securesystemslib
import securesystemslib.keys

Expand Down Expand Up @@ -547,4 +550,5 @@ def test_signable_has_invalid_format(self):

# Run unit test.
if __name__ == '__main__':
utils.configure_test_logging(sys.argv)
unittest.main()
Loading

0 comments on commit 03b15fb

Please sign in to comment.