Doc fixes in preparation for the docstyle PR (#8061)
* Fixes in preparation for doc styling * More fixes * Better syntax * Fixes * Style * More fixes * More fixes
This commit is contained in:
@@ -352,22 +352,22 @@ class CaptureStd:
|
||||
- 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
|
||||
|
||||
"""
|
||||
|
||||
@@ -444,17 +444,17 @@ class CaptureLogger:
|
||||
Results:
|
||||
The captured output is available via `self.out`
|
||||
|
||||
Example:
|
||||
Example::
|
||||
|
||||
>>> from transformers import logging
|
||||
>>> from transformers.testing_utils import CaptureLogger
|
||||
>>> from transformers import logging
|
||||
>>> from transformers.testing_utils import CaptureLogger
|
||||
|
||||
>>> msg = "Testing 1, 2, 3"
|
||||
>>> logging.set_verbosity_info()
|
||||
>>> logger = logging.get_logger("transformers.tokenization_bart")
|
||||
>>> with CaptureLogger(logger) as cl:
|
||||
... logger.info(msg)
|
||||
>>> assert cl.out, msg+"\n"
|
||||
>>> msg = "Testing 1, 2, 3"
|
||||
>>> logging.set_verbosity_info()
|
||||
>>> logger = logging.get_logger("transformers.tokenization_bart")
|
||||
>>> with CaptureLogger(logger) as cl:
|
||||
... logger.info(msg)
|
||||
>>> assert cl.out, msg+"\n"
|
||||
"""
|
||||
|
||||
def __init__(self, logger):
|
||||
@@ -485,24 +485,36 @@ class TestCasePlus(unittest.TestCase):
|
||||
of test, unless `after=False`.
|
||||
|
||||
# 1. create a unique temp dir, `tmp_dir` will contain the path to the created temp dir
|
||||
def test_whatever(self):
|
||||
tmp_dir = self.get_auto_remove_tmp_dir()
|
||||
|
||||
::
|
||||
|
||||
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
|
||||
def test_whatever(self):
|
||||
tmp_dir = self.get_auto_remove_tmp_dir(tmp_dir="./tmp/run/test")
|
||||
|
||||
::
|
||||
|
||||
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
|
||||
def test_whatever(self):
|
||||
tmp_dir = self.get_auto_remove_tmp_dir(tmp_dir="./tmp/run/test", after=False)
|
||||
|
||||
::
|
||||
|
||||
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
|
||||
def test_whatever(self):
|
||||
tmp_dir = self.get_auto_remove_tmp_dir(tmp_dir="./tmp/run/test", before=True)
|
||||
|
||||
::
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user