def test_export_img_with_non_visio_file(self): try: tmpdir = mkdtemp() with self.assertRaises(IOError): export_img(__file__, os.path.join(tmpdir, 'output.png'), None, None) finally: rmtree(tmpdir)
def test_export_img_from_vsd(self): try: tmpdir = mkdtemp() export_img(os.path.join(EXAMPLE_DIR, 'multipages.vsd'), os.path.join(tmpdir, 'output.png'), None, None) self.assertEqual(['output1.png', 'output2.png'], os.listdir(tmpdir)) finally: rmtree(tmpdir)
def test_export_img_from_vsd(self): try: tmpdir = mkdtemp() export_img(os.path.join(EXAMPLE_DIR, 'multipages.vsd'), os.path.join(tmpdir, 'output.png'), None, None) self.assertEqual(['output1.png', 'output2.png'], os.listdir(tmpdir)) finally: rmtree(tmpdir)
def test_export_img_if_visio_not_found(self, win32com_client): from pywintypes import com_error win32com_client.Dispatch.side_effect = com_error try: tmpdir = mkdtemp() with self.assertRaises(OSError): export_img(os.path.join(EXAMPLE_DIR, 'singlepage.vsdx'), os.path.join(tmpdir, 'output.png'), None, None) finally: rmtree(tmpdir)
def test_export_img_multipages2(self): try: tmpdir = mkdtemp() export_img(os.path.join(EXAMPLE_DIR, 'multipages2.vsdx'), os.path.join(tmpdir, 'output.png'), None, None) expected = ['output01.png', 'output02.png', 'output03.png', 'output04.png', 'output05.png', 'output06.png', 'output07.png', 'output08.png', 'output09.png', 'output10.png'] self.assertEqual(expected, os.listdir(tmpdir)) finally: rmtree(tmpdir)
def test_export_img_singlepage_to_gif(self): try: tmpdir = mkdtemp() export_img(os.path.join(EXAMPLE_DIR, 'singlepage.vsdx'), os.path.join(tmpdir, 'output.gif'), None, None) self.assertEqual(['output.gif'], os.listdir(tmpdir)) expected = os.path.join(EXAMPLE_DIR, 'singlepage', 'output.gif') actual = os.path.join(tmpdir, 'output.gif') self.assertEqual(open(expected, 'rb').read(), open(actual, 'rb').read()) finally: rmtree(tmpdir)
def test_export_img_multipages2(self): try: tmpdir = mkdtemp() export_img(os.path.join(EXAMPLE_DIR, 'multipages2.vsdx'), os.path.join(tmpdir, 'output.png'), None, None) expected = [ 'output01.png', 'output02.png', 'output03.png', 'output04.png', 'output05.png', 'output06.png', 'output07.png', 'output08.png', 'output09.png', 'output10.png' ] self.assertEqual(expected, os.listdir(tmpdir)) finally: rmtree(tmpdir)
def test_export_img_singlepage_to_gif(self): try: tmpdir = mkdtemp() export_img(os.path.join(EXAMPLE_DIR, 'singlepage.vsdx'), os.path.join(tmpdir, 'output.gif'), None, None) self.assertEqual(['output.gif'], os.listdir(tmpdir)) expected = os.path.join(EXAMPLE_DIR, 'singlepage', 'output.gif') actual = os.path.join(tmpdir, 'output.gif') self.assertEqual( open(expected, 'rb').read(), open(actual, 'rb').read()) finally: rmtree(tmpdir)
def test_export_img_multipages_with_pagename(self): try: tmpdir = mkdtemp() export_img(os.path.join(EXAMPLE_DIR, 'multipages.vsdx'), os.path.join(tmpdir, 'output.png'), None, u"ページ - 2") self.assertEqual(['output.png'], os.listdir(tmpdir)) expected = os.path.join(EXAMPLE_DIR, 'multipages', 'output2.png') actual = os.path.join(tmpdir, 'output.png') self.assertEqual(open(expected, 'rb').read(), open(actual, 'rb').read()) finally: rmtree(tmpdir)
def test_export_img_multipages_with_pagename(self): try: tmpdir = mkdtemp() export_img(os.path.join(EXAMPLE_DIR, 'multipages.vsdx'), os.path.join(tmpdir, 'output.png'), None, u"ページ - 2") self.assertEqual(['output.png'], os.listdir(tmpdir)) expected = os.path.join(EXAMPLE_DIR, 'multipages', 'output2.png') actual = os.path.join(tmpdir, 'output.png') self.assertEqual( open(expected, 'rb').read(), open(actual, 'rb').read()) finally: rmtree(tmpdir)
def test_export_img_output_dir_not_found(self): with self.assertRaises(IOError): export_img(os.path.join(EXAMPLE_DIR, 'singlepage.vsdx'), '/path/to/output.png', None, None)
def test_export_img_visio_file_not_found(self): with self.assertRaises(IOError): export_img('/path/to/notexist.vsd', '/path/to/output.png', None, None)
def test_export_img_output_dir_not_found(self): with self.assertRaises(IOError): export_img(os.path.join(EXAMPLE_DIR, 'singlepage.vsdx'), '/path/to/output.png', None, None)
def test_export_img_visio_file_not_found(self): with self.assertRaises(IOError): export_img('/path/to/notexist.vsd', '/path/to/output.png', None, None)