def test_functional_merge_one_results_empty(self): # res_1 has hits # res_2 has no hits and no systems res_1 = 'results_no_hits' src_res_1 = self.find_data('data_set', res_1) dest_res_1 = os.path.join(self.test_dir, res_1) res_2 = 'results_2' src_res_2 = self.find_data('data_set', res_2) dest_res_2 = os.path.join(self.test_dir, res_2) shutil.copytree(src_res_1, dest_res_1) shutil.copytree(src_res_2, dest_res_2) merge_dir = os.path.join(self.test_dir, 'merged_results') os.mkdir(merge_dir) cmd = f"macsymerge -o {merge_dir} --mute -qq {dest_res_1} {dest_res_2}" macsy_merge_results.main(args=cmd.split()[1:]) results_files = ('best_solution.tsv', 'best_solution_summary.tsv', 'best_solution_loners.tsv', 'best_solution_multisystems.tsv', 'all_best_solutions.tsv', 'all_systems.tsv', 'all_systems.txt', 'rejected_clusters.txt') for res in results_files: with self.subTest(res): expected = self.find_data('data_set', 'merged_results_one_res_no_hits', f"merged_{res}") recieved = os.path.join(merge_dir, f"merged_{res}") self.assertFileEqual(expected, recieved, comment='#')
def test_functional_merge_out_error(self): res_1 = 'results_1' src_res_1 = self.find_data('data_set', res_1) dest_res_1 = os.path.join(self.test_dir, res_1) res_2 = 'results_no_hits' src_res_2 = self.find_data('data_set', res_2) dest_res_2 = os.path.join(self.test_dir, res_2) merge_dir = os.path.join(self.test_dir, 'merged_results') ########################### # the -o option is a file ########################### open(merge_dir, 'w').close() cmd = f"macsy_merge_results -o {merge_dir} {dest_res_1} {dest_res_2}" with self.catch_io(out=True): # we cannot test the log message here # because the logger are init when main is called # after that the context is establish # so when the wrapper is called the handler cannot be substitute by the fake # but we can catch stdout with self.assertRaises(IOError): macsy_merge_results.main(args=cmd.split()[1:], log_level='WARNING') stdout = sys.stdout.getvalue().strip() self.assertEqual(self.remove_red_ansi_color(stdout), f'{merge_dir} is not a directory') os.unlink(merge_dir)
def test_functional_merge_out_not_writable(self): res_1 = 'results_1' src_res_1 = self.find_data('data_set', res_1) dest_res_1 = os.path.join(self.test_dir, res_1) res_2 = 'results_no_hits' src_res_2 = self.find_data('data_set', res_2) dest_res_2 = os.path.join(self.test_dir, res_2) merge_dir = os.path.join(self.test_dir, 'merged_results') ###################################### # the -o option is a dir NOT writable ##################################### os.mkdir(merge_dir, mode=0o444) cmd = f"macsy_merge_results -o {merge_dir} {dest_res_1} {dest_res_2}" try: with self.catch_io(out=True): with self.assertRaises(IOError): macsy_merge_results.main(args=cmd.split()[1:], log_level='WARNING') stdout = sys.stdout.getvalue().strip() self.assertEqual(self.remove_red_ansi_color(stdout), f'{merge_dir} is not writable') finally: shutil.rmtree(merge_dir) ###################################### # the -o option parent is NOT writable ###################################### os.chmod(self.test_dir, mode=0o444) with self.catch_io(out=True): with self.assertRaises(IOError): macsy_merge_results.main(args=cmd.split()[1:], log_level='WARNING') stdout = sys.stdout.getvalue().strip() self.assertEqual( self.remove_red_ansi_color(stdout), f"Cannot create {merge_dir} : [Errno 13] Permission denied: '{merge_dir}'" )