Unverified Commit 17dceae7 authored by Patrick von Platen's avatar Patrick von Platen Committed by GitHub
Browse files

Fix circle ci flaky fail of wmt example (#3485)

* force bleu

* fix wrong file name

* rename file

* different filenames for each example test

* test files should clean up after themselves

* test files should clean up after themselves

* do not force bleu

* correct typo

* fix isort
parent 00ea100e
import logging import logging
import os
import sys import sys
import tempfile import tempfile
import unittest import unittest
...@@ -8,6 +9,8 @@ from unittest.mock import patch ...@@ -8,6 +9,8 @@ from unittest.mock import patch
from .evaluate_cnn import _run_generate 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."] articles = [" New York (CNN)When Liana Barrientos was 23 years old, she got married in Westchester County."]
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
...@@ -19,10 +22,11 @@ class TestBartExamples(unittest.TestCase): ...@@ -19,10 +22,11 @@ class TestBartExamples(unittest.TestCase):
def test_bart_cnn_cli(self): def test_bart_cnn_cli(self):
stream_handler = logging.StreamHandler(sys.stdout) stream_handler = logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler) 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: with tmp.open("w") as f:
f.write("\n".join(articles)) 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): with patch.object(sys, "argv", testargs):
_run_generate() _run_generate()
self.assertTrue(Path("output.txt").exists()) self.assertTrue(Path(output_file_name).exists())
os.remove(Path(output_file_name))
import logging import logging
import os
import sys import sys
import tempfile import tempfile
import unittest import unittest
...@@ -8,6 +9,9 @@ from unittest.mock import patch ...@@ -8,6 +9,9 @@ from unittest.mock import patch
from .evaluate_cnn import run_generate 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."] articles = ["New York (CNN)When Liana Barrientos was 23 years old, she got married in Westchester County."]
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
...@@ -19,11 +23,13 @@ class TestT5Examples(unittest.TestCase): ...@@ -19,11 +23,13 @@ class TestT5Examples(unittest.TestCase):
def test_t5_cli(self): def test_t5_cli(self):
stream_handler = logging.StreamHandler(sys.stdout) stream_handler = logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler) 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: with tmp.open("w") as f:
f.write("\n".join(articles)) 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): with patch.object(sys, "argv", testargs):
run_generate() run_generate()
self.assertTrue(Path("output.txt").exists()) self.assertTrue(Path(output_file_name).exists())
self.assertTrue(Path("score.txt").exists()) self.assertTrue(Path(score_file_name).exists())
os.remove(Path(output_file_name))
os.remove(Path(score_file_name))
import logging import logging
import os
import sys import sys
import tempfile import tempfile
import unittest import unittest
...@@ -8,7 +9,11 @@ from unittest.mock import patch ...@@ -8,7 +9,11 @@ from unittest.mock import patch
from .evaluate_wmt import run_generate 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) logging.basicConfig(level=logging.DEBUG)
...@@ -19,10 +24,20 @@ class TestT5Examples(unittest.TestCase): ...@@ -19,10 +24,20 @@ class TestT5Examples(unittest.TestCase):
def test_t5_cli(self): def test_t5_cli(self):
stream_handler = logging.StreamHandler(sys.stdout) stream_handler = logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler) 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)) 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): with patch.object(sys, "argv", testargs):
run_generate() 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))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment