class ItolTest(unittest.TestCase): def setUp(self): self.itol = Itol() def test_initializes(self): self.assertEqual(type(self.itol.params), dict) self.assertEqual(self.itol.files, []) self.assertIsNotNone(self.itol.comm) def test_add_file(self): with tempfile.NamedTemporaryFile() as temp: self.itol.add_file(temp.name) with self.assertRaises(IOError): self.itol.add_file(' ') def test_good_upload(self): with patch('itolapi.Comm.upload_tree') as mock_upload: mock_upload.return_value = True self.itol.comm.tree_id = 1234 self.assertEqual(self.itol.upload(), 1234) def test_bad_upload(self): with patch('itolapi.Comm.upload_tree') as mock_upload: mock_upload.return_value = False self.itol.comm.tree_id = 1234 self.assertEqual(self.itol.upload(), 0) def test_get_webpage(self): self.itol.comm.tree_id = 'asdf' webpage = self.itol.get_webpage() self.assertIn('itol.embl.de', webpage) self.assertIn('asdf', webpage) def test_get_itol_export(self): self.itol.comm.tree_id = 1234 export = self.itol.get_itol_export() self.assertEqual(export.params['tree'], 1234) @patch('itolapi.itol.pprint.pprint') def test_print_variables(self, mock_print): self.itol.params['treeName'] = 'test' with tempfile.NamedTemporaryFile() as temp: self.itol.add_file(temp.name) self.itol.print_variables() self.assertEqual(mock_print.call_args_list[0][0][0], self.itol.files) self.assertEqual(mock_print.call_args_list[1][0][0], self.itol.params)
print('') print('Creating the upload params') # Create the Itol class test = Itol() # Set the tree file tree = os.path.join(current_dir, 'tree_of_life.tree.txt') test.add_file(tree) test.add_file(os.path.join(current_dir, 'colors_tol.txt')) test.add_file(os.path.join(current_dir, 'labels.txt')) test.add_file(os.path.join(current_dir, 'ranges.txt')) # Add parameters test.params['treeName'] = 'Tree of Life Example' # Check parameters test.print_variables() # Submit the tree print('') print(( 'Uploading the tree. This may take some time depending on how large the ' 'tree is and how much load there is on the itol server' )) good_upload = test.upload() if not good_upload: print('There was an error:' + test.comm.upload_output) sys.exit(1) # Read the tree ID print('Tree ID: ' + str(test.comm.tree_id)) # Read the iTOL API return statement
print('') print('Creating the upload params') # Create the Itol class test = Itol() # Set the tree file tree = os.path.join(current_dir, args.tree) test.add_file(tree) test.add_file(os.path.join(current_dir, args.colour)) #test.add_file(os.path.join(current_dir, 'labels.txt')) #test.add_file(os.path.join(current_dir, 'ranges.txt')) # Add parameters test.params['treeName'] = 'Tree File' # Check parameters test.print_variables() # Submit the tree print('') print( ('Uploading the tree. This may take some time depending on how large the ' 'tree is and how much load there is on the itol server')) good_upload = test.upload() if not good_upload: print('There was an error:' + test.comm.upload_output) sys.exit(1) # Read the tree ID print('Tree ID: ' + str(test.comm.tree_id)) # Read the iTOL API return statement print('iTOL output: ' + str(test.comm.upload_output))
root_path = os.path.join(current_dir, '..') sys.path.append(root_path) boom = Itol() # Set the tree file tree = os.path.join(current_dir, 'MERS_CoV.tree.txt') boom.add_file(tree) # Add parameters boom.params['treeName'] = 'MERS_CoV' boom.params['display_mode'] = '2' boom.params['ignore_branch_length'] = '1' boom.params['current_font_size'] = '28' # Check parameters boom.print_variables() # Submit the tree print('') print( ('Uploading the tree. This may take some time depending on how large the ' 'tree is and how much load there is on the itol server')) good_upload = boom.upload() if not good_upload: print('There was an error:' + boom.comm.upload_output) sys.exit(1) # Read the tree ID print('Tree ID: ' + str(boom.comm.tree_id)) # Read the iTOL API return statement