def test_vap_sample_parseheatmaperror(testdir, mock_testclass): sample = 'POLR2A' parameters = Path(__file__).parent.joinpath('parameters.txt') selection = Path(__file__).parent.joinpath('genes.txt') splits = ['POLR2A-100-110', 'POLR2A-120-130'] genes = [ 'YDR524W-C', 'YLR355C', 'YLR110C', 'YGR192C', 'YGL008C', 'YKL060C' ] beds = [split + '-cov.bed' for split in splits] output = sample + '-vap-output' sample_parameters = output + '/parameters.txt' Split.splits = MagicMock(return_value=splits) v.parse_genes = MagicMock(return_value=genes) v.create_parameters = MagicMock() subprocess.run = MagicMock() v.parse_heatmap_values = MagicMock(side_effect=AssertionError) v.create_heatmap = MagicMock() with pytest.raises(AssertionError): v.vap_sample(sample, parameters, selection)
def test_vap_sample(testdir, mock_testclass): sample = 'POLR2A' parameters = Path(__file__).parent.joinpath('parameters.txt') selection = Path(__file__).parent.joinpath('genes.txt') splits = ['POLR2A-100-110', 'POLR2A-120-130'] genes = [ 'YDR524W-C', 'YLR355C', 'YLR110C', 'YGR192C', 'YGL008C', 'YKL060C' ] beds = [split + '-cov.bed' for split in splits] output = sample + '-vap-output' sample_parameters = output + '/parameters.txt' splits_values = {} for split in splits: splits_values[split] = {} for gene in genes: splits_values[split][gene] = str(random.random()) merged_heatmap = sample + '-heatmap.txt' Split.splits = MagicMock(return_value=splits) v.parse_genes = MagicMock(return_value=genes) v.create_parameters = MagicMock() subprocess.run = MagicMock() v.parse_heatmap_values = MagicMock(return_value=splits_values) v.create_heatmap = MagicMock() shutil.rmtree = MagicMock() v.vap_sample(sample, parameters, selection) Split.splits.assert_called_once_with(sample) v.parse_genes.assert_called_once_with(parameters, selection) v.create_parameters.assert_called_once_with(beds, output, selection, parameters, sample_parameters) cmd = ['vap'] if os.name == 'nt': cmd = ['vap.exe'] cmd.extend(['-p', sample_parameters]) subprocess.run.assert_called_once_with(cmd, check=True) v.parse_heatmap_values.assert_called_once_with(splits, output) v.create_heatmap.assert_called_once_with(sample, genes, splits, splits_values, merged_heatmap) shutil.rmtree.assert_called_once_with(output)