Remove test print statements

This commit is contained in:
vladdd 2013-08-06 14:36:16 -04:00
commit fa88d6e9b6
23 changed files with 97 additions and 115 deletions

View file

@ -79,7 +79,7 @@
'tuf.tests'
],
scripts=[
'quickstart.py',
'tuf/repo/quickstart.py',
'tuf/pushtools/push.py',
'tuf/pushtools/receivetools/receive.py',
'tuf/repo/signercli.py'

View file

@ -55,6 +55,14 @@
logging.Formatter.converter = time.gmtime
formatter = logging.Formatter(_FORMAT_STRING)
# Set the handlers for the logger.
# The built-in stream handler will log
# messages to 'sys.stderr' and capture
# '_DEFAULT_LOG_LEVEL' messages.
stream_handler = logging.StreamHandler()
stream_handler.setLevel(_DEFAULT_LOG_LEVEL)
stream_handler.setFormatter(formatter)
# Set the built-in file handler. Messages
# will be logged to '_DEFAULT_LOG_FILENAME'
# and use the logger's default log level.
@ -65,6 +73,7 @@
# Set the logger and its settings.
logger = logging.getLogger('tuf')
logger.setLevel(_DEFAULT_LOG_LEVEL)
logger.addHandler(stream_handler)
logger.addHandler(file_handler)
# Silently ignore logger exceptions.
@ -97,3 +106,4 @@ def set_log_level(log_level):
"""
logger.setLevel(log_level)
stream_handler.setLevel(log_level)

View file

@ -228,7 +228,6 @@ def build_repository(project_directory):
except ValueError, e:
message = 'Invalid expiration date entered'
logger.error(message)
print(message)
timeout = None
continue
@ -287,7 +286,6 @@ def build_repository(project_directory):
metadata_directory = os.path.join(repository_directory, 'metadata')
message = 'Creating '+repr(metadata_directory)
logger.info(message)
print(message)
os.mkdir(metadata_directory)
except OSError, e:
if e.errno == errno.EEXIST:
@ -326,7 +324,6 @@ def build_repository(project_directory):
except ValueError, e:
message = 'Invalid role threshold entered'
logger.warning(message)
print(message)
role_threshold = None
continue
@ -394,7 +391,6 @@ def build_repository(project_directory):
repr(client_metadata_directory)+'. The client metadata '+\
'will need to be manually created. See the README file.'
logger.warn(message)
print(message)
else:
raise

View file

@ -104,7 +104,6 @@ def _get_password(prompt='Password: ', confirm=False):
else:
message = 'Mismatch; try again.'
logger.info(message)
print(message)
@ -212,15 +211,13 @@ def _list_keyids(keystore_directory, metadata_directory):
if keyid in keyids:
keyids_dict[keyid].append(targets_role)
# Print the keyids without the '.key' extension and the roles
# Log the keyids without the '.key' extension and the roles
# associated with them.
message = 'Listing the keyids in '+repr(keystore_directory)
logger.info(message)
print(message)
for keyid in keyids_dict:
message = keyid+' : '+str(keyids_dict[keyid])
logger.info(message)
print(message)
@ -263,7 +260,6 @@ def _get_keyids(keystore_directory):
if keyid not in loaded_keyid:
message = 'Could not load keyid: '+keyid
logger.error(message)
print(message)
continue
# Append 'keyid' to the loaded list of keyids.
@ -315,7 +311,6 @@ def _get_all_config_keyids(config_filepath, keystore_directory):
if not loaded_key or keyid not in loaded_key:
message = 'Could not load keyid: '+keyid
logger.error(message)
print(message)
continue
loaded_keyids[key].append(keyid)
break
@ -364,7 +359,6 @@ def _get_role_config_keyids(config_filepath, keystore_directory, role):
if not loaded_key or keyid not in loaded_key:
message = 'Could not load keyid: '+keyid
logger.error(message)
print(message)
continue
role_keyids.append(keyid)
break
@ -588,7 +582,7 @@ def generate_rsa_key(keystore_directory):
try:
rsa_key = save_rsa_key(keystore_directory=keystore_directory,
password=password, bits=rsa_key_bits)
print('Generated a new key: '+rsa_key['keyid'])
logger.info('Generated a new key: '+rsa_key['keyid'])
except (tuf.FormatError, tuf.CryptoError), e:
message = 'The RSA key could not be generated. '+str(e)+'\n'
raise tuf.RepositoryError(message)
@ -703,7 +697,6 @@ def dump_key(keystore_directory):
message = '*WARNING* Printing the private key reveals' \
' sensitive information *WARNING*'
logger.warning(message)
print(message)
input = _prompt(prompt, str)
if input.lower() == 'private':
show_private = True
@ -717,7 +710,7 @@ def dump_key(keystore_directory):
raise tuf.RepositoryError(message)
# Print the contents of the key metadata.
print(json.dumps(key_metadata, indent=2, sort_keys=True))
logger.info(json.dumps(key_metadata, indent=2, sort_keys=True))
@ -1050,7 +1043,6 @@ def sign_metadata_file(keystore_directory):
# Retrieve the keyids of the signing keys from the user.
message = 'The keyids that will sign the metadata file must be loaded.'
logger.info(message)
print(message)
loaded_keyids = _get_keyids(keystore_directory)
if len(loaded_keyids) == 0:
@ -1182,7 +1174,6 @@ def _load_parent_role(metadata_directory, keystore_directory, targets_roles):
if parent_role not in targets_roles:
message = 'Invalid role name entered'
logger.info(message)
print(message)
parent_role = None
continue
else:
@ -1204,7 +1195,6 @@ def _load_parent_role(metadata_directory, keystore_directory, targets_roles):
if keyid not in loaded_keyid:
message = 'The keyid could not be loaded.'
logger.info(message)
print(message)
continue
parent_keyids.append(loaded_keyid[0])
break
@ -1234,7 +1224,6 @@ def _get_delegated_role(keystore_directory, metadata_directory):
# Retrieve the delegated role\'s keyids from the user.
message = 'The keyid of the delegated role must be loaded.'
logger.info(message)
print(message)
delegated_keyids = _get_keyids(keystore_directory)
# Ensure at least one delegated key was loaded.

View file

@ -4,34 +4,33 @@
<Author>
Konstantin Andrianov
Zane Fisher
<Started>
January 26, 2013
August 2013. Modified previous behavior that explicitly imported individual
unit tests. -Zane Fisher
<Copyright>
See LICENSE for licensing information.
<Purpose>
Run all the unit tests in 'tuf/tests'.
Run all the unit tests from every .py file beginning with "test_" in 'tuf/tests'.
"""
# The unit tests listed below should provide their respective test suites
# and run on import.
import tuf.tests.test_download
import tuf.tests.test_formats
import tuf.tests.test_hash
import tuf.tests.test_keydb
import tuf.tests.test_keystore
import tuf.tests.test_mirrors
import tuf.tests.test_quickstart
import tuf.tests.test_roledb
import tuf.tests.test_rsa_key
import tuf.tests.test_schema
import tuf.tests.test_signercli
import tuf.tests.test_signerlib
import tuf.tests.test_sig
import tuf.tests.test_util
import tuf.tests.test_updater
import tuf.tests.system_tests.test_util_test_tools
import tuf.tests.system_tests.test_replay_attack
import unittest
import glob
import tuf.keydb as keydb
import tuf.repo.keystore as keystore
import tuf.roledb as roledb
tests_list = glob.glob('test_*.py')
# Remove '.py' from each filename.
tests_list = [test[:-3] for test in tests_list]
suite = unittest.TestLoader().loadTestsFromNames(tests_list)
unittest.TextTestRunner(verbosity=2).run(suite)

View file

@ -144,7 +144,7 @@
import tuf.repo.signerlib as signerlib
import tuf.repo.keystore as keystore
logger = logging.getLogger('tuf')
# Disable logging for cleaner output.
def disable_logging():
@ -200,7 +200,7 @@ def cleanup(root_repo, server_process=None):
if server_process.returncode is None:
server_process.kill()
print 'Server terminated.\n'
logger.info('Server terminated.\n')
# Clear the keystore.
keystore.clear_keystore()

View file

@ -22,6 +22,7 @@
"""
import tuf
import tuf.log
import tuf.download as download
import tuf.tests.unittest_toolbox as unittest_toolbox
@ -36,6 +37,8 @@
import SocketServer
import SimpleHTTPServer
logger = logging.getLogger('tuf')
# Disable/Enable logging. Comment-out to Enable logging.
logging.getLogger('tuf')
logging.disable(logging.CRITICAL)
@ -61,9 +64,9 @@ def setUp(self):
self.PORT = random.randint(30000, 45000)
command = ['python', 'simple_server.py', str(self.PORT)]
self.server_proc = subprocess.Popen(command, stderr=subprocess.PIPE)
print '\n\tServer process started.'
print '\tServer process id: '+str(self.server_proc.pid)
print '\tServing on port: '+str(self.PORT)
logger.info('\n\tServer process started.')
logger.info('\tServer process id: '+str(self.server_proc.pid))
logger.info('\tServing on port: '+str(self.PORT))
junk, rel_target_filepath = os.path.split(target_filepath)
self.url = 'http://localhost:'+str(self.PORT)+'/'+rel_target_filepath
@ -83,7 +86,7 @@ def setUp(self):
def tearDown(self):
unittest_toolbox.Modified_TestCase.tearDown(self)
if self.server_proc.returncode is None:
print '\tServer process '+str(self.server_proc.pid)+' terminated.'
logger.info('\tServer process '+str(self.server_proc.pid)+' terminated.')
self.server_proc.kill()
self.target_fileobj.close()
@ -183,5 +186,5 @@ def test_download_url_to_tempfileobj(self):
# Run unit test.
suite = unittest.TestLoader().loadTestsFromTestCase(TestDownload)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -675,5 +675,5 @@ def test_encode_canonical(self):
# Run unit test.
suite = unittest.TestLoader().loadTestsFromTestCase(TestFormats)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -19,17 +19,26 @@
import os
import StringIO
import logging
import tempfile
import unittest
import tuf.hash
logger = logging.getLogger('tuf')
if not 'hashlib' in tuf.hash._supported_libraries:
logger.warn('Not testing hashlib: could not be imported.')
if not 'pycrypto' in tuf.hash._supported_libraries:
logger.warn('Not testing pycrypto: could not be imported.')
class TestHash(unittest.TestCase):
def _run_with_all_hash_libraries(self, test_func):
test_func('hashlib')
test_func('pycrypto')
if 'hashlib' in tuf.hash._supported_libraries:
test_func('hashlib')
if 'pycrypto' in tuf.hash._supported_libraries:
test_func('pycrypto')
def test_md5_update(self):
@ -216,5 +225,5 @@ def _do_update_file_obj(self, library):
# Run unit test.
suite = unittest.TestLoader().loadTestsFromTestCase(TestHash)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -225,5 +225,5 @@ def test_create_keydb_from_root_metadata(self):
# Run unit test.
suite = unittest.TestLoader().loadTestsFromTestCase(TestKeydb)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -321,5 +321,5 @@ def test_internal_decrypt(self):
# Run the unit tests.
suite = unittest.TestLoader().loadTestsFromTestCase(TestKeystore)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -97,5 +97,5 @@ def test_get_list_of_mirrors(self):
# Run the unittests
suite = unittest.TestLoader().loadTestsFromTestCase(TestMirrors)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -18,6 +18,7 @@
import os
import getpass
import logging
import tempfile
import unittest
import ConfigParser
@ -26,13 +27,17 @@
import tuf.pushtools.push as push
import tuf.pushtools.transfer.scp as scp
import tuf.pushtools.pushtoolslib as pushtoolslib
import tuf.tests.system_tests.util_test_tools as util_test_tools
import system_tests.util_test_tools as util_test_tools
logger = logging.getLogger('tuf')
# Disable all logging calls of level CRITICAL and below.
# Comment the line below to enable logging.
logging.disable(logging.CRITICAL)
class TestPush(unittest.TestCase):
src_push_dict = {}
print scp.transfer
logger.info(scp.transfer)
ORIGINAL_PUSH_CONFIG = pushtoolslib.PUSH_CONFIG
@ -160,5 +165,5 @@ def test_expected_behaviour_of_push_with_scp(self):
# Run the unittests
suite = unittest.TestLoader().loadTestsFromTestCase(TestPush)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -165,5 +165,5 @@ def test_exceptions_handeling_of_read_config_file(self):
# Run the unittests
suite = unittest.TestLoader().loadTestsFromTestCase(TestPushtoolslib)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -25,8 +25,8 @@
import shutil
import unittest
import logging
import tuf.repo.quickstart as quickstart
import quickstart
import tuf.util
import tuf.tests.unittest_toolbox
@ -192,5 +192,5 @@ def _remove_repository_directories(repo_dir, keystore_dir, client_dir):
# Run the unit tests.
suite = unittest.TestLoader().loadTestsFromTestCase(TestQuickstart)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -406,5 +406,5 @@ def _test_rolename(self, test_function):
# Run the unit tests.
suite = unittest.TestLoader().loadTestsFromTestCase(TestRoledb)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -180,5 +180,5 @@ def test_verify_signature(self):
# Run the unit tests.
suite = unittest.TestLoader().loadTestsFromTestCase(TestRsa_key)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -326,5 +326,5 @@ def test_RegularExpression(self):
# Run the unit tests.
suite = unittest.TestLoader().loadTestsFromTestCase(TestSchema)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -391,5 +391,5 @@ def test_signable_has_invalid_format(self):
# Run unit test.
suite = unittest.TestLoader().loadTestsFromTestCase(TestSig)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()

View file

@ -1494,8 +1494,6 @@ def _mock_get_keyids(junk):
# Test: normal case 1.
# Testing first level delegation.
print 'delegated_targets_dir: '+str(delegated_targets_dir)
print 'files in delegated_targets_dir: '+repr(os.listdir(delegated_targets_dir))
signercli.make_delegation(keystore_dir)
# Verify delegated metadata file exists.
@ -1559,10 +1557,5 @@ def _mock_get_keyids(junk):
signercli._get_metadata_directory = original_get_metadata_directory
# Run unit tests.
loader = unittest_toolbox.unittest.TestLoader
suite = loader().loadTestsFromTestCase(TestSignercli)
try:
unittest_toolbox.unittest.TextTestRunner(verbosity=2).run(suite)
finally:
unittest_toolbox.Modified_TestCase.clear_toolbox()
if __name__ == '__main__':
unittest.main()

View file

@ -960,7 +960,7 @@ def _get_role_info(self, role, directory=None):
return timestamp_meta, role_keyids, meta_dir
else:
print '\nUnrecognized top-level role.'
logger.warning('\nUnrecognized top-level role.')
@ -976,11 +976,5 @@ def _get_signed_role_info(self, role, directory=None):
return signed_meta, role_info
# Run unit test.
suite = unittest.TestLoader().loadTestsFromTestCase(TestSignerlib)
try:
unittest.TextTestRunner(verbosity=2).run(suite)
finally:
unit_tbox.clear_toolbox()
tuf.repo.keystore.clear_keystore()
if __name__ == '__main__':
unittest.main()

View file

@ -408,7 +408,7 @@ def test_2__import_delegations(self):
# Verify that there was no change in roledb and keydb dictionaries
# by checking the number of elements in the dictionaries.
self.assertEqual(len(roledb._roledb_dict), 5)
self.assertEqual(len(roledb._roledb_dict), 5)
self.assertEqual(len(keydb._keydb_dict), 5)
# Test: normal case, first level delegation.
@ -1149,21 +1149,5 @@ def test_8_remove_obsolete_targets(self):
tuf.download.download_url_to_tempfileobj = original_download
# Run all unit tests.
loader = unittest_toolbox.unittest.TestLoader()
suite = unittest_toolbox.unittest.TestSuite()
class1_tests = loader.loadTestsFromTestCase(TestUpdater_init_)
class2_tests = loader.loadTestsFromTestCase(TestUpdater)
suite.addTest(class1_tests)
suite.addTest(class2_tests)
try:
unittest_toolbox.unittest.TextTestRunner(verbosity=2).run(suite)
finally:
# Removing repositories.
setup.remove_all_repositories(TestUpdater.repositories['main_repository'])
unittest_toolbox.Modified_TestCase.clear_toolbox()
if __name__ == '__main__':
unittest.main()

View file

@ -302,5 +302,5 @@ def test_B6_load_json_file(self):
# Run unit test.
suite = unittest.TestLoader().loadTestsFromTestCase(TestUtil)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()