diff --git a/examples/summarization/bart/test_bart_examples.py b/examples/summarization/bart/test_bart_examples.py index faa0725b55..18064cc5d2 100644 --- a/examples/summarization/bart/test_bart_examples.py +++ b/examples/summarization/bart/test_bart_examples.py @@ -1,4 +1,5 @@ import logging +import os import sys import tempfile import unittest @@ -8,6 +9,8 @@ from unittest.mock import patch from .evaluate_cnn import _run_generate +output_file_name = "output_bart_sum.txt" + articles = [" New York (CNN)When Liana Barrientos was 23 years old, she got married in Westchester County."] logging.basicConfig(level=logging.DEBUG) @@ -19,10 +22,11 @@ class TestBartExamples(unittest.TestCase): def test_bart_cnn_cli(self): stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) - tmp = Path(tempfile.gettempdir()) / "utest_generations.hypo" + tmp = Path(tempfile.gettempdir()) / "utest_generations_bart_sum.hypo" with tmp.open("w") as f: f.write("\n".join(articles)) - testargs = ["evaluate_cnn.py", str(tmp), "output.txt"] + testargs = ["evaluate_cnn.py", str(tmp), output_file_name] with patch.object(sys, "argv", testargs): _run_generate() - self.assertTrue(Path("output.txt").exists()) + self.assertTrue(Path(output_file_name).exists()) + os.remove(Path(output_file_name)) diff --git a/examples/summarization/t5/test_t5_examples.py b/examples/summarization/t5/test_t5_examples.py index 58b5db681e..57f3e342d7 100644 --- a/examples/summarization/t5/test_t5_examples.py +++ b/examples/summarization/t5/test_t5_examples.py @@ -1,4 +1,5 @@ import logging +import os import sys import tempfile import unittest @@ -8,6 +9,9 @@ from unittest.mock import patch from .evaluate_cnn import run_generate +output_file_name = "output_t5_sum.txt" +score_file_name = "score_t5_sum.txt" + articles = ["New York (CNN)When Liana Barrientos was 23 years old, she got married in Westchester County."] logging.basicConfig(level=logging.DEBUG) @@ -19,11 +23,13 @@ class TestT5Examples(unittest.TestCase): def test_t5_cli(self): stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) - tmp = Path(tempfile.gettempdir()) / "utest_generations.hypo" + tmp = Path(tempfile.gettempdir()) / "utest_generations_t5_sum.hypo" with tmp.open("w") as f: f.write("\n".join(articles)) - testargs = ["evaluate_cnn.py", "t5-small", str(tmp), "output.txt", str(tmp), "score.txt"] + testargs = ["evaluate_cnn.py", "t5-small", str(tmp), output_file_name, str(tmp), score_file_name] with patch.object(sys, "argv", testargs): run_generate() - self.assertTrue(Path("output.txt").exists()) - self.assertTrue(Path("score.txt").exists()) + self.assertTrue(Path(output_file_name).exists()) + self.assertTrue(Path(score_file_name).exists()) + os.remove(Path(output_file_name)) + os.remove(Path(score_file_name)) diff --git a/examples/translation/t5/test_t5_examples.py b/examples/translation/t5/test_t5_examples.py index c7d1fe6882..eea17c227a 100644 --- a/examples/translation/t5/test_t5_examples.py +++ b/examples/translation/t5/test_t5_examples.py @@ -1,4 +1,5 @@ import logging +import os import sys import tempfile import unittest @@ -8,7 +9,11 @@ from unittest.mock import patch from .evaluate_wmt import run_generate -text = [" New York (CNN)When Liana Barrientos was 23 years old, she got married in Westchester County."] +text = ["When Liana Barrientos was 23 years old, she got married in Westchester County."] +translation = ["Als Liana Barrientos 23 Jahre alt war, heiratete sie in Westchester County."] + +output_file_name = "output_t5_trans.txt" +score_file_name = "score_t5_trans.txt" logging.basicConfig(level=logging.DEBUG) @@ -19,10 +24,20 @@ class TestT5Examples(unittest.TestCase): def test_t5_cli(self): stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) - tmp = Path(tempfile.gettempdir()) / "utest_generations.hypo" - with tmp.open("w") as f: + + tmp_source = Path(tempfile.gettempdir()) / "utest_generations_t5_trans.hypo" + with tmp_source.open("w") as f: f.write("\n".join(text)) - testargs = ["evaluate_cnn.py", str(tmp), "output.txt", str(tmp), "score.txt"] + + tmp_target = Path(tempfile.gettempdir()) / "utest_generations_t5_trans.target" + with tmp_target.open("w") as f: + f.write("\n".join(translation)) + + testargs = ["evaluate_wmt.py", str(tmp_source), output_file_name, str(tmp_target), score_file_name] + with patch.object(sys, "argv", testargs): run_generate() - self.assertTrue(Path("output.txt").exists()) + self.assertTrue(Path(output_file_name).exists()) + self.assertTrue(Path(score_file_name).exists()) + os.remove(Path(output_file_name)) + os.remove(Path(score_file_name))