Doc styling (#8067)
* Important files * Styling them all * Revert "Styling them all" This reverts commit 7d029395fdae8513b8281cbc2a6c239f8093503e. * Syling them for realsies * Fix syntax error * Fix benchmark_utils * More fixes * Fix modeling auto and script * Remove new line * Fixes * More fixes * Fix more files * Style * Add FSMT * More fixes * More fixes * More fixes * More fixes * Fixes * More fixes * More fixes * Last fixes * Make sphinx happy
This commit is contained in:
@@ -88,8 +88,8 @@ def is_pipeline_test(test_case):
|
||||
"""
|
||||
Decorator marking a test as a pipeline test.
|
||||
|
||||
Pipeline tests are skipped by default and we can run only them by setting RUN_PIPELINE_TEST environment variable
|
||||
to a truthy value and selecting the is_pipeline_test pytest mark.
|
||||
Pipeline tests are skipped by default and we can run only them by setting RUN_PIPELINE_TEST environment variable to
|
||||
a truthy value and selecting the is_pipeline_test pytest mark.
|
||||
|
||||
"""
|
||||
if not _run_pipeline_tests:
|
||||
@@ -107,8 +107,7 @@ def slow(test_case):
|
||||
"""
|
||||
Decorator marking a test as slow.
|
||||
|
||||
Slow tests are skipped by default. Set the RUN_SLOW environment variable
|
||||
to a truthy value to run them.
|
||||
Slow tests are skipped by default. Set the RUN_SLOW environment variable to a truthy value to run them.
|
||||
|
||||
"""
|
||||
if not _run_slow_tests:
|
||||
@@ -121,9 +120,8 @@ def custom_tokenizers(test_case):
|
||||
"""
|
||||
Decorator marking a test for a custom tokenizer.
|
||||
|
||||
Custom tokenizers require additional dependencies, and are skipped
|
||||
by default. Set the RUN_CUSTOM_TOKENIZERS environment variable
|
||||
to a truthy value to run them.
|
||||
Custom tokenizers require additional dependencies, and are skipped by default. Set the RUN_CUSTOM_TOKENIZERS
|
||||
environment variable to a truthy value to run them.
|
||||
"""
|
||||
if not _run_custom_tokenizers:
|
||||
return unittest.skip("test of custom tokenizers")(test_case)
|
||||
@@ -201,8 +199,7 @@ def require_torch_multigpu(test_case):
|
||||
|
||||
These tests are skipped on a machine without multiple GPUs.
|
||||
|
||||
To run *only* the multigpu tests, assuming all test names contain multigpu:
|
||||
$ pytest -sv ./tests -k "multigpu"
|
||||
To run *only* the multigpu tests, assuming all test names contain multigpu: $ pytest -sv ./tests -k "multigpu"
|
||||
"""
|
||||
if not _torch_available:
|
||||
return unittest.skip("test requires PyTorch")(test_case)
|
||||
@@ -306,8 +303,8 @@ def get_tests_dir(append_path=None):
|
||||
append_path: optional path to append to the tests dir path
|
||||
|
||||
Return:
|
||||
The full path to the `tests` dir, so that the tests can be invoked from anywhere.
|
||||
Optionally `append_path` is joined after the `tests` dir the former is provided.
|
||||
The full path to the `tests` dir, so that the tests can be invoked from anywhere. Optionally `append_path` is
|
||||
joined after the `tests` dir the former is provided.
|
||||
|
||||
"""
|
||||
# this function caller's __file__
|
||||
@@ -344,30 +341,29 @@ def assert_screenout(out, what):
|
||||
|
||||
|
||||
class CaptureStd:
|
||||
"""Context manager to capture:
|
||||
stdout, clean it up and make it available via obj.out
|
||||
stderr, and make it available via obj.err
|
||||
"""
|
||||
Context manager to capture:
|
||||
stdout, clean it up and make it available via obj.out stderr, and make it available via obj.err
|
||||
|
||||
init arguments:
|
||||
- out - capture stdout: True/False, default True
|
||||
- err - capture stdout: True/False, default True
|
||||
init arguments: - out - capture stdout: True/False, default True - err - capture stdout: True/False, default
|
||||
True
|
||||
|
||||
Examples::
|
||||
Examples::
|
||||
|
||||
with CaptureStdout() as cs:
|
||||
print("Secret message")
|
||||
print(f"captured: {cs.out}")
|
||||
with CaptureStdout() as cs:
|
||||
print("Secret message")
|
||||
print(f"captured: {cs.out}")
|
||||
|
||||
import sys
|
||||
with CaptureStderr() as cs:
|
||||
print("Warning: ", file=sys.stderr)
|
||||
print(f"captured: {cs.err}")
|
||||
import sys
|
||||
with CaptureStderr() as cs:
|
||||
print("Warning: ", file=sys.stderr)
|
||||
print(f"captured: {cs.err}")
|
||||
|
||||
# to capture just one of the streams, but not the other
|
||||
with CaptureStd(err=False) as cs:
|
||||
print("Secret message")
|
||||
print(f"captured: {cs.out}")
|
||||
# but best use the stream-specific subclasses
|
||||
# to capture just one of the streams, but not the other
|
||||
with CaptureStd(err=False) as cs:
|
||||
print("Secret message")
|
||||
print(f"captured: {cs.out}")
|
||||
# but best use the stream-specific subclasses
|
||||
|
||||
"""
|
||||
|
||||
@@ -436,7 +432,8 @@ class CaptureStderr(CaptureStd):
|
||||
|
||||
|
||||
class CaptureLogger:
|
||||
"""Context manager to capture `logging` streams
|
||||
"""
|
||||
Context manager to capture `logging` streams
|
||||
|
||||
Args:
|
||||
- logger: 'logging` logger object
|
||||
@@ -476,13 +473,12 @@ class CaptureLogger:
|
||||
|
||||
|
||||
class TestCasePlus(unittest.TestCase):
|
||||
"""This class extends `unittest.TestCase` with additional features.
|
||||
"""
|
||||
This class extends `unittest.TestCase` with additional features.
|
||||
|
||||
Feature 1: Flexible auto-removable temp dirs which are guaranteed to get
|
||||
removed at the end of test.
|
||||
Feature 1: Flexible auto-removable temp dirs which are guaranteed to get removed at the end of test.
|
||||
|
||||
In all the following scenarios the temp dir will be auto-removed at the end
|
||||
of test, unless `after=False`.
|
||||
In all the following scenarios the temp dir will be auto-removed at the end of test, unless `after=False`.
|
||||
|
||||
# 1. create a unique temp dir, `tmp_dir` will contain the path to the created temp dir
|
||||
|
||||
@@ -491,38 +487,35 @@ class TestCasePlus(unittest.TestCase):
|
||||
def test_whatever(self):
|
||||
tmp_dir = self.get_auto_remove_tmp_dir()
|
||||
|
||||
# 2. create a temp dir of my choice and delete it at the end - useful for debug when you want to
|
||||
# monitor a specific directory
|
||||
# 2. create a temp dir of my choice and delete it at the end - useful for debug when you want to # monitor a
|
||||
specific directory
|
||||
|
||||
::
|
||||
|
||||
def test_whatever(self):
|
||||
tmp_dir = self.get_auto_remove_tmp_dir(tmp_dir="./tmp/run/test")
|
||||
|
||||
# 3. create a temp dir of my choice and do not delete it at the end - useful for when you want
|
||||
# to look at the temp results
|
||||
# 3. create a temp dir of my choice and do not delete it at the end - useful for when you want # to look at the
|
||||
temp results
|
||||
|
||||
::
|
||||
|
||||
def test_whatever(self):
|
||||
tmp_dir = self.get_auto_remove_tmp_dir(tmp_dir="./tmp/run/test", after=False)
|
||||
|
||||
# 4. create a temp dir of my choice and ensure to delete it right away - useful for when you
|
||||
# disabled deletion in the previous test run and want to make sure the that tmp dir is empty
|
||||
# before the new test is run
|
||||
# 4. create a temp dir of my choice and ensure to delete it right away - useful for when you # disabled deletion in
|
||||
the previous test run and want to make sure the that tmp dir is empty # before the new test is run
|
||||
|
||||
::
|
||||
|
||||
def test_whatever(self):
|
||||
tmp_dir = self.get_auto_remove_tmp_dir(tmp_dir="./tmp/run/test", before=True)
|
||||
|
||||
Note 1: In order to run the equivalent of `rm -r` safely, only subdirs of the
|
||||
project repository checkout are allowed if an explicit `tmp_dir` is used, so
|
||||
that by mistake no `/tmp` or similar important part of the filesystem will
|
||||
get nuked. i.e. please always pass paths that start with `./`
|
||||
Note 1: In order to run the equivalent of `rm -r` safely, only subdirs of the project repository checkout are
|
||||
allowed if an explicit `tmp_dir` is used, so that by mistake no `/tmp` or similar important part of the filesystem
|
||||
will get nuked. i.e. please always pass paths that start with `./`
|
||||
|
||||
Note 2: Each test can register multiple temp dirs and they all will get
|
||||
auto-removed, unless requested otherwise.
|
||||
Note 2: Each test can register multiple temp dirs and they all will get auto-removed, unless requested otherwise.
|
||||
|
||||
"""
|
||||
|
||||
@@ -540,8 +533,8 @@ class TestCasePlus(unittest.TestCase):
|
||||
delete the tmp dir at the end of the test
|
||||
|
||||
Returns:
|
||||
tmp_dir(:obj:`string`):
|
||||
either the same value as passed via `tmp_dir` or the path to the auto-created tmp dir
|
||||
tmp_dir(:obj:`string`): either the same value as passed via `tmp_dir` or the path to the auto-created tmp
|
||||
dir
|
||||
"""
|
||||
if tmp_dir is not None:
|
||||
# using provided path
|
||||
@@ -577,11 +570,10 @@ class TestCasePlus(unittest.TestCase):
|
||||
|
||||
|
||||
def mockenv(**kwargs):
|
||||
"""this is a convenience wrapper, that allows this:
|
||||
"""
|
||||
this is a convenience wrapper, that allows this:
|
||||
|
||||
@mockenv(RUN_SLOW=True, USE_TF=False)
|
||||
def test_something():
|
||||
run_slow = os.getenv("RUN_SLOW", False)
|
||||
use_tf = os.getenv("USE_TF", False)
|
||||
@mockenv(RUN_SLOW=True, USE_TF=False) def test_something(): run_slow = os.getenv("RUN_SLOW", False) use_tf =
|
||||
os.getenv("USE_TF", False)
|
||||
"""
|
||||
return unittest.mock.patch.dict(os.environ, kwargs)
|
||||
|
||||
Reference in New Issue
Block a user