def test_write_output_with_content(self): with tempfile.TemporaryDirectory() as temp_dir: files = { 'file_a': os.path.join(temp_dir, 'file_a.txt'), 'file_b': os.path.join(temp_dir, 'file_b.txt') } for name, path in files.items(): with open(path, 'w') as fh: fh.write(name) with mock.patch.object(Singularity, "dataflow") as patch_dataflow, \ mock.patch.object(Singularity, "warning") as patch_warning, \ mock.patch.object(Singularity, "get_output_file_list", lambda *args, **kwargs: files) as patch_output_file_list: s = Singularity(None, None) s.write_output() patch_dataflow.assert_called_once_with(files, 1)
def test_error_with_missing_file(self): with tempfile.TemporaryDirectory() as temp_dir: files = { 'file_a': os.path.join(temp_dir, 'file_a.txt'), 'file_b': os.path.join(temp_dir, 'file_b.txt') } with open(files['file_a'], 'w') as fh: fh.write('file_a') missing_file = files['file_b'] self.assertFalse(os.path.exists(missing_file)) with mock.patch.object(Singularity, "dataflow") as patch_dataflow, \ mock.patch.object(Singularity, "warning") as patch_warning, \ mock.patch.object(Singularity, "get_output_file_list", lambda *args, **kwargs: files) as patch_output_file_list: s = Singularity(None, None) with self.assertRaisesRegex( AssertionError, re.escape(f"Missing file: {missing_file}")): s.write_output()
def test_write_output_with_no_files(self): with mock.patch.object(Singularity, "dataflow") as patch_dataflow, \ mock.patch.object(Singularity, "warning") as patch_warning: s = Singularity(None, None) s.write_output() patch_dataflow.assert_called_once_with(dict(), 1)