def test_no_error_alive_after(self): # No Error | Alive After - Excel in proc @ end with safexl.application(kill_after=False, maximize=False, include_addins=False) as app: wb = app.Workbooks.Add() ws = wb.ActiveSheet ws.Range("A1").Value = 555 self.assertTrue(safexl.is_excel_open()) self.assertEqual(wb.Name, "Book1") self.assertEqual(ws.Name, "Sheet1") self.assertEqual(ws.Range("A1").Value, 555) self.assertTrue(safexl.is_excel_open())
def test_error_alive_after(self): # Error | Alive After - Excel not in proc @ end with self.assertRaises(safexl.toolkit.ExcelError): with safexl.application(kill_after=False, maximize=False, include_addins=False) as app: wb = app.Workbooks.Add() ws = wb.ActiveSheet self.assertTrue(safexl.is_excel_open()) # Error on this line ws.Name = "a*b*c" # None of the following characters are allowed in sheet names # ["\\", "/", "*", "[", "]", ":", "?"] self.assertFalse(safexl.is_excel_open())
def setUp(self): with safexl.application(kill_after=False, maximize=False, include_addins=False) as prev_app: wb = prev_app.Workbooks.Add() self.assertEqual("Book1", wb.Name) self.assertTrue(safexl.is_excel_open())
def test_when_excel_is_open(self): pythoncom.CoInitialize() application = win32com.client.Dispatch("Excel.Application") self.assertTrue(safexl.is_excel_open()) safexl.kill_all_instances_of_excel(application) del application pythoncom.CoUninitialize()
def test_no_error_kill_after(self): # No Error | Kill After - prev Excel open after, new Excel gone current_openfile_count = len(safexl.toolkit.excel_open_files()) with safexl.application(kill_after=True, maximize=False, include_addins=False) as app: wb = app.Workbooks.Add() ws = wb.ActiveSheet ws.Range("A1").Value = 555 self.assertTrue(safexl.is_excel_open()) self.assertEqual(len(safexl.toolkit.excel_open_files()), current_openfile_count + 1) self.assertEqual(wb.Name, "Book2") self.assertEqual(ws.Name, "Sheet1") self.assertEqual(ws.Range("A1").Value, 555) self.assertEqual(len(safexl.toolkit.excel_open_files()), current_openfile_count) self.assertTrue(safexl.is_excel_open())
def test_error_alive_after(self): # Error | Alive After - prev Excel open after, new Excel gone with self.assertRaises(safexl.toolkit.ExcelError): current_openfile_count = len(safexl.toolkit.excel_open_files()) with safexl.application(kill_after=False, maximize=False, include_addins=False) as app: wb = app.Workbooks.Add() ws = wb.ActiveSheet self.assertTrue(safexl.is_excel_open()) self.assertEqual(len(safexl.toolkit.excel_open_files()), current_openfile_count + 1) # Error on this line ws.Name = "a*b*c" # None of the following characters are allowed in sheet names # ["\\", "/", "*", "[", "]", ":", "?"] self.assertEqual(len(safexl.toolkit.excel_open_files()), current_openfile_count) self.assertTrue(safexl.is_excel_open())
def test_that_results_update_immediately(self): safexl.kill_all_instances_of_excel() self.assertFalse(safexl.is_excel_open()) pythoncom.CoInitialize() application = win32com.client.Dispatch("Excel.Application") # no workbooks have been added yet open_files_1 = self.count_tempfiles() self.assertEqual(0, open_files_1) # 1 workbook added, 1 more .tmp file than before wb1 = application.Workbooks.Add() open_files_2 = self.count_tempfiles() self.assertEqual(1, open_files_2) self.assertEqual(open_files_1 + 1, open_files_2) # 2 workbooks added, 1 more .tmp file than before wb2 = application.Workbooks.Add() open_files_3 = self.count_tempfiles() self.assertEqual(2, open_files_3) self.assertEqual(open_files_2 + 1, open_files_3) # 1 workbook removed, 1 less .tmp file than before application.DisplayAlerts = False wb2.Close(SaveChanges=False) application.DisplayAlerts = True open_files_4 = self.count_tempfiles() self.assertEqual(1, open_files_4) self.assertEqual(open_files_3 - 1, open_files_4) # 2 workbooks removed, 1 less .tmp file than before, back to beginning application.DisplayAlerts = False wb1.Close(SaveChanges=False) application.DisplayAlerts = True open_files_5 = self.count_tempfiles() self.assertEqual(0, open_files_5) self.assertEqual(open_files_4 - 1, open_files_5) self.assertEqual(open_files_5, open_files_1) safexl.kill_all_instances_of_excel(application) del application pythoncom.CoUninitialize()
def tearDown(self): # want to be sure that we end each app test with a clean slate safexl.kill_all_instances_of_excel() self.assertFalse(safexl.is_excel_open())
def setUp(self): safexl.kill_all_instances_of_excel() self.assertFalse(safexl.is_excel_open())
def test_when_excel_is_not_open(self): safexl.kill_all_instances_of_excel() self.assertFalse(safexl.is_excel_open())