# 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

class TestUtils(unittest.TestCase):
    def test_write_to_file(self):
        file = MagicMock()
        write_to_file(file, ["first line", "second line"])

        data = "".join([call[0][0] for call in file.write.call_args_list])
        self.assertEqual(data, dedent("""
            first line

# 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


class TestUtils(unittest.TestCase):
    def test_write_to_file(self):
        file = MagicMock()
        write_to_file(file, ["first line", "second line"])

        data = "".join([call[0][0] for call in file.write.call_args_list])
        self.assertEqual(data, dedent("""
            first line

            second line