# Path: swe_pipeline.py
# def write_to_file(file, lines):
#     for line in lines:
#         print(line, file=file)
#     print(file=file)
# 
# def write_to_output(filename_mapping):
#     for should_copy, filename, output_dir in filename_mapping:
#         if should_copy:
#             shutil.copy(filename, output_dir)
# 
# def cleanup(options, tmp_dir):
#     if not options.no_delete:
#         shutil.rmtree(tmp_dir)
#     else:
#         print("Leaving working directory as is: %s" % tmp_dir, file=sys.stderr)
# 
# def output_filename(tmp_dir, filename, suffix):
#     directory, _ = os.path.splitext(filename)
#     basename = os.path.basename(directory)
#     return os.path.join(tmp_dir, "%s.%s" % (basename, suffix))


import os
import sys
import unittest
from swe_pipeline import write_to_file, write_to_output, cleanup, output_filename
from textwrap import dedent
from unittest.mock import call, patch, MagicMock, mock_open

        """).lstrip())

    @patch("swe_pipeline.shutil")
    def test_write_to_output(self, shutil_mock):
        write_to_output([
            (True, "file1", "/tmp1"),
            (False, "file2", "/tmp2"),
            (True, "file3", "/tmp3"),
        ])
        self.assertEqual(
            shutil_mock.copy.call_args_list,
            [call('file1', '/tmp1'), call('file3', '/tmp3')]
        )

    @patch("swe_pipeline.shutil")
    def test_cleanup_delete(self, shutil_mock):
        options = MagicMock()
        options.no_delete = False
        cleanup(options, "/tmp")
        self.assertEqual(
            shutil_mock.rmtree.call_args_list,
            [call('/tmp')]
        )

    @patch("swe_pipeline.shutil")
    def test_cleanup_without_delete(self, shutil_mock):
        options = MagicMock()
        options.no_delete = True
        with open(os.devnull, 'w') as sys.stderr:

# Path: swe_pipeline.py
# def write_to_file(file, lines):
#     for line in lines:
#         print(line, file=file)
#     print(file=file)
# 
# def write_to_output(filename_mapping):
#     for should_copy, filename, output_dir in filename_mapping:
#         if should_copy:
#             shutil.copy(filename, output_dir)
# 
# def cleanup(options, tmp_dir):
#     if not options.no_delete:
#         shutil.rmtree(tmp_dir)
#     else:
#         print("Leaving working directory as is: %s" % tmp_dir, file=sys.stderr)
# 
# def output_filename(tmp_dir, filename, suffix):
#     directory, _ = os.path.splitext(filename)
#     basename = os.path.basename(directory)
#     return os.path.join(tmp_dir, "%s.%s" % (basename, suffix))


# Path: tests/test_pipeline_utils.py
import os
import sys
import unittest
from swe_pipeline import write_to_file, write_to_output, cleanup, output_filename
from textwrap import dedent
from unittest.mock import call, patch, MagicMock, mock_open


        """).lstrip())

    @patch("swe_pipeline.shutil")
    def test_write_to_output(self, shutil_mock):
        write_to_output([
            (True, "file1", "/tmp1"),
            (False, "file2", "/tmp2"),
            (True, "file3", "/tmp3"),
        ])
        self.assertEqual(
            shutil_mock.copy.call_args_list,
            [call('file1', '/tmp1'), call('file3', '/tmp3')]
        )

    @patch("swe_pipeline.shutil")
    def test_cleanup_delete(self, shutil_mock):
        options = MagicMock()
        options.no_delete = False
        cleanup(options, "/tmp")
        self.assertEqual(
            shutil_mock.rmtree.call_args_list,
            [call('/tmp')]
        )

    @patch("swe_pipeline.shutil")
    def test_cleanup_without_delete(self, shutil_mock):
        options = MagicMock()
        options.no_delete = True
        with open(os.devnull, 'w') as sys.stderr:

            cleanup(options, "/tmp")