Getting ready for Python 3 compatibility (update print statements)

This commit is contained in:
Michael Mintz 2016-06-25 14:30:31 -04:00
parent a74c9ceeca
commit 10b937760a
8 changed files with 26 additions and 25 deletions

View File

@ -14,7 +14,7 @@ class MyTestSuite(BaseCase):
def test_2(self):
# This test should FAIL
print "\n(This test fails on purpose)"
print("\n(This test fails on purpose)")
self.open("http://xkcd.com/1675/")
raise Exception("FAKE EXCEPTION: This test fails on purpose.")
@ -26,6 +26,6 @@ class MyTestSuite(BaseCase):
def test_4(self):
# This test should FAIL
print "\n(This test fails on purpose)"
print("\n(This test fails on purpose)")
self.open("http://xkcd.com/1670/")
self.find_element("FakeElement.DoesNotExist", timeout=0.5)

View File

@ -6,9 +6,9 @@ class MyTestClass(BaseCase):
@decorators.rate_limited(3.5) # The arg is max calls per second
def print_item(self, item):
print item
print(item)
def test_rate_limited_printing(self):
print "\nRunning rate-limited print test:"
print("\nRunning rate-limited print test:")
for item in xrange(1, 11):
self.print_item(item)

View File

@ -212,16 +212,17 @@ def build_report(report_log_path, page_results_list,
results_file = add_results_page(report_html)
archived_results_file = report_log_path + '/' + HTML_REPORT
shutil.copyfile(results_file, archived_results_file)
print "\n* The latest html report page is located at:\n" + results_file
print "\n* Files saved for this report are located at:\n" + report_log_path
print ""
print("\n* The latest html report page is located at:\n" + results_file)
print(
"\n* Files saved for this report are located at:\n" + report_log_path)
print("")
if not hide_report:
if browser_type == 'chrome':
browser = webdriver.Chrome()
else:
browser = webdriver.Firefox()
browser.get("file://%s" % archived_results_file)
print "\n*** Close the html report window to continue. ***"
print("\n*** Close the html report window to continue. ***")
while len(browser.window_handles):
time.sleep(0.1)
browser.quit()

View File

@ -19,11 +19,11 @@ def download_selenium():
try:
local_file = open(JAR_FILE, 'wb')
remote_file = urllib.urlopen(SELENIUM_JAR)
print 'Downloading Selenium Server JAR File...\n'
print('Downloading Selenium Server JAR File...\n')
local_file.write(remote_file.read())
local_file.close()
remote_file.close()
print 'Download Complete!\n'
print('Download Complete!\n')
except Exception, details:
raise Exception("Error while downloading Selenium Server. Details: %s"
% details)
@ -91,4 +91,4 @@ def execute_selenium(host, port, file_path):
try:
return start_selenium_server(JAR_FILE, port, file_path)
except StartSeleniumException:
print "Selenium Server might already be running. Continuing... "
print("Selenium Server might already be running. Continuing... ")

View File

@ -974,7 +974,7 @@ class BaseCase(unittest.TestCase):
uploaded_files.append(logfile_name)
s3_bucket.save_uploaded_file_names(uploaded_files)
index_file = s3_bucket.upload_index_file(test_id, guid)
print "\n\n*** Log files uploaded: ***\n%s\n" % index_file
print("\n\n*** Log files uploaded: ***\n%s\n" % index_file)
logging.error(
"\n\n*** Log files uploaded: ***\n%s\n" % index_file)
if self.with_db_reporting:

View File

@ -132,8 +132,8 @@ class Base(Plugin):
def add_fails_or_errors(self, test):
if self.report_on:
if test.id() == 'nose.failure.Failure.runTest':
print ">>> ERROR: Could not locate tests to run!"
print ">>> The Test Report WILL NOT be generated!"
print(">>> ERROR: Could not locate tests to run!")
print(">>> The Test Report WILL NOT be generated!")
self.import_error = True
return
self.failures.append(test.id())
@ -154,9 +154,9 @@ class Base(Plugin):
if (err[0] == errors.BlockedTest or
err[0] == errors.SkipTest or
err[0] == errors.DeprecatedTest):
print err[1].__str__().split('''-------------------- >> '''
print(err[1].__str__().split('''-------------------- >> '''
'''begin captured logging'''
''' << --------------------''', 1)[0]
''' << --------------------''', 1)[0])
else:
self.__log_all_options_if_none_specified(test)
self.add_fails_or_errors(test)

View File

@ -36,7 +36,7 @@ class S3Logging(Plugin):
uploaded_files.append(logfile_name)
s3_bucket.save_uploaded_file_names(uploaded_files)
index_file = s3_bucket.upload_index_file(test.id(), guid)
print "\n\n*** Log files uploaded: ***\n%s\n" % index_file
print("\n\n*** Log files uploaded: ***\n%s\n" % index_file)
logging.error("\n\n*** Log files uploaded: ***\n%s\n" % index_file)
# If the database plugin is running, attach a link

View File

@ -121,8 +121,8 @@ class SeleniumBrowser(Plugin):
test.test.demo_mode = self.options.demo_mode
test.test.demo_sleep = self.options.demo_sleep
except Exception as err:
print "Error starting/connecting to Selenium:"
print err
print("Error starting/connecting to Selenium:")
print(err)
os.kill(os.getpid(), 9)
else:
connected = False
@ -139,21 +139,21 @@ class SeleniumBrowser(Plugin):
connected = True
break
except Exception as err:
print "Attempt #%s to connect to Selenium failed" % i
print("Attempt #%s to connect to Selenium failed" % i)
if i < 3:
print "Retrying in 3 seconds..."
print("Retrying in 3 seconds...")
time.sleep(3)
if not connected:
print "Error starting/connecting to Selenium:"
print err
print "\n\n"
print("Error starting/connecting to Selenium:")
print(err)
print("\n\n")
os.kill(os.getpid(), 9)
def afterTest(self, test):
try:
self.driver.quit()
except:
print "No driver to quit."
print("No driver to quit.")
if self.options.headless:
if self.headless_active:
self.display.stop()