def test_no_position_file(self): with tempfile.TemporaryDirectory(prefix='test_grep_vcf') as tmpdir: pos_file_name = self.find_data('data.txt') pos_file_name = os.path.join(tmpdir, os.path.basename(pos_file_name)) data_file_name = self.find_data('data.vcf') data_file_name = shutil.copyfile(data_file_name, os.path.join(tmpdir, os.path.basename(data_file_name))) command = f"grep_vcf {pos_file_name}" with self.assertRaises(FileNotFoundError) as ctx: main(args=command.split()[1:]) self.assertEqual(str(ctx.exception), f"The file {pos_file_name} does not exists.")
def test_empty_positions(self): with tempfile.TemporaryDirectory(prefix='test_grep_vcf') as tmpdir: pos_file_name = self.find_data('empty.txt') pos_file_name = shutil.copyfile(pos_file_name, os.path.join(tmpdir, os.path.basename(pos_file_name))) data_file_name = self.find_data('data.vcf') data_file_name = shutil.copyfile(data_file_name, os.path.join(tmpdir, os.path.basename(data_file_name))) command = f"grep_vcf --vcf {data_file_name} {pos_file_name}" with self.catch_io(out=True): main(args=command.split()[1:]) stdout = sys.stdout.getvalue().strip() self.assertEqual(stdout, '')
def test_specify_out(self): with tempfile.TemporaryDirectory(prefix='test_grep_vcf') as tmpdir: pos_file_name = self.find_data('data.txt') pos_file_name = shutil.copyfile(pos_file_name, os.path.join(tmpdir, os.path.basename(pos_file_name))) data_file_name = self.find_data('data.vcf') data_file_name = shutil.copyfile(data_file_name, os.path.join(tmpdir, os.path.basename(data_file_name))) out_file_name = os.path.join(tmpdir, 'diff.vcf') command = f"grep_vcf --out {out_file_name} {pos_file_name}" main(args=command.split()[1:]) with open(out_file_name) as out: res = out.read() self.assertEqual(res, "7\tvcf ligne 1\n9\tvcf ligne 3\n11\tvcf ligne 4\n")