Skip to content

Commit

Permalink
Update fake.py (#1)
Browse files Browse the repository at this point in the history
* Update fake.py
  • Loading branch information
barseghyanartur authored Nov 27, 2023
1 parent 5f372c2 commit 6bb0524
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
__author__ = "Artur Barseghyan <artur.barseghyan@gmail.com>"
__copyright__ = "2023 Artur Barseghyan"
__license__ = "MIT"
__all__ = ("Faker",)
__all__ = (
"Faker",
"TextPdfGenerator",
"GraphicPdfGenerator",
"DocxGenerator",
"AuthorshipData",
)


PDF_TEXT_TPL_PAGE_OBJECT = """{page_num} 0 obj
Expand Down Expand Up @@ -156,7 +162,7 @@ class TextPdfGenerator:
.. code-block:: python
from pathlib import Path
from faker import Faker, TextPdfGenerator
from fake import Faker, TextPdfGenerator
FAKER = Faker()
Expand Down Expand Up @@ -263,7 +269,7 @@ class GraphicPdfGenerator:
.. code-block:: python
from pathlib import Path
from faker import Faker, GraphicPdfGenerator
from fake import Faker, GraphicPdfGenerator
FAKER = Faker()
Expand Down Expand Up @@ -532,7 +538,7 @@ class Faker:
.. code-block:: python
from faker import Faker
from fake import Faker
FAKER = Faker()
Expand Down Expand Up @@ -560,18 +566,16 @@ class Faker:
.. code-block:: python
from pathlib import Path
from faker import Faker, TextPdfGenerator, GraphicPdfGenerator
from fake import Faker, TextPdfGenerator, GraphicPdfGenerator
FAKER = Faker()
graphic_pdf_file = Path("media") / "graphic_pdf.pdf"
graphic_pdf_file.write_bytes(
FAKER.pdf(num_pages=100, generator=GraphicPdfGenerator)
Path("/tmp/graphic_pdf.pdf").write_bytes(
FAKER.pdf(nb_pages=100, generator=GraphicPdfGenerator)
)
text_pdf_file = Path("media") / "text_pdf.pdf"
text_pdf_file.write_bytes(
FAKER.pdf(num_pages=100, generator=TextPdfGenerator)
Path("/tmp/text_pdf.pdf").write_bytes(
FAKER.pdf(nb_pages=100, generator=TextPdfGenerator)
)
----
Expand All @@ -581,21 +585,17 @@ class Faker:
.. code-block:: python
from pathlib import Path
from faker import Faker, TextPdfGenerator, GraphicPdfGenerator
from fake import Faker, TextPdfGenerator, GraphicPdfGenerator
FAKER = Faker()
png_file = Path("media") / "image.png"
png_file.write_bytes(FAKER.png())
Path("/tmp/image.png").write_bytes(FAKER.png())
svg_file = Path("media") / "image.svg"
svg_file.write_bytes(FAKER.svg())
Path("/tmp/image.svg").write_bytes(FAKER.svg())
bmp_file = Path("media") / "image.bmp"
bmp_file.write_bytes(FAKER.bmp())
Path("/tmp/image.bmp").write_bytes(FAKER.bmp())
gif_file = Path("media") / "image.gif"
gif_file.write_bytes(FAKER.gif())
Path("/tmp/image.gif").write_bytes(FAKER.gif())
Note, that all image formats accept `size` (default: `(100, 100)`)
and `color`(default: `(255, 0, 0)`) arguments.
Expand Down Expand Up @@ -1111,7 +1111,7 @@ def test_email(self) -> None:
for domain, expected_domain in domains:
with self.subTest(domain=domain, expected_domain=expected_domain):
kwargs = {"domain": domain}
email: str = self.faker.email(**kwargs)
email: str = self.faker.email(**kwargs) # type: ignore
self.assertIsInstance(email, str)
self.assertTrue(email.endswith(f"@{expected_domain}"))

Expand Down Expand Up @@ -1295,8 +1295,8 @@ def test_text_pdf(self):
with self.subTest("All params None, should fail"):
with self.assertRaises(ValueError):
self.faker.pdf(
nb_pages=None, # noqa
texts=None, # noqa
nb_pages=None, # type: ignore
texts=None,
generator=TextPdfGenerator,
)

Expand Down Expand Up @@ -1339,13 +1339,15 @@ def test_gif(self):
def test_image(self):
for image_format in {"png", "svg", "bmp", "gif"}:
with self.subTest(image_format=image_format):
image = self.faker.image(image_format=image_format)
image = self.faker.image(
image_format=image_format, # type: ignore
)
self.assertTrue(image)
self.assertIsInstance(image, bytes)
for image_format in {"bin"}:
with self.subTest(image_format=image_format):
with self.assertRaises(ValueError):
self.faker.image(image_format=image_format)
self.faker.image(image_format=image_format) # type: ignore

def test_docx(self):
with self.subTest("All params None, should fail"):
Expand Down

0 comments on commit 6bb0524

Please sign in to comment.