Getting ready for Python 3 compatibility (update print statements)
This commit is contained in:
parent
a74c9ceeca
commit
10b937760a
|
@ -14,7 +14,7 @@ class MyTestSuite(BaseCase):
|
||||||
|
|
||||||
def test_2(self):
|
def test_2(self):
|
||||||
# This test should FAIL
|
# This test should FAIL
|
||||||
print "\n(This test fails on purpose)"
|
print("\n(This test fails on purpose)")
|
||||||
self.open("http://xkcd.com/1675/")
|
self.open("http://xkcd.com/1675/")
|
||||||
raise Exception("FAKE EXCEPTION: This test fails on purpose.")
|
raise Exception("FAKE EXCEPTION: This test fails on purpose.")
|
||||||
|
|
||||||
|
@ -26,6 +26,6 @@ class MyTestSuite(BaseCase):
|
||||||
|
|
||||||
def test_4(self):
|
def test_4(self):
|
||||||
# This test should FAIL
|
# 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.open("http://xkcd.com/1670/")
|
||||||
self.find_element("FakeElement.DoesNotExist", timeout=0.5)
|
self.find_element("FakeElement.DoesNotExist", timeout=0.5)
|
||||||
|
|
|
@ -6,9 +6,9 @@ class MyTestClass(BaseCase):
|
||||||
|
|
||||||
@decorators.rate_limited(3.5) # The arg is max calls per second
|
@decorators.rate_limited(3.5) # The arg is max calls per second
|
||||||
def print_item(self, item):
|
def print_item(self, item):
|
||||||
print item
|
print(item)
|
||||||
|
|
||||||
def test_rate_limited_printing(self):
|
def test_rate_limited_printing(self):
|
||||||
print "\nRunning rate-limited print test:"
|
print("\nRunning rate-limited print test:")
|
||||||
for item in xrange(1, 11):
|
for item in xrange(1, 11):
|
||||||
self.print_item(item)
|
self.print_item(item)
|
||||||
|
|
|
@ -212,16 +212,17 @@ def build_report(report_log_path, page_results_list,
|
||||||
results_file = add_results_page(report_html)
|
results_file = add_results_page(report_html)
|
||||||
archived_results_file = report_log_path + '/' + HTML_REPORT
|
archived_results_file = report_log_path + '/' + HTML_REPORT
|
||||||
shutil.copyfile(results_file, archived_results_file)
|
shutil.copyfile(results_file, archived_results_file)
|
||||||
print "\n* The latest html report page is located at:\n" + 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* Files saved for this report are located at:\n" + report_log_path)
|
||||||
|
print("")
|
||||||
if not hide_report:
|
if not hide_report:
|
||||||
if browser_type == 'chrome':
|
if browser_type == 'chrome':
|
||||||
browser = webdriver.Chrome()
|
browser = webdriver.Chrome()
|
||||||
else:
|
else:
|
||||||
browser = webdriver.Firefox()
|
browser = webdriver.Firefox()
|
||||||
browser.get("file://%s" % archived_results_file)
|
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):
|
while len(browser.window_handles):
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
browser.quit()
|
browser.quit()
|
||||||
|
|
|
@ -19,11 +19,11 @@ def download_selenium():
|
||||||
try:
|
try:
|
||||||
local_file = open(JAR_FILE, 'wb')
|
local_file = open(JAR_FILE, 'wb')
|
||||||
remote_file = urllib.urlopen(SELENIUM_JAR)
|
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.write(remote_file.read())
|
||||||
local_file.close()
|
local_file.close()
|
||||||
remote_file.close()
|
remote_file.close()
|
||||||
print 'Download Complete!\n'
|
print('Download Complete!\n')
|
||||||
except Exception, details:
|
except Exception, details:
|
||||||
raise Exception("Error while downloading Selenium Server. Details: %s"
|
raise Exception("Error while downloading Selenium Server. Details: %s"
|
||||||
% details)
|
% details)
|
||||||
|
@ -91,4 +91,4 @@ def execute_selenium(host, port, file_path):
|
||||||
try:
|
try:
|
||||||
return start_selenium_server(JAR_FILE, port, file_path)
|
return start_selenium_server(JAR_FILE, port, file_path)
|
||||||
except StartSeleniumException:
|
except StartSeleniumException:
|
||||||
print "Selenium Server might already be running. Continuing... "
|
print("Selenium Server might already be running. Continuing... ")
|
||||||
|
|
|
@ -974,7 +974,7 @@ class BaseCase(unittest.TestCase):
|
||||||
uploaded_files.append(logfile_name)
|
uploaded_files.append(logfile_name)
|
||||||
s3_bucket.save_uploaded_file_names(uploaded_files)
|
s3_bucket.save_uploaded_file_names(uploaded_files)
|
||||||
index_file = s3_bucket.upload_index_file(test_id, guid)
|
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(
|
logging.error(
|
||||||
"\n\n*** Log files uploaded: ***\n%s\n" % index_file)
|
"\n\n*** Log files uploaded: ***\n%s\n" % index_file)
|
||||||
if self.with_db_reporting:
|
if self.with_db_reporting:
|
||||||
|
|
|
@ -132,8 +132,8 @@ class Base(Plugin):
|
||||||
def add_fails_or_errors(self, test):
|
def add_fails_or_errors(self, test):
|
||||||
if self.report_on:
|
if self.report_on:
|
||||||
if test.id() == 'nose.failure.Failure.runTest':
|
if test.id() == 'nose.failure.Failure.runTest':
|
||||||
print ">>> ERROR: Could not locate tests to run!"
|
print(">>> ERROR: Could not locate tests to run!")
|
||||||
print ">>> The Test Report WILL NOT be generated!"
|
print(">>> The Test Report WILL NOT be generated!")
|
||||||
self.import_error = True
|
self.import_error = True
|
||||||
return
|
return
|
||||||
self.failures.append(test.id())
|
self.failures.append(test.id())
|
||||||
|
@ -154,9 +154,9 @@ class Base(Plugin):
|
||||||
if (err[0] == errors.BlockedTest or
|
if (err[0] == errors.BlockedTest or
|
||||||
err[0] == errors.SkipTest or
|
err[0] == errors.SkipTest or
|
||||||
err[0] == errors.DeprecatedTest):
|
err[0] == errors.DeprecatedTest):
|
||||||
print err[1].__str__().split('''-------------------- >> '''
|
print(err[1].__str__().split('''-------------------- >> '''
|
||||||
'''begin captured logging'''
|
'''begin captured logging'''
|
||||||
''' << --------------------''', 1)[0]
|
''' << --------------------''', 1)[0])
|
||||||
else:
|
else:
|
||||||
self.__log_all_options_if_none_specified(test)
|
self.__log_all_options_if_none_specified(test)
|
||||||
self.add_fails_or_errors(test)
|
self.add_fails_or_errors(test)
|
||||||
|
|
|
@ -36,7 +36,7 @@ class S3Logging(Plugin):
|
||||||
uploaded_files.append(logfile_name)
|
uploaded_files.append(logfile_name)
|
||||||
s3_bucket.save_uploaded_file_names(uploaded_files)
|
s3_bucket.save_uploaded_file_names(uploaded_files)
|
||||||
index_file = s3_bucket.upload_index_file(test.id(), guid)
|
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)
|
logging.error("\n\n*** Log files uploaded: ***\n%s\n" % index_file)
|
||||||
|
|
||||||
# If the database plugin is running, attach a link
|
# If the database plugin is running, attach a link
|
||||||
|
|
|
@ -121,8 +121,8 @@ class SeleniumBrowser(Plugin):
|
||||||
test.test.demo_mode = self.options.demo_mode
|
test.test.demo_mode = self.options.demo_mode
|
||||||
test.test.demo_sleep = self.options.demo_sleep
|
test.test.demo_sleep = self.options.demo_sleep
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print "Error starting/connecting to Selenium:"
|
print("Error starting/connecting to Selenium:")
|
||||||
print err
|
print(err)
|
||||||
os.kill(os.getpid(), 9)
|
os.kill(os.getpid(), 9)
|
||||||
else:
|
else:
|
||||||
connected = False
|
connected = False
|
||||||
|
@ -139,21 +139,21 @@ class SeleniumBrowser(Plugin):
|
||||||
connected = True
|
connected = True
|
||||||
break
|
break
|
||||||
except Exception as err:
|
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:
|
if i < 3:
|
||||||
print "Retrying in 3 seconds..."
|
print("Retrying in 3 seconds...")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
if not connected:
|
if not connected:
|
||||||
print "Error starting/connecting to Selenium:"
|
print("Error starting/connecting to Selenium:")
|
||||||
print err
|
print(err)
|
||||||
print "\n\n"
|
print("\n\n")
|
||||||
os.kill(os.getpid(), 9)
|
os.kill(os.getpid(), 9)
|
||||||
|
|
||||||
def afterTest(self, test):
|
def afterTest(self, test):
|
||||||
try:
|
try:
|
||||||
self.driver.quit()
|
self.driver.quit()
|
||||||
except:
|
except:
|
||||||
print "No driver to quit."
|
print("No driver to quit.")
|
||||||
if self.options.headless:
|
if self.options.headless:
|
||||||
if self.headless_active:
|
if self.headless_active:
|
||||||
self.display.stop()
|
self.display.stop()
|
||||||
|
|
Loading…
Reference in New Issue