aboutsummaryrefslogtreecommitdiff
path: root/docs/autopatch.rst
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2023-08-29 22:31:30 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-08-29 22:31:30 +0000
commitee132a3ba2a7295008913e19af9328d0954f240e (patch)
treef40c1a21c47e1a74164c5feb8a577145a2970aeb /docs/autopatch.rst
parentf9490653f18ce1f2997b79d6ef6d46f2b10ee44d (diff)
parentf1db2cd21ffd0089578fd72dd32e3df5f2f40f44 (diff)
downloadpyfakefs-master.tar.gz
Upgrade pyfakefs to 979a878b12a3f625abe986a2249b677e6193ae3d am: a3bcabf4b7 am: 78fdc2ac9e am: 1261801ef1 am: 9f1f3798d8 am: f1db2cd21fHEADandroid-14.0.0_r50mastermainandroid14-qpr3-release
Original change: https://android-review.googlesource.com/c/platform/external/python/pyfakefs/+/2726660 Change-Id: I5d286395144c422ac19f4b0c0a1b5279f14942b7 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'docs/autopatch.rst')
-rw-r--r--docs/autopatch.rst29
1 files changed, 17 insertions, 12 deletions
diff --git a/docs/autopatch.rst b/docs/autopatch.rst
index 66d6a22..c317964 100644
--- a/docs/autopatch.rst
+++ b/docs/autopatch.rst
@@ -11,6 +11,11 @@ The pyfakefs source code contains files that demonstrate this usage model:
- ``example_test.py`` tests ``example.py``. During testing, the pyfakefs fake
file system is used by ``example_test.py`` and ``example.py`` alike.
+.. note:: This example uses the Python ``unittest`` module for testing, but the
+ functionality is similar if using the ``fs`` fixture in ``pytest``,
+ the ``patchfs`` decorator, or the ``Patcher`` class.
+
+
Software Under Test
-------------------
``example.py`` contains a few functions that manipulate files. For instance:
@@ -18,7 +23,7 @@ Software Under Test
.. code:: python
def create_file(path):
- '''Create the specified file and add some content to it. Use the open()
+ """Create the specified file and add some content to it. Use the open()
built in function.
For example, the following file operations occur in the fake file system.
@@ -37,8 +42,8 @@ Software Under Test
>>> with open('/test/file.txt') as f:
... f.readlines()
["This is test file '/test/file.txt'.\\n", 'It was created using the open() function.\\n']
- '''
- with open(path, 'w') as f:
+ """
+ with open(path, "w") as f:
f.write("This is test file '{}'.\n".format(path))
f.write("It was created using the open() function.\n")
@@ -60,6 +65,7 @@ and modules:
import os
import unittest
from pyfakefs import fake_filesystem_unittest
+
# The module under test is example:
import example
@@ -71,7 +77,7 @@ Doctests
.. code:: python
def load_tests(loader, tests, ignore):
- '''Load the pyfakefs/example.py doctest tests into unittest.'''
+ """Load the pyfakefs/example.py doctest tests into unittest."""
return fake_filesystem_unittest.load_doctests(loader, tests, ignore, example)
@@ -89,7 +95,6 @@ Next comes the ``unittest`` test class. This class is derived from
.. code:: python
class TestExample(fake_filesystem_unittest.TestCase):
-
def setUp(self):
self.setUpPyfakefs()
@@ -98,16 +103,16 @@ Next comes the ``unittest`` test class. This class is derived from
pass
def test_create_file(self):
- '''Test example.create_file()'''
+ """Test example.create_file()"""
# The os module has been replaced with the fake os module so all of the
# following occurs in the fake filesystem.
- self.assertFalse(os.path.isdir('/test'))
- os.mkdir('/test')
- self.assertTrue(os.path.isdir('/test'))
+ self.assertFalse(os.path.isdir("/test"))
+ os.mkdir("/test")
+ self.assertTrue(os.path.isdir("/test"))
- self.assertFalse(os.path.exists('/test/file.txt'))
- example.create_file('/test/file.txt')
- self.assertTrue(os.path.exists('/test/file.txt'))
+ self.assertFalse(os.path.exists("/test/file.txt"))
+ example.create_file("/test/file.txt")
+ self.assertTrue(os.path.exists("/test/file.txt"))
...