[testing] a new TestCasePlus subclass + get_auto_remove_tmp_dir() (#6494)

* [testing] switch to a new TestCasePlus + get_auto_remove_tmp_dir() for auto-removal of tmp dirs

* respect after=True for tempfile, simplify code

* comments

* comment fix

* put `before` last in args, so can make debug even faster
This commit is contained in:
Stas Bekman
2020-08-17 05:12:19 -07:00
committed by GitHub
parent 36010cb1e2
commit 9dbe4094f2
3 changed files with 124 additions and 49 deletions

View File

@@ -1,11 +1,10 @@
import argparse
import logging
import shutil
import sys
import unittest
from unittest.mock import patch
import run_glue_with_pabee
from transformers.testing_utils import TestCasePlus
logging.basicConfig(level=logging.DEBUG)
@@ -20,20 +19,19 @@ def get_setup_file():
return args.f
def clean_test_dir(path):
shutil.rmtree(path, ignore_errors=True)
class PabeeTests(unittest.TestCase):
class PabeeTests(TestCasePlus):
def test_run_glue(self):
stream_handler = logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)
testargs = """
tmp_dir = self.get_auto_remove_tmp_dir()
testargs = f"""
run_glue_with_pabee.py
--model_type albert
--model_name_or_path albert-base-v2
--data_dir ./tests/fixtures/tests_samples/MRPC/
--output_dir {tmp_dir}
--overwrite_output_dir
--task_name mrpc
--do_train
--do_eval
@@ -42,16 +40,11 @@ class PabeeTests(unittest.TestCase):
--learning_rate=2e-5
--max_steps=50
--warmup_steps=2
--overwrite_output_dir
--seed=42
--max_seq_length=128
"""
output_dir = "./tests/fixtures/tests_samples/temp_dir_{}".format(hash(testargs))
testargs += "--output_dir " + output_dir
testargs = testargs.split()
""".split()
with patch.object(sys, "argv", testargs):
result = run_glue_with_pabee.main()
for value in result.values():
self.assertGreaterEqual(value, 0.75)
clean_test_dir(output_dir)