# Path: swe_pipeline.py
# def parse(options, filename, annotated_sentences, tmp_dir):
#     tagged_conll_filename = output_filename(tmp_dir, filename, "tag.conll")
#     parsed_filename = output_filename(tmp_dir, filename, "conll")
#     log_filename = output_filename(tmp_dir, filename, "log")
# 
#     # The parser command line is dependent on the input and
#     # output files, so we build that one for each data file
#     parser_cmdline = [
#         "java",
#         "-Xmx2000m",
#         "-jar", os.path.expanduser(options.malt),
#         "-m", "parse",
#         "-i", tagged_conll_filename,
#         "-o", parsed_filename,
#         "-w", tmp_dir,
#         "-c", os.path.basename(options.parsing_model)
#     ]
# 
#     # Conversion from .tag file to tagged.conll (input format for the parser)
#     tagged_conll_file = open(tagged_conll_filename, "w", encoding="utf-8")
#     tagged_to_tagged_conll(annotated_sentences, tagged_conll_file)
#     tagged_conll_file.close()
# 
#     # Run the parser
#     with open(log_filename, "w", encoding="utf-8") as log_file:
#         returncode = Popen(
#             parser_cmdline, stdout=log_file, stderr=log_file
#         ).wait()
# 
#     if returncode:
#         sys.exit("Parsing failed! See log file: %s" % log_filename)
# 
#     return parsed_filename


from swe_pipeline import parse
from unittest.mock import patch, MagicMock, mock_open
import unittest
            ["IN", "PS|NEU|SIN|DEF", "NN|NEU|SIN|IND|NOM", "VB|PRS|AKT"],
        )]

        open_mock = mock_open()
        with patch("swe_pipeline.open", open_mock, create=True):
            self.assertEqual(
                parse(options, "file.txt", data, "/tmp"),
                "/tmp/file.conll"
            )
            arguments = popen_mock.call_args_list[1][0][0]
            self.assertEqual(
                " ".join(arguments),
                (
                    "java -Xmx2000m -jar /dummy/maltparser.jar "
                    "-m parse -i /tmp/file.tag.conll -o /tmp/file.conll "
                    "-w /tmp -c maltmodel.mco"
                )
            )

    @patch("swe_pipeline.tagged_to_tagged_conll")
    @patch("swe_pipeline.Popen")
    def test_parser_error(self, popen_mock, *args):
        options = self._default_options()

        popen_mock().wait.return_value = 1
        data = []

        open_mock = mock_open()
        with patch("swe_pipeline.open", open_mock, create=True):
            with self.assertRaises(SystemExit):

# Path: swe_pipeline.py
# def parse(options, filename, annotated_sentences, tmp_dir):
#     tagged_conll_filename = output_filename(tmp_dir, filename, "tag.conll")
#     parsed_filename = output_filename(tmp_dir, filename, "conll")
#     log_filename = output_filename(tmp_dir, filename, "log")
# 
#     # The parser command line is dependent on the input and
#     # output files, so we build that one for each data file
#     parser_cmdline = [
#         "java",
#         "-Xmx2000m",
#         "-jar", os.path.expanduser(options.malt),
#         "-m", "parse",
#         "-i", tagged_conll_filename,
#         "-o", parsed_filename,
#         "-w", tmp_dir,
#         "-c", os.path.basename(options.parsing_model)
#     ]
# 
#     # Conversion from .tag file to tagged.conll (input format for the parser)
#     tagged_conll_file = open(tagged_conll_filename, "w", encoding="utf-8")
#     tagged_to_tagged_conll(annotated_sentences, tagged_conll_file)
#     tagged_conll_file.close()
# 
#     # Run the parser
#     with open(log_filename, "w", encoding="utf-8") as log_file:
#         returncode = Popen(
#             parser_cmdline, stdout=log_file, stderr=log_file
#         ).wait()
# 
#     if returncode:
#         sys.exit("Parsing failed! See log file: %s" % log_filename)
# 
#     return parsed_filename


# Path: tests/test_pipeline_parse.py
from swe_pipeline import parse
from unittest.mock import patch, MagicMock, mock_open
import unittest

            ["IN", "PS|NEU|SIN|DEF", "NN|NEU|SIN|IND|NOM", "VB|PRS|AKT"],
        )]

        open_mock = mock_open()
        with patch("swe_pipeline.open", open_mock, create=True):
            self.assertEqual(
                parse(options, "file.txt", data, "/tmp"),
                "/tmp/file.conll"
            )
            arguments = popen_mock.call_args_list[1][0][0]
            self.assertEqual(
                " ".join(arguments),
                (
                    "java -Xmx2000m -jar /dummy/maltparser.jar "
                    "-m parse -i /tmp/file.tag.conll -o /tmp/file.conll "
                    "-w /tmp -c maltmodel.mco"
                )
            )

    @patch("swe_pipeline.tagged_to_tagged_conll")
    @patch("swe_pipeline.Popen")
    def test_parser_error(self, popen_mock, *args):
        options = self._default_options()

        popen_mock().wait.return_value = 1
        data = []

        open_mock = mock_open()
        with patch("swe_pipeline.open", open_mock, create=True):
            with self.assertRaises(SystemExit):

                parse(options, "file.txt", data, "/tmp")