diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 20229636..21f50d63 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,6 +61,8 @@ jobs: steps: - name: Install wkhtmltopdf run: sudo apt-get update && sudo apt-get install -y wkhtmltopdf libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0 poppler-utils + - name: Clean-up + run: sudo apt clean && sudo apt autoclean && sudo rm -rf /tmp/* && sudo rm -rf /usr/share/dotnet && sudo rm -rf /opt/ghc && sudo rm -rf "/usr/local/share/boost" && sudo rm -rf "$AGENT_TOOLSDIRECTORY" - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 @@ -105,6 +107,8 @@ jobs: steps: - name: Install wkhtmltopdf run: sudo apt-get update && sudo apt-get install -y wkhtmltopdf libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0 poppler-utils + - name: Clean-up + run: sudo apt clean && sudo apt autoclean && sudo rm -rf /tmp/* && sudo rm -rf /usr/share/dotnet && sudo rm -rf /opt/ghc && sudo rm -rf "/usr/local/share/boost" && sudo rm -rf "$AGENT_TOOLSDIRECTORY" - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 @@ -159,6 +163,8 @@ jobs: steps: - name: Install wkhtmltopdf run: sudo apt-get update && sudo apt-get install -y wkhtmltopdf libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0 poppler-utils + - name: Clean-up + run: sudo apt clean && sudo apt autoclean && sudo rm -rf /tmp/* && sudo rm -rf /usr/share/dotnet && sudo rm -rf /opt/ghc && sudo rm -rf "/usr/local/share/boost" && sudo rm -rf "$AGENT_TOOLSDIRECTORY" - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1527811e..18d3975e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,12 +4,13 @@ Release history and notes .. _Armenian genocide: https://en.wikipedia.org/wiki/Armenian_genocide .. _Blockade of the Republic of Artsakh: https://en.wikipedia.org/wiki/Blockade_of_the_Republic_of_Artsakh_(2022%E2%80%93present) +.. _Pillow: https://pypi.org/project/pillow/ .. _WeasyPrint: https://pypi.org/project/weasyprint/ .. _imgkit: https://pypi.org/project/imgkit/ .. _pdf2image: https://pypi.org/project/pdf2image/ .. _pdfkit: https://pypi.org/project/pdfkit/ -.. _Pillow: https://pypi.org/project/pillow/ .. _reportlab: https://pypi.org/project/reportlab/ +.. _wkhtmltopdf: https://wkhtmltopdf.org/ `Sequence based identifiers `_ @@ -26,6 +27,14 @@ are used for versioning (schema follows below): 0.3.4 to 0.4). - All backwards incompatible changes are mentioned in this document. +0.17.9 +------ +2023-10-10 + +- Improvements and fixes in the documentation. +- Announcing feature plans to change default PDF and Image generators + to `Pillow`_ based ones, instead of `wkhtmltopdf`_ in version 0.18. + 0.17.8 ------ 2023-09-21 diff --git a/docs/_static/css/prism_sphinx_rtd_theme.css b/docs/_static/css/prism_sphinx_rtd_theme.css new file mode 100644 index 00000000..bc5de47f --- /dev/null +++ b/docs/_static/css/prism_sphinx_rtd_theme.css @@ -0,0 +1,177 @@ +/** + * Python Sphinx RTD theme for PrismJs. + * + * The original sphinx-rtd-theme (https://github.com/readthedocs/sphinx_rtd_theme). + * + * Adapted from PrismJS prism-themes (https://github.com/PrismJS/prism-themes), + * specifically prism-gruvbox-light.css theme. + * + * @author Artur Barseghyan (https://github.com/barseghyanartur) + * @version 1.0 + */ + +code[class*="language-"], +pre[class*="language-"] { + color: #3c3836; + font-family: Consolas, Monaco, "Andale Mono", monospace; + direction: ltr; + text-align: left; + white-space: pre; + word-spacing: normal; + word-break: normal; + line-height: 1.5; + -moz-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; + -webkit-hyphens: none; + -moz-hyphens: none; + -ms-hyphens: none; + hyphens: none; +} + +pre[class*="language-"]::-moz-selection, +pre[class*="language-"] ::-moz-selection, +code[class*="language-"]::-moz-selection, +code[class*="language-"] ::-moz-selection { + color: #282828; + background: #a89984; +} + +pre[class*="language-"]::selection, +pre[class*="language-"] ::selection, +code[class*="language-"]::selection, +code[class*="language-"] ::selection { + color: #282828; + background: #a89984; +} + +/* Code blocks */ +pre[class*="language-"] { + padding: 1em; + margin: 0.5em 0; + overflow: auto; +} + +:not(pre) > code[class*="language-"], +pre[class*="language-"] { + background: #eeffcc; + border: none !important; + box-shadow: none !important; +} + +/* Inline code */ +:not(pre) > code[class*="language-"] { + padding: 0.1em; + border-radius: 0.3em; +} + +.token.comment { + font-style: italic; +} + +.token.comment, +.token.prolog, +.token.cdata { + color: #7c6f64; +} + +.token.keyword { + color: #007020; + font-weight: bold; +} + +.token.delimiter, +.token.boolean, +.token.selector, +.token.important, +.token.atrule { + color: #9d0006; +} + +.token.operator, +.token.punctuation, +.token.attr-name { + color: #7c6f64; + background-color: #eeffcc; +} + +.token.tag, +.token.tag .punctuation, +.token.doctype, +.token.builtin { + color: #b57614; +} + +.token.entity, +.token.number, +.token.symbol { + color: #8f3f71; +} + +.token.property, +.token.constant, +.token.variable { + color: #9d0006; +} + +.token.string { + color: #4070a0; +} + +.token.char { + color: #797403; +} + +.token.attr-value, +.token.attr-value .punctuation { + color: #7c6f64; +} + +.token.url { + color: #797403; + text-decoration: underline; +} + +.token.function { + color: #b57614; +} + +.token.regex { + background: #797403; +} + +.token.bold { + font-weight: bold; +} + +.token.italic { + font-style: italic; +} + +.token.inserted { + background: #7c6f64; +} + +.token.deleted { + background: #9d0006; +} + +/* Additional overrides */ +.rst-content code, +.rst-content tt, +code { + border: none; +} + +pre[class*="language-"] { + border: 1px solid #e1e4e5!important; +} +code[class*="language-"], +pre[class*="language-"] { + font-size: 12px; +} + +pre[class*="language-"] > code:first-child { + margin: 0!important; + padding: 0!important; +} diff --git a/docs/_static/examples/creating_docx/docx_1.py b/docs/_static/examples/creating_docx/docx_1.py new file mode 100644 index 00000000..4967423f --- /dev/null +++ b/docs/_static/examples/creating_docx/docx_1.py @@ -0,0 +1,9 @@ +# Required imports +from faker import Faker +from faker_file.providers.docx_file import DocxFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(DocxFileProvider) # Register DocxFileProvider + +# Generate DOCX file +docx_file = FAKER.docx_file() diff --git a/docs/_static/examples/creating_docx/docx_2.py b/docs/_static/examples/creating_docx/docx_2.py new file mode 100644 index 00000000..4e2e9020 --- /dev/null +++ b/docs/_static/examples/creating_docx/docx_2.py @@ -0,0 +1,9 @@ +# Required imports +from faker import Faker +from faker_file.providers.docx_file import DocxFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(DocxFileProvider) # Register DocxFileProvider + +# Generate DOCX file of 20,000 characters +docx_file = FAKER.docx_file(max_nb_chars=20_000) diff --git a/docs/_static/examples/creating_docx/docx_3.py b/docs/_static/examples/creating_docx/docx_3.py new file mode 100644 index 00000000..beb98c60 --- /dev/null +++ b/docs/_static/examples/creating_docx/docx_3.py @@ -0,0 +1,9 @@ +# Required imports +from faker import Faker +from faker_file.providers.docx_file import DocxFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(DocxFileProvider) # Register DocxFileProvider + +# Generate DOCX file, wrapping each line after 80 characters +docx_file = FAKER.docx_file(wrap_chars_after=80) diff --git a/docs/_static/examples/creating_docx/docx_4.py b/docs/_static/examples/creating_docx/docx_4.py new file mode 100644 index 00000000..00e97189 --- /dev/null +++ b/docs/_static/examples/creating_docx/docx_4.py @@ -0,0 +1,47 @@ +# Required imports +from faker import Faker +from faker_file.base import DynamicTemplate +from faker_file.contrib.docx_file import ( + add_page_break, + add_paragraph, + add_picture, + add_table, +) +from faker_file.providers.docx_file import DocxFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(DocxFileProvider) # Register DocxFileProvider + +# Create a DOCX file with paragraph, picture, table and manual page breaks +# in between the mentioned elements. The ``DynamicTemplate`` simply +# accepts a list of callables (such as ``add_paragraph``, +# ``add_page_break``) and dictionary to be later on fed to the callables +# as keyword arguments for customising the default values. +docx_file = FAKER.docx_file( + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + ) +) + +# You could make the list as long as you like or simply multiply for +# easier repetition as follows: +docx_file = FAKER.docx_file( + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + * 5 # Will repeat your config 5 times + ) +) diff --git a/docs/_static/examples/creating_images/augment_1.py b/docs/_static/examples/creating_images/augment_1.py new file mode 100644 index 00000000..0c976c6b --- /dev/null +++ b/docs/_static/examples/creating_images/augment_1.py @@ -0,0 +1,60 @@ +from faker import Faker +from faker_file.providers.augment_image_from_path import ( + AugmentImageFromPathProvider, +) +from faker_file.providers.augment_random_image_from_dir import ( + AugmentRandomImageFromDirProvider, +) +from faker_file.providers.image.augment import ( + add_brightness, + decrease_contrast, + flip_horizontal, + flip_vertical, + resize_height, + resize_width, +) +from faker_file.providers.png_file import GraphicPngFileProvider + +FAKER = Faker() +FAKER.add_provider(AugmentImageFromPathProvider) +FAKER.add_provider(AugmentRandomImageFromDirProvider) +FAKER.add_provider(GraphicPngFileProvider) + +# Create a couple of graphic images to augment later on. +FAKER.graphic_png_file(basename="01") # One named 01.png +# And 5 more with random names. +for __ in range(5): + FAKER.graphic_png_file() + +# We assumed that directory "/tmp/tmp/" exists and contains +# image files, among which "01.png". Augmentations will be applied +# sequentially, one by one until all fulfilled. If you wish to apply only +# a random number of augmentations, but not all, pass the `num_steps` +# argument, with value less than the number of `augmentations` provided. +augmented_image_file = FAKER.augment_image_from_path( + path="/tmp/tmp/01.png", + augmentations=[ + (flip_horizontal, {}), + (flip_vertical, {}), + (decrease_contrast, {}), + (add_brightness, {}), + (resize_width, {"lower": 0.9, "upper": 1.1}), + (resize_height, {"lower": 0.9, "upper": 1.1}), + ], + prefix="augmented_image_01_", + # num_steps=3, +) + +augmented_random_image_file = FAKER.augment_random_image_from_dir( + source_dir_path="/tmp/tmp/", + augmentations=[ + (flip_horizontal, {}), + (flip_vertical, {}), + (decrease_contrast, {}), + (add_brightness, {}), + (resize_width, {"lower": 0.9, "upper": 1.1}), + (resize_height, {"lower": 0.9, "upper": 1.1}), + ], + prefix="augmented_random_image_", + # num_steps=3, +) diff --git a/docs/_static/examples/creating_images/imgkit_1.py b/docs/_static/examples/creating_images/imgkit_1.py new file mode 100644 index 00000000..737c9adb --- /dev/null +++ b/docs/_static/examples/creating_images/imgkit_1.py @@ -0,0 +1,9 @@ +from faker import Faker +from faker_file.providers.image.imgkit_generator import ImgkitImageGenerator +from faker_file.providers.png_file import PngFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(PngFileProvider) # Register PngFileProvider + +# Generate PNG file using `imgkit` +pdf_file = FAKER.png_file(image_generator_cls=ImgkitImageGenerator) diff --git a/docs/_static/examples/creating_images/imgkit_2.py b/docs/_static/examples/creating_images/imgkit_2.py new file mode 100644 index 00000000..c28d7b8f --- /dev/null +++ b/docs/_static/examples/creating_images/imgkit_2.py @@ -0,0 +1,11 @@ +from faker import Faker +from faker_file.providers.image.imgkit_generator import ImgkitImageGenerator +from faker_file.providers.png_file import PngFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(PngFileProvider) # Register PngFileProvider + +# Generate an image file, wrapping each line after 80 characters +png_file = FAKER.png_file( + image_generator_cls=ImgkitImageGenerator, wrap_chars_after=80 +) diff --git a/docs/_static/examples/creating_images/imgkit_3.py b/docs/_static/examples/creating_images/imgkit_3.py new file mode 100644 index 00000000..6e419fcd --- /dev/null +++ b/docs/_static/examples/creating_images/imgkit_3.py @@ -0,0 +1,11 @@ +from faker import Faker +from faker_file.providers.image.imgkit_generator import ImgkitImageGenerator +from faker_file.providers.png_file import PngFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(PngFileProvider) # Register PngFileProvider + +# Generate an image file of 20,000 characters +png_file = FAKER.png_file( + image_generator_cls=ImgkitImageGenerator, max_nb_chars=20_000 +) diff --git a/docs/_static/examples/creating_images/imgkit_4.py b/docs/_static/examples/creating_images/imgkit_4.py new file mode 100644 index 00000000..cc7e53d5 --- /dev/null +++ b/docs/_static/examples/creating_images/imgkit_4.py @@ -0,0 +1,42 @@ +from faker import Faker +from faker_file.base import DynamicTemplate +from faker_file.contrib.image.imgkit_snippets import ( + add_paragraph, + add_picture, + add_table, +) +from faker_file.providers.image.imgkit_generator import ImgkitImageGenerator +from faker_file.providers.png_file import PngFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(PngFileProvider) # Register PngFileProvider + +# Create an image file with a paragraph, a picture and a table. +# The ``DynamicTemplate`` simply accepts a list of callables (such +# as ``add_paragraph``, ``add_picture``) and dictionary to be later on +# fed to the callables as keyword arguments for customising the default +# values. +png_file = FAKER.png_file( + image_generator_cls=ImgkitImageGenerator, + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_picture, {}), # Add picture + (add_table, {}), # Add table + ] + ), +) + +# You could make the list as long as you like or simply multiply for +# easier repetition as follows: +png_file = FAKER.png_file( + image_generator_cls=ImgkitImageGenerator, + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_picture, {}), # Add picture + (add_table, {}), # Add table + ] + * 5 # Will repeat your config 5 times + ), +) diff --git a/docs/_static/examples/creating_images/pillow_1.py b/docs/_static/examples/creating_images/pillow_1.py new file mode 100644 index 00000000..dcbb1862 --- /dev/null +++ b/docs/_static/examples/creating_images/pillow_1.py @@ -0,0 +1,8 @@ +from faker import Faker +from faker_file.providers.image.pil_generator import PilImageGenerator +from faker_file.providers.png_file import PngFileProvider + +FAKER = Faker() +FAKER.add_provider(PngFileProvider) + +png_file = FAKER.png_file(image_generator_cls=PilImageGenerator) diff --git a/docs/_static/examples/creating_images/pillow_2.py b/docs/_static/examples/creating_images/pillow_2.py new file mode 100644 index 00000000..d9b47ca9 --- /dev/null +++ b/docs/_static/examples/creating_images/pillow_2.py @@ -0,0 +1,19 @@ +from faker import Faker +from faker_file.providers.image.pil_generator import PilImageGenerator +from faker_file.providers.png_file import PngFileProvider + +FAKER = Faker() +FAKER.add_provider(PngFileProvider) + +png_file = FAKER.png_file( + image_generator_cls=PilImageGenerator, + image_generator_kwargs={ + "encoding": "utf8", + "font_size": 14, + "page_width": 800, + "page_height": 1200, + "line_height": 16, + "spacing": 5, + }, + wrap_chars_after=100, +) diff --git a/docs/_static/examples/creating_images/pillow_3.py b/docs/_static/examples/creating_images/pillow_3.py new file mode 100644 index 00000000..bd5daa54 --- /dev/null +++ b/docs/_static/examples/creating_images/pillow_3.py @@ -0,0 +1,42 @@ +from faker import Faker +from faker_file.base import DynamicTemplate +from faker_file.contrib.image.pil_snippets import ( + add_paragraph, + add_picture, + add_table, +) +from faker_file.providers.image.pil_generator import PilImageGenerator +from faker_file.providers.png_file import PngFileProvider + +FAKER = Faker() +FAKER.add_provider(PngFileProvider) + +# Create an image file with paragraph, picture and table. +# The ``DynamicTemplate`` simply accepts a list of callables (such as +# ``add_paragraph``, ``add_picture``) and dictionary to be later on fed +# to the callables as keyword arguments for customising the default +# values. +png_file = FAKER.png_file( + image_generator_cls=PilImageGenerator, + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_picture, {}), # Add picture + (add_table, {}), # Add table + ] + ), +) + +# You could make the list as long as you like or simply multiply for +# easier repetition as follows: +png_file = FAKER.png_file( + image_generator_cls=PilImageGenerator, + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_picture, {}), # Add picture + (add_table, {}), # Add table + ] + * 5 # Will repeat your config 5 times + ), +) diff --git a/docs/_static/examples/creating_images/pillow_4.py b/docs/_static/examples/creating_images/pillow_4.py new file mode 100644 index 00000000..8210b532 --- /dev/null +++ b/docs/_static/examples/creating_images/pillow_4.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.png_file import GraphicPngFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(GraphicPngFileProvider) # Register provider + +png_file = FAKER.graphic_png_file() diff --git a/docs/_static/examples/creating_images/pillow_5.py b/docs/_static/examples/creating_images/pillow_5.py new file mode 100644 index 00000000..4ac14e91 --- /dev/null +++ b/docs/_static/examples/creating_images/pillow_5.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.png_file import GraphicPngFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(GraphicPngFileProvider) # Register provider + +png_file = FAKER.graphic_png_file(size=(800, 800)) diff --git a/docs/_static/examples/creating_images/weasyprint_1.py b/docs/_static/examples/creating_images/weasyprint_1.py new file mode 100644 index 00000000..f7e07358 --- /dev/null +++ b/docs/_static/examples/creating_images/weasyprint_1.py @@ -0,0 +1,11 @@ +from faker import Faker +from faker_file.providers.image.weasyprint_generator import ( + WeasyPrintImageGenerator, +) +from faker_file.providers.png_file import PngFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(PngFileProvider) # Register provider + +# Generate image file using `WeasyPrint` +png_file = FAKER.png_file(image_generator_cls=WeasyPrintImageGenerator) diff --git a/docs/_static/examples/creating_images/weasyprint_2.py b/docs/_static/examples/creating_images/weasyprint_2.py new file mode 100644 index 00000000..9ac3d3d6 --- /dev/null +++ b/docs/_static/examples/creating_images/weasyprint_2.py @@ -0,0 +1,44 @@ +from faker import Faker +from faker_file.base import DynamicTemplate +from faker_file.contrib.image.weasyprint_snippets import ( + add_paragraph, + add_picture, + add_table, +) +from faker_file.providers.image.weasyprint_generator import ( + WeasyPrintImageGenerator, +) +from faker_file.providers.png_file import PngFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(PngFileProvider) # Register provider + +# Create an image file with paragraph, picture and table. +# The ``DynamicTemplate`` simply accepts a list of callables (such +# as ``add_paragraph``, ``add_picture``) and dictionary to be later on +# fed to the callables as keyword arguments for customising the default +# values. +png_file = FAKER.png_file( + image_generator_cls=WeasyPrintImageGenerator, + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_picture, {}), # Add picture + (add_table, {}), # Add table + ] + ), +) + +# You could make the list as long as you like or simply multiply for +# easier repetition as follows: +png_file = FAKER.png_file( + image_generator_cls=WeasyPrintImageGenerator, + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_picture, {}), # Add picture + (add_table, {}), # Add table + ] + * 5 # Will repeat your config 5 times + ), +) diff --git a/docs/_static/examples/creating_odt/odt_1.py b/docs/_static/examples/creating_odt/odt_1.py new file mode 100644 index 00000000..1472037e --- /dev/null +++ b/docs/_static/examples/creating_odt/odt_1.py @@ -0,0 +1,9 @@ +# Required imports +from faker import Faker +from faker_file.providers.odt_file import OdtFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(OdtFileProvider) # Register OdtFileProvider + +# Generate ODT file +odt_file = FAKER.odt_file() diff --git a/docs/_static/examples/creating_odt/odt_2.py b/docs/_static/examples/creating_odt/odt_2.py new file mode 100644 index 00000000..daead688 --- /dev/null +++ b/docs/_static/examples/creating_odt/odt_2.py @@ -0,0 +1,9 @@ +# Required imports +from faker import Faker +from faker_file.providers.odt_file import OdtFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(OdtFileProvider) # Register OdtFileProvider + +# Generate ODT file of 20,000 characters +odt_file = FAKER.odt_file(max_nb_chars=20_000) diff --git a/docs/_static/examples/creating_odt/odt_3.py b/docs/_static/examples/creating_odt/odt_3.py new file mode 100644 index 00000000..46d33904 --- /dev/null +++ b/docs/_static/examples/creating_odt/odt_3.py @@ -0,0 +1,9 @@ +# Required imports +from faker import Faker +from faker_file.providers.odt_file import OdtFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(OdtFileProvider) # Register OdtFileProvider + +# Generate ODT file, wrapping each line after 80 characters +odt_file = FAKER.odt_file(wrap_chars_after=80) diff --git a/docs/_static/examples/creating_odt/odt_4.py b/docs/_static/examples/creating_odt/odt_4.py new file mode 100644 index 00000000..d9e01fcf --- /dev/null +++ b/docs/_static/examples/creating_odt/odt_4.py @@ -0,0 +1,47 @@ +# Required imports +from faker import Faker +from faker_file.base import DynamicTemplate +from faker_file.contrib.odt_file import ( + add_page_break, + add_paragraph, + add_picture, + add_table, +) +from faker_file.providers.odt_file import OdtFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(OdtFileProvider) # Register OdtFileProvider + +# Create a ODT file with paragraph, picture, table and manual page breaks +# in between the mentioned elements. The ``DynamicTemplate`` simply +# accepts a list of callables (such as ``add_paragraph``, +# ``add_page_break``) and dictionary to be later on fed to the callables +# as keyword arguments for customising the default values. +odt_file = FAKER.odt_file( + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + ) +) + +# You could make the list as long as you like or simply multiply for +# easier repetition as follows: +odt_file = FAKER.odt_file( + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + * 5 # Will repeat your config 5 times + ) +) diff --git a/docs/_static/examples/creating_pdf/pdfkit_1.py b/docs/_static/examples/creating_pdf/pdfkit_1.py new file mode 100644 index 00000000..e22fd7f3 --- /dev/null +++ b/docs/_static/examples/creating_pdf/pdfkit_1.py @@ -0,0 +1,12 @@ +# Required imports +from faker import Faker +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.pdf_file.generators.pdfkit_generator import ( + PdfkitPdfGenerator, +) + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(PdfFileProvider) # Register PdfFileProvider + +# Generate PDF file using `pdfkit` +pdf_file = FAKER.pdf_file(pdf_generator_cls=PdfkitPdfGenerator) diff --git a/docs/_static/examples/creating_pdf/pdfkit_2.py b/docs/_static/examples/creating_pdf/pdfkit_2.py new file mode 100644 index 00000000..7dc7cd00 --- /dev/null +++ b/docs/_static/examples/creating_pdf/pdfkit_2.py @@ -0,0 +1,14 @@ +# Required imports +from faker import Faker +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.pdf_file.generators.pdfkit_generator import ( + PdfkitPdfGenerator, +) + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(PdfFileProvider) # Register PdfFileProvider + +# Generate PDF file of 20,000 characters, using `pdfkit` +pdf_file = FAKER.pdf_file( + pdf_generator_cls=PdfkitPdfGenerator, max_nb_chars=20_000 +) diff --git a/docs/_static/examples/creating_pdf/pdfkit_3.py b/docs/_static/examples/creating_pdf/pdfkit_3.py new file mode 100644 index 00000000..b7ee5ee0 --- /dev/null +++ b/docs/_static/examples/creating_pdf/pdfkit_3.py @@ -0,0 +1,14 @@ +# Required imports +from faker import Faker +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.pdf_file.generators.pdfkit_generator import ( + PdfkitPdfGenerator, +) + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(PdfFileProvider) # Register PdfFileProvider + +# Generate PDF file, wrapping each line after 80 characters, using `pdfkit` +pdf_file = FAKER.pdf_file( + pdf_generator_cls=PdfkitPdfGenerator, wrap_chars_after=80 +) diff --git a/docs/_static/examples/creating_pdf/pdfkit_4.py b/docs/_static/examples/creating_pdf/pdfkit_4.py new file mode 100644 index 00000000..2c70c57c --- /dev/null +++ b/docs/_static/examples/creating_pdf/pdfkit_4.py @@ -0,0 +1,52 @@ +# Required imports +from faker import Faker +from faker_file.base import DynamicTemplate +from faker_file.contrib.pdf_file.pdfkit_snippets import ( + add_page_break, + add_paragraph, + add_picture, + add_table, +) +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.pdf_file.generators.pdfkit_generator import ( + PdfkitPdfGenerator, +) + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(PdfFileProvider) # Register PdfFileProvider + +# Create a PDF file with paragraph, picture, table and manual page breaks +# in between the mentioned elements. The ``DynamicTemplate`` simply +# accepts a list of callables (such as ``add_paragraph``, +# ``add_page_break``) and dictionary to be later on fed to the callables +# as keyword arguments for customising the default values. +pdf_file = FAKER.pdf_file( + pdf_generator_cls=PdfkitPdfGenerator, + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + ), +) + +# You could make the list as long as you like or simply multiply for +# easier repetition as follows: +pdf_file = FAKER.pdf_file( + pdf_generator_cls=PdfkitPdfGenerator, + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + * 5 # Will repeat your config 5 times + ), +) diff --git a/docs/_static/examples/creating_pdf/pillow_1.py b/docs/_static/examples/creating_pdf/pillow_1.py new file mode 100644 index 00000000..23152307 --- /dev/null +++ b/docs/_static/examples/creating_pdf/pillow_1.py @@ -0,0 +1,10 @@ +from faker import Faker +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.pdf_file.generators.pil_generator import ( + PilPdfGenerator, +) + +FAKER = Faker() +FAKER.add_provider(PdfFileProvider) + +pdf_file = FAKER.pdf_file(pdf_generator_cls=PilPdfGenerator) diff --git a/docs/_static/examples/creating_pdf/pillow_2.py b/docs/_static/examples/creating_pdf/pillow_2.py new file mode 100644 index 00000000..79e2174a --- /dev/null +++ b/docs/_static/examples/creating_pdf/pillow_2.py @@ -0,0 +1,21 @@ +from faker import Faker +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.pdf_file.generators.pil_generator import ( + PilPdfGenerator, +) + +FAKER = Faker() +FAKER.add_provider(PdfFileProvider) + +pdf_file = FAKER.pdf_file( + pdf_generator_cls=PilPdfGenerator, + pdf_generator_kwargs={ + "encoding": "utf8", + "font_size": 14, + "page_width": 800, + "page_height": 1200, + "line_height": 16, + "spacing": 5, + }, + wrap_chars_after=100, +) diff --git a/docs/_static/examples/creating_pdf/pillow_3.py b/docs/_static/examples/creating_pdf/pillow_3.py new file mode 100644 index 00000000..369c20f2 --- /dev/null +++ b/docs/_static/examples/creating_pdf/pillow_3.py @@ -0,0 +1,51 @@ +from faker import Faker +from faker_file.base import DynamicTemplate +from faker_file.contrib.pdf_file.pil_snippets import ( + add_page_break, + add_paragraph, + add_picture, + add_table, +) +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.pdf_file.generators.pil_generator import ( + PilPdfGenerator, +) + +FAKER = Faker() +FAKER.add_provider(PdfFileProvider) + +# Create a PDF file with paragraph, picture, table and manual page breaks +# in between the mentioned elements. The ``DynamicTemplate`` simply +# accepts a list of callables (such as ``add_paragraph``, +# ``add_page_break``) and dictionary to be later on fed to the callables +# as keyword arguments for customising the default values. +pdf_file = FAKER.pdf_file( + pdf_generator_cls=PilPdfGenerator, + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + ), +) + +# You could make the list as long as you like or simply multiply for +# easier repetition as follows: +pdf_file = FAKER.pdf_file( + pdf_generator_cls=PilPdfGenerator, + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + * 5 # Will repeat your config 5 times + ), +) diff --git a/docs/_static/examples/creating_pdf/pillow_4.py b/docs/_static/examples/creating_pdf/pillow_4.py new file mode 100644 index 00000000..ee823bc4 --- /dev/null +++ b/docs/_static/examples/creating_pdf/pillow_4.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.pdf_file import GraphicPdfFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(GraphicPdfFileProvider) # Register provider + +pdf_file = FAKER.graphic_pdf_file() diff --git a/docs/_static/examples/creating_pdf/pillow_5.py b/docs/_static/examples/creating_pdf/pillow_5.py new file mode 100644 index 00000000..c5442417 --- /dev/null +++ b/docs/_static/examples/creating_pdf/pillow_5.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.pdf_file import GraphicPdfFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(GraphicPdfFileProvider) # Register provider + +pdf_file = FAKER.graphic_pdf_file(size=(800, 800)) diff --git a/docs/_static/examples/creating_pdf/reportlab_1.py b/docs/_static/examples/creating_pdf/reportlab_1.py new file mode 100644 index 00000000..57c83c04 --- /dev/null +++ b/docs/_static/examples/creating_pdf/reportlab_1.py @@ -0,0 +1,12 @@ +# Required imports +from faker import Faker +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.pdf_file.generators.reportlab_generator import ( + ReportlabPdfGenerator, +) + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(PdfFileProvider) # Register provider + +# Generate PDF file using `reportlab` +pdf_file = FAKER.pdf_file(pdf_generator_cls=ReportlabPdfGenerator) diff --git a/docs/_static/examples/creating_pdf/reportlab_2.py b/docs/_static/examples/creating_pdf/reportlab_2.py new file mode 100644 index 00000000..16654762 --- /dev/null +++ b/docs/_static/examples/creating_pdf/reportlab_2.py @@ -0,0 +1,52 @@ +# Required imports +from faker import Faker +from faker_file.base import DynamicTemplate +from faker_file.contrib.pdf_file.reportlab_snippets import ( + add_page_break, + add_paragraph, + add_picture, + add_table, +) +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.pdf_file.generators.reportlab_generator import ( + ReportlabPdfGenerator, +) + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(PdfFileProvider) # Register provider + +# Create a PDF file with paragraph, picture, table and manual page breaks +# in between the mentioned elements. The ``DynamicTemplate`` simply +# accepts a list of callables (such as ``add_paragraph``, +# ``add_page_break``) and dictionary to be later on fed to the callables +# as keyword arguments for customising the default values. +pdf_file = FAKER.pdf_file( + pdf_generator_cls=ReportlabPdfGenerator, + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + ), +) + +# You could make the list as long as you like or simply multiply for +# easier repetition as follows: +pdf_file = FAKER.pdf_file( + pdf_generator_cls=ReportlabPdfGenerator, + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + * 5 # Will repeat your config 5 times + ), +) diff --git a/docs/_static/examples/methodology/clean_up_files_1.py b/docs/_static/examples/methodology/clean_up_files_1.py new file mode 100644 index 00000000..887abf9b --- /dev/null +++ b/docs/_static/examples/methodology/clean_up_files_1.py @@ -0,0 +1,5 @@ +# Import instance at once +from faker_file.registry import FILE_REGISTRY + +# Trigger the clean-up +FILE_REGISTRY.clean_up() diff --git a/docs/_static/examples/methodology/clean_up_files_2.py b/docs/_static/examples/methodology/clean_up_files_2.py new file mode 100644 index 00000000..c07ac0c1 --- /dev/null +++ b/docs/_static/examples/methodology/clean_up_files_2.py @@ -0,0 +1,12 @@ +from faker import Faker +from faker_file.providers.txt_file import TxtFileProvider +from faker_file.registry import FILE_REGISTRY # Import instance at once + +FAKER = Faker() +FAKER.add_provider(TxtFileProvider) + +# Create a file to remove +txt_file = FAKER.txt_file() + +# We assume that there's an initialized `txt_file` instance to remove. +FILE_REGISTRY.remove(txt_file) # Where file is an instance of ``StringValue`` diff --git a/docs/_static/examples/methodology/clean_up_files_3.py b/docs/_static/examples/methodology/clean_up_files_3.py new file mode 100644 index 00000000..523a5dde --- /dev/null +++ b/docs/_static/examples/methodology/clean_up_files_3.py @@ -0,0 +1,14 @@ +from faker import Faker +from faker_file.providers.txt_file import TxtFileProvider +from faker_file.registry import FILE_REGISTRY # Import instance at once + +FAKER = Faker() +FAKER.add_provider(TxtFileProvider) + +# Create a file to remove +filename = str(FAKER.txt_file()) + +# We assume that there's an initialized `filename` (str) to remove. +txt_file = FILE_REGISTRY.search(filename) +if txt_file: + FILE_REGISTRY.remove(txt_file) diff --git a/docs/_static/examples/methodology/create_docx_file_1.py b/docs/_static/examples/methodology/create_docx_file_1.py new file mode 100644 index 00000000..530749b2 --- /dev/null +++ b/docs/_static/examples/methodology/create_docx_file_1.py @@ -0,0 +1,10 @@ +from faker import Faker +from faker_file.providers.docx_file import DocxFileProvider + +FAKER = Faker() +FAKER.add_provider(DocxFileProvider) + +docx_file = FAKER.docx_file(max_nb_chars=50) +print(docx_file) # Sample value: 'tmp/tmpgdctmfbp.docx' +print(docx_file.data["content"]) # Sample value: 'Learn where receive social.' +print(docx_file.data["filename"]) # Sample value: '/tmp/tmp/tmpgdctmfbp.docx' diff --git a/docs/_static/examples/methodology/create_docx_file_2.py b/docs/_static/examples/methodology/create_docx_file_2.py new file mode 100644 index 00000000..b468ccb1 --- /dev/null +++ b/docs/_static/examples/methodology/create_docx_file_2.py @@ -0,0 +1,43 @@ +from faker import Faker +from faker_file.providers.docx_file import DocxFileProvider + +FAKER = Faker() +FAKER.add_provider(DocxFileProvider) + +TEMPLATE = """ +{{date}} {{city}}, {{country}} + +Hello {{name}}, + +{{text}} + +Address: {{address}} + +Best regards, + +{{name}} +{{address}} +{{phone_number}} +""" + +docx_file = FAKER.docx_file(content=TEMPLATE) + +print(docx_file) # Sample value: 'tmp/tmpgdctmfbp.docx' +print(docx_file.data["content"]) +# Sample value below: +# 2009-05-14 Pettyberg, Puerto Rico +# Hello Lauren Williams, +# +# Everyone bill I information. Put particularly note language support +# green. Game free family probably case day vote. +# Commercial especially game heart. +# +# Address: 19017 Jennifer Drives +# Jamesbury, MI 39121 +# +# Best regards, +# +# Robin Jones +# 4650 Paul Extensions +# Port Johnside, VI 78151 +# 001-704-255-3093 diff --git a/docs/_static/examples/methodology/create_docx_file_3.py b/docs/_static/examples/methodology/create_docx_file_3.py new file mode 100644 index 00000000..a3c919da --- /dev/null +++ b/docs/_static/examples/methodology/create_docx_file_3.py @@ -0,0 +1,30 @@ +from faker import Faker +from faker_file.base import DynamicTemplate +from faker_file.contrib.docx_file import ( + add_page_break, + add_paragraph, + add_picture, + add_table, +) +from faker_file.providers.docx_file import DocxFileProvider + +FAKER = Faker() +FAKER.add_provider(DocxFileProvider) + +# Create a DOCX file with paragraph, picture, table and manual page breaks +# in between the mentioned elements. The ``DynamicTemplate`` simply +# accepts a list of callables (such as ``add_paragraph``, +# ``add_page_break``) and dictionary to be later on fed to the callables +# as keyword arguments for customising the default values. +docx_file = FAKER.docx_file( + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + ) +) diff --git a/docs/_static/examples/methodology/file_from_path_provider.py b/docs/_static/examples/methodology/file_from_path_provider.py new file mode 100644 index 00000000..2777c613 --- /dev/null +++ b/docs/_static/examples/methodology/file_from_path_provider.py @@ -0,0 +1,17 @@ +from faker import Faker +from faker_file.providers.docx_file import DocxFileProvider +from faker_file.providers.file_from_path import FileFromPathProvider + +FAKER = Faker() +FAKER.add_provider(FileFromPathProvider) +FAKER.add_provider(DocxFileProvider) + +# Create a file to use +docx_file = FAKER.docx_file(basename="file") + +# We assume that directory "/tmp/tmp/" exists and contains a file named +# "file.docx". +docx_file_copy = FAKER.file_from_path( + path="/tmp/tmp/file.docx", + prefix="zzz", +) diff --git a/docs/_static/examples/methodology/rand_file_from_dir_provider.py b/docs/_static/examples/methodology/rand_file_from_dir_provider.py new file mode 100644 index 00000000..5f53a7f0 --- /dev/null +++ b/docs/_static/examples/methodology/rand_file_from_dir_provider.py @@ -0,0 +1,18 @@ +from faker import Faker +from faker_file.providers.docx_file import DocxFileProvider +from faker_file.providers.random_file_from_dir import RandomFileFromDirProvider + +FAKER = Faker() +FAKER.add_provider(RandomFileFromDirProvider) +FAKER.add_provider(DocxFileProvider) + +# Create files to use +for __i in range(10): + FAKER.docx_file(basename="file") + +# We assume that directory "/tmp/tmp/" exists and contains files with".docx" +# extension. +docx_file_copy = FAKER.random_file_from_dir( + source_dir_path="/tmp/tmp/", + prefix="zzz", +) diff --git a/docs/_static/examples/prismjs/sample.js b/docs/_static/examples/prismjs/sample.js new file mode 100644 index 00000000..c25eda96 --- /dev/null +++ b/docs/_static/examples/prismjs/sample.js @@ -0,0 +1,5 @@ +function foo(bar) { + var a = 42, + b = 'Prism'; + return a + bar(b); +} diff --git a/docs/_static/examples/prismjs/sample.py b/docs/_static/examples/prismjs/sample.py new file mode 100644 index 00000000..299cadc9 --- /dev/null +++ b/docs/_static/examples/prismjs/sample.py @@ -0,0 +1,7 @@ +from typing import Callable + + +def foo(bar: Callable[[str], int]) -> int: + a = 42 + b = "Prism" + return a + bar(b) diff --git a/docs/_static/examples/quick_start/factory_import_and_init_1.py b/docs/_static/examples/quick_start/factory_import_and_init_1.py new file mode 100644 index 00000000..bc32e89c --- /dev/null +++ b/docs/_static/examples/quick_start/factory_import_and_init_1.py @@ -0,0 +1,125 @@ +# Imports and initialization +from django.conf import settings +from factory import Faker, Trait +from factory.django import DjangoModelFactory +from faker_file.providers.augment_file_from_dir import ( + AugmentFileFromDirProvider, +) +from faker_file.providers.bin_file import BinFileProvider +from faker_file.providers.bmp_file import BmpFileProvider +from faker_file.providers.csv_file import CsvFileProvider +from faker_file.providers.docx_file import DocxFileProvider +from faker_file.providers.eml_file import EmlFileProvider +from faker_file.providers.epub_file import EpubFileProvider +from faker_file.providers.ico_file import ( + GraphicIcoFileProvider, + IcoFileProvider, +) +from faker_file.providers.jpeg_file import ( + GraphicJpegFileProvider, + JpegFileProvider, +) +from faker_file.providers.mp3_file import Mp3FileProvider +from faker_file.providers.odp_file import OdpFileProvider +from faker_file.providers.ods_file import OdsFileProvider +from faker_file.providers.odt_file import OdtFileProvider +from faker_file.providers.pdf_file import ( + GraphicPdfFileProvider, + PdfFileProvider, +) +from faker_file.providers.png_file import ( + GraphicPngFileProvider, + PngFileProvider, +) +from faker_file.providers.pptx_file import PptxFileProvider +from faker_file.providers.random_file_from_dir import RandomFileFromDirProvider +from faker_file.providers.rtf_file import RtfFileProvider +from faker_file.providers.svg_file import SvgFileProvider +from faker_file.providers.tar_file import TarFileProvider +from faker_file.providers.txt_file import TxtFileProvider +from faker_file.providers.webp_file import ( + GraphicWebpFileProvider, + WebpFileProvider, +) +from faker_file.providers.xlsx_file import XlsxFileProvider +from faker_file.providers.zip_file import ZipFileProvider +from faker_file.storages.filesystem import FileSystemStorage + +from upload.models import Upload + +Faker.add_provider(AugmentFileFromDirProvider) +Faker.add_provider(BinFileProvider) +Faker.add_provider(BmpFileProvider) +Faker.add_provider(CsvFileProvider) +Faker.add_provider(DocxFileProvider) +Faker.add_provider(EmlFileProvider) +Faker.add_provider(EpubFileProvider) +Faker.add_provider(GraphicIcoFileProvider) +Faker.add_provider(GraphicJpegFileProvider) +Faker.add_provider(GraphicPdfFileProvider) +Faker.add_provider(GraphicPngFileProvider) +Faker.add_provider(GraphicWebpFileProvider) +Faker.add_provider(IcoFileProvider) +Faker.add_provider(JpegFileProvider) +Faker.add_provider(Mp3FileProvider) +Faker.add_provider(OdpFileProvider) +Faker.add_provider(OdsFileProvider) +Faker.add_provider(OdtFileProvider) +Faker.add_provider(PdfFileProvider) +Faker.add_provider(PngFileProvider) +Faker.add_provider(PptxFileProvider) +Faker.add_provider(RandomFileFromDirProvider) +Faker.add_provider(RtfFileProvider) +Faker.add_provider(SvgFileProvider) +Faker.add_provider(TarFileProvider) +Faker.add_provider(TxtFileProvider) +Faker.add_provider(WebpFileProvider) +Faker.add_provider(XlsxFileProvider) +Faker.add_provider(ZipFileProvider) + +# Define a file storage, because we need to customize things in +# order for it to work with Django. +STORAGE = FileSystemStorage(root_path=settings.MEDIA_ROOT, rel_path="tmp") + +# Factories + + +class UploadFactory(DjangoModelFactory): + """Upload factory.""" + + name = Faker("text", max_nb_chars=100) + description = Faker("text", max_nb_chars=1000) + + class Meta: + model = Upload + + class Params: + bin_file = Trait(file=Faker("bin_file", storage=STORAGE)) + bmp_file = Trait(file=Faker("bmp_file", storage=STORAGE)) + csv_file = Trait(file=Faker("csv_file", storage=STORAGE)) + docx_file = Trait(file=Faker("docx_file", storage=STORAGE)) + eml_file = Trait(file=Faker("eml_file", storage=STORAGE)) + epub_file = Trait(file=Faker("epub_file", storage=STORAGE)) + ico_file = Trait(file=Faker("ico_file", storage=STORAGE)) + jpeg_file = Trait(file=Faker("jpeg_file", storage=STORAGE)) + mp3_file = Trait(file=Faker("mp3_file", storage=STORAGE)) + odp_file = Trait(file=Faker("odp_file", storage=STORAGE)) + ods_file = Trait(file=Faker("ods_file", storage=STORAGE)) + odt_file = Trait(file=Faker("odt_file", storage=STORAGE)) + pdf_file = Trait(file=Faker("pdf_file", storage=STORAGE)) + png_file = Trait(file=Faker("png_file", storage=STORAGE)) + pptx_file = Trait(file=Faker("pptx_file", storage=STORAGE)) + rtf_file = Trait(file=Faker("rtf_file", storage=STORAGE)) + svg_file = Trait(file=Faker("svg_file", storage=STORAGE)) + tar_file = Trait(file=Faker("tar_file", storage=STORAGE)) + txt_file = Trait(file=Faker("txt_file", storage=STORAGE)) + webp_file = Trait(file=Faker("webp_file", storage=STORAGE)) + xlsx_file = Trait(file=Faker("xlsx_file", storage=STORAGE)) + zip_file = Trait(file=Faker("zip_file", storage=STORAGE)) + + +# Usage examples +UploadFactory(bin_file=True) # Upload with BIN file +UploadFactory(docx_file=True) # Upload with DOCX file +UploadFactory(jpeg_file=True) # Upload with JPEG file +UploadFactory(zip_file=True) # Upload with ZIP file diff --git a/docs/_static/examples/quick_start/factory_models_1.py b/docs/_static/examples/quick_start/factory_models_1.py new file mode 100644 index 00000000..33bcf170 --- /dev/null +++ b/docs/_static/examples/quick_start/factory_models_1.py @@ -0,0 +1,19 @@ +from django.db import models + + +class Upload(models.Model): + """Upload model.""" + + name = models.CharField(max_length=255, unique=True) + description = models.TextField(null=True, blank=True) + + # File + file = models.FileField(null=True) + + class Meta: + app_label = "uploads" # Ignore this line when copying + verbose_name = "Upload" + verbose_name_plural = "Upload" + + def __str__(self): + return self.name diff --git a/docs/_static/examples/quick_start/import_and_init_1.py b/docs/_static/examples/quick_start/import_and_init_1.py new file mode 100644 index 00000000..a5ff7035 --- /dev/null +++ b/docs/_static/examples/quick_start/import_and_init_1.py @@ -0,0 +1,155 @@ +# Imports and initialization +from faker import Faker +from faker_file.providers.augment_file_from_dir import ( + AugmentFileFromDirProvider, +) +from faker_file.providers.bin_file import BinFileProvider +from faker_file.providers.bmp_file import BmpFileProvider +from faker_file.providers.csv_file import CsvFileProvider +from faker_file.providers.docx_file import DocxFileProvider +from faker_file.providers.eml_file import EmlFileProvider +from faker_file.providers.epub_file import EpubFileProvider +from faker_file.providers.gif_file import GifFileProvider +from faker_file.providers.ico_file import ( + GraphicIcoFileProvider, + IcoFileProvider, +) +from faker_file.providers.jpeg_file import ( + GraphicJpegFileProvider, + JpegFileProvider, +) +from faker_file.providers.mp3_file import Mp3FileProvider +from faker_file.providers.odp_file import OdpFileProvider +from faker_file.providers.ods_file import OdsFileProvider +from faker_file.providers.odt_file import OdtFileProvider +from faker_file.providers.pdf_file import ( + GraphicPdfFileProvider, + PdfFileProvider, +) +from faker_file.providers.png_file import ( + GraphicPngFileProvider, + PngFileProvider, +) +from faker_file.providers.pptx_file import PptxFileProvider +from faker_file.providers.random_file_from_dir import RandomFileFromDirProvider +from faker_file.providers.rtf_file import RtfFileProvider +from faker_file.providers.svg_file import SvgFileProvider +from faker_file.providers.tar_file import TarFileProvider +from faker_file.providers.tiff_file import TiffFileProvider +from faker_file.providers.txt_file import TxtFileProvider +from faker_file.providers.webp_file import ( + GraphicWebpFileProvider, + WebpFileProvider, +) +from faker_file.providers.xlsx_file import XlsxFileProvider +from faker_file.providers.zip_file import ZipFileProvider + +FAKER = Faker() +FAKER.add_provider(AugmentFileFromDirProvider) +FAKER.add_provider(BinFileProvider) +FAKER.add_provider(BmpFileProvider) +FAKER.add_provider(CsvFileProvider) +FAKER.add_provider(DocxFileProvider) +FAKER.add_provider(EmlFileProvider) +FAKER.add_provider(EpubFileProvider) +FAKER.add_provider(GifFileProvider) +FAKER.add_provider(GraphicIcoFileProvider) +FAKER.add_provider(GraphicJpegFileProvider) +FAKER.add_provider(GraphicPdfFileProvider) +FAKER.add_provider(GraphicPngFileProvider) +FAKER.add_provider(GraphicWebpFileProvider) +FAKER.add_provider(IcoFileProvider) +FAKER.add_provider(JpegFileProvider) +FAKER.add_provider(Mp3FileProvider) +FAKER.add_provider(OdpFileProvider) +FAKER.add_provider(OdsFileProvider) +FAKER.add_provider(OdtFileProvider) +FAKER.add_provider(PdfFileProvider) +FAKER.add_provider(PngFileProvider) +FAKER.add_provider(PptxFileProvider) +FAKER.add_provider(RandomFileFromDirProvider) +FAKER.add_provider(RtfFileProvider) +FAKER.add_provider(SvgFileProvider) +FAKER.add_provider(TarFileProvider) +FAKER.add_provider(TiffFileProvider) +FAKER.add_provider(TxtFileProvider) +FAKER.add_provider(WebpFileProvider) +FAKER.add_provider(XlsxFileProvider) +FAKER.add_provider(ZipFileProvider) + +# Create files to test `augment_file_from_dir` with +FAKER.docx_file() +FAKER.eml_file() +FAKER.odt_file() +FAKER.txt_file() + +# Usage examples +# augmented_file = FAKER.augment_file_from_dir( +# source_dir_path="/tmp/tmp/", +# ) +bin_file = FAKER.bin_file() +bmp_file = FAKER.bmp_file() +csv_file = FAKER.csv_file() +docx_file = FAKER.docx_file() +eml_file = FAKER.eml_file() +epub_file = FAKER.epub_file() +gif_file = FAKER.gif_file() +graphic_ico_file = FAKER.graphic_ico_file() +graphic_jpeg_file = FAKER.graphic_jpeg_file() +graphic_pdf_file = FAKER.graphic_pdf_file() +graphic_png_file = FAKER.graphic_png_file() +graphic_webp_file = FAKER.graphic_webp_file() +ico_file = FAKER.ico_file() +jpeg_file = FAKER.jpeg_file() +mp3_file = FAKER.mp3_file() +odp_file = FAKER.odp_file() +ods_file = FAKER.ods_file() +odt_file = FAKER.odt_file() +pdf_file = FAKER.pdf_file() +png_file = FAKER.png_file() +pptx_file = FAKER.pptx_file() +random_file = FAKER.random_file_from_dir( + source_dir_path="/tmp/tmp/", +) +rtf_file = FAKER.rtf_file() +svg_file = FAKER.svg_file() +tar_file = FAKER.tar_file() +tiff_file = FAKER.tiff_file() +txt_file = FAKER.txt_file() +# webp_file = FAKER.webp_file() +xlsx_file = FAKER.xlsx_file() +zip_file = FAKER.zip_file() + +# Usage examples bytes back +# augmented_raw = FAKER.augment_file_from_dir( +# source_dir_path="/tmp/tmp/", +# raw=True, +# ) +bin_raw = FAKER.bin_file(raw=True) +bmp_raw = FAKER.bmp_file(raw=True) +csv_raw = FAKER.csv_file(raw=True) +docx_raw = FAKER.docx_file(raw=True) +eml_raw = FAKER.eml_file(raw=True) +epub_raw = FAKER.epub_file(raw=True) +gif_raw = FAKER.gif_file(raw=True) +ico_raw = FAKER.ico_file(raw=True) +jpeg_raw = FAKER.jpeg_file(raw=True) +mp3_raw = FAKER.mp3_file(raw=True) +odp_raw = FAKER.odp_file(raw=True) +ods_raw = FAKER.ods_file(raw=True) +odt_raw = FAKER.odt_file(raw=True) +pdf_raw = FAKER.pdf_file(raw=True) +png_raw = FAKER.png_file(raw=True) +pptx_raw = FAKER.pptx_file(raw=True) +random_raw = FAKER.random_file_from_dir( + source_dir_path="/tmp/tmp/", + raw=True, +) +rtf_raw = FAKER.rtf_file(raw=True) +svg_raw = FAKER.svg_file(raw=True) +tar_raw = FAKER.tar_file(raw=True) +tiff_raw = FAKER.tiff_file(raw=True) +txt_raw = FAKER.txt_file(raw=True) +# webp_raw = FAKER.webp_file(raw=True) +xlsx_raw = FAKER.xlsx_file(raw=True) +zip_raw = FAKER.zip_file(raw=True) diff --git a/docs/_static/examples/recipes/augment_file_from_dir_1.py b/docs/_static/examples/recipes/augment_file_from_dir_1.py new file mode 100644 index 00000000..2f9eeb35 --- /dev/null +++ b/docs/_static/examples/recipes/augment_file_from_dir_1.py @@ -0,0 +1,28 @@ +from faker import Faker +from faker_file.providers.augment_file_from_dir import ( + AugmentFileFromDirProvider, +) +from faker_file.providers.docx_file import DocxFileProvider +from faker_file.providers.eml_file import EmlFileProvider +from faker_file.providers.odt_file import OdtFileProvider +from faker_file.providers.txt_file import TxtFileProvider + +FAKER = Faker() +FAKER.add_provider(DocxFileProvider) +FAKER.add_provider(TxtFileProvider) +FAKER.add_provider(EmlFileProvider) +FAKER.add_provider(OdtFileProvider) +FAKER.add_provider(AugmentFileFromDirProvider) + +# Create files to test `augment_file_from_dir` with +FAKER.docx_file() +FAKER.eml_file() +FAKER.odt_file() +FAKER.txt_file() + +# We assume that directory "/tmp/tmp/" exists and contains +# files of `DOCX`, `EML`, `EPUB`, `ODT`, `PDF`, `RTF` or `TXT` +# formats. +augmented_file = FAKER.augment_file_from_dir( + source_dir_path="/tmp/tmp/", +) diff --git a/docs/_static/examples/recipes/augment_file_from_dir_2.py b/docs/_static/examples/recipes/augment_file_from_dir_2.py new file mode 100644 index 00000000..c6e6bd0a --- /dev/null +++ b/docs/_static/examples/recipes/augment_file_from_dir_2.py @@ -0,0 +1,28 @@ +from faker import Faker +from faker_file.providers.augment_file_from_dir import ( + AugmentFileFromDirProvider, +) +from faker_file.providers.docx_file import DocxFileProvider +from faker_file.providers.eml_file import EmlFileProvider +from faker_file.providers.odt_file import OdtFileProvider +from faker_file.providers.txt_file import TxtFileProvider + +FAKER = Faker() +FAKER.add_provider(DocxFileProvider) +FAKER.add_provider(TxtFileProvider) +FAKER.add_provider(EmlFileProvider) +FAKER.add_provider(OdtFileProvider) +FAKER.add_provider(AugmentFileFromDirProvider) + +# Create files to test `augment_file_from_dir` with +FAKER.docx_file() +FAKER.eml_file() +FAKER.odt_file() +FAKER.txt_file() + +# We assume that directory "/tmp/tmp/" exists and contains +# files of `DOCX` and `ODT` formats. +augmented_file = FAKER.augment_file_from_dir( + source_dir_path="/tmp/tmp/", + extensions={"docx", "odt"}, # Pick only DOCX or ODT +) diff --git a/docs/_static/examples/recipes/augment_file_from_dir_3.py b/docs/_static/examples/recipes/augment_file_from_dir_3.py new file mode 100644 index 00000000..54f1cea0 --- /dev/null +++ b/docs/_static/examples/recipes/augment_file_from_dir_3.py @@ -0,0 +1,36 @@ +from faker import Faker +from faker_file.providers.augment_file_from_dir import ( + AugmentFileFromDirProvider, +) +from faker_file.providers.augment_file_from_dir.augmenters import ( + nlpaug_augmenter, +) +from faker_file.providers.docx_file import DocxFileProvider +from faker_file.providers.eml_file import EmlFileProvider +from faker_file.providers.odt_file import OdtFileProvider +from faker_file.providers.txt_file import TxtFileProvider + +FAKER = Faker() +FAKER.add_provider(DocxFileProvider) +FAKER.add_provider(TxtFileProvider) +FAKER.add_provider(EmlFileProvider) +FAKER.add_provider(OdtFileProvider) +FAKER.add_provider(AugmentFileFromDirProvider) + +# Create files to test `augment_file_from_dir` with +FAKER.docx_file() +FAKER.eml_file() +FAKER.odt_file() +FAKER.txt_file() + +# We assume that directory "/tmp/tmp/" exists and contains +# files of `DOCX`, `EML`, `EPUB`, `ODT`, `PDF`, `RTF` or `TXT` +# formats. +augmented_file = FAKER.augment_file_from_dir( + source_dir_path="/tmp/tmp/", + text_augmenter_cls=nlpaug_augmenter.ContextualWordEmbeddingsAugmenter, + text_augmenter_kwargs={ + "model_path": "bert-base-cased", + "action": "substitute", # or "insert" + }, +) diff --git a/docs/_static/examples/recipes/aws_s3_storage_1.py b/docs/_static/examples/recipes/aws_s3_storage_1.py new file mode 100644 index 00000000..a5f2ad43 --- /dev/null +++ b/docs/_static/examples/recipes/aws_s3_storage_1.py @@ -0,0 +1,14 @@ +from faker import Faker +from faker_file.providers.txt_file import TxtFileProvider +from faker_file.storages.aws_s3 import AWSS3Storage + +FAKER = Faker() +FAKER.add_provider(TxtFileProvider) + +AWS_S3_STORAGE = AWSS3Storage( + bucket_name="your-bucket-name", + root_path="", + rel_path="", +) + +txt_file = FAKER.txt_file(storage=AWS_S3_STORAGE) diff --git a/docs/_static/examples/recipes/aws_s3_storage_2.py b/docs/_static/examples/recipes/aws_s3_storage_2.py new file mode 100644 index 00000000..6e352197 --- /dev/null +++ b/docs/_static/examples/recipes/aws_s3_storage_2.py @@ -0,0 +1,14 @@ +from faker import Faker +from faker_file.providers.txt_file import TxtFileProvider +from faker_file.storages.aws_s3 import AWSS3Storage + +FAKER = Faker() +FAKER.add_provider(TxtFileProvider) + +AWS_S3_STORAGE = AWSS3Storage( + bucket_name="your-bucket-name", + root_path="", + rel_path="user/uploads", +) + +txt_file = FAKER.txt_file(storage=AWS_S3_STORAGE) diff --git a/docs/_static/examples/recipes/aws_s3_storage_3.py b/docs/_static/examples/recipes/aws_s3_storage_3.py new file mode 100644 index 00000000..abad8645 --- /dev/null +++ b/docs/_static/examples/recipes/aws_s3_storage_3.py @@ -0,0 +1,15 @@ +from django.conf import settings +from faker import Faker +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.storages.aws_s3 import AWSS3Storage + +STORAGE = AWSS3Storage( + bucket_name=settings.AWS_STORAGE_BUCKET_NAME, + root_path="", + rel_path="", +) + +FAKER = Faker() +FAKER.add_provider(PdfFileProvider) + +pdf_file = FAKER.pdf_file(storage=STORAGE) diff --git a/docs/_static/examples/recipes/aws_s3_storage_4.py b/docs/_static/examples/recipes/aws_s3_storage_4.py new file mode 100644 index 00000000..d49a7517 --- /dev/null +++ b/docs/_static/examples/recipes/aws_s3_storage_4.py @@ -0,0 +1,28 @@ +from django.conf import settings +from factory import Faker +from factory.django import DjangoModelFactory +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.storages.aws_s3 import AWSS3Storage + +from upload.models import Upload + +STORAGE = AWSS3Storage( + bucket_name=settings.AWS_STORAGE_BUCKET_NAME, + root_path="", + rel_path="", +) + +Faker.add_provider(PdfFileProvider) + + +class UploadFactory(DjangoModelFactory): + name = Faker("word") + description = Faker("text") + file = Faker("pdf_file", storage=STORAGE) + + class Meta: + model = Upload + + +# Usage example +upload = UploadFactory() diff --git a/docs/_static/examples/recipes/docx_file_1.py b/docs/_static/examples/recipes/docx_file_1.py new file mode 100644 index 00000000..6be7e257 --- /dev/null +++ b/docs/_static/examples/recipes/docx_file_1.py @@ -0,0 +1,11 @@ +from faker import Faker +from faker_file.providers.docx_file import DocxFileProvider + +FAKER = Faker() +FAKER.add_provider(DocxFileProvider) + +docx_file = FAKER.docx_file( + prefix="zzz", + max_nb_chars=1_024, + wrap_chars_after=80, +) diff --git a/docs/_static/examples/recipes/docx_file_mixed_1.py b/docs/_static/examples/recipes/docx_file_mixed_1.py new file mode 100644 index 00000000..8952f4ef --- /dev/null +++ b/docs/_static/examples/recipes/docx_file_mixed_1.py @@ -0,0 +1,30 @@ +from faker import Faker +from faker_file.base import DynamicTemplate +from faker_file.contrib.docx_file import ( + add_page_break, + add_paragraph, + add_picture, + add_table, +) +from faker_file.providers.docx_file import DocxFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(DocxFileProvider) # Register DocxFileProvider + +# Create a DOCX file with paragraph, picture, table and manual page breaks +# in between the mentioned elements. The ``DynamicTemplate`` simply +# accepts a list of callables (such as ``add_paragraph``, +# ``add_page_break``) and dictionary to be later on fed to the callables +# as keyword arguments for customising the default values. +docx_file = FAKER.docx_file( + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + ) +) diff --git a/docs/_static/examples/recipes/eml_file_1.py b/docs/_static/examples/recipes/eml_file_1.py new file mode 100644 index 00000000..3f0672ca --- /dev/null +++ b/docs/_static/examples/recipes/eml_file_1.py @@ -0,0 +1,9 @@ +from faker import Faker +from faker_file.providers.eml_file import EmlFileProvider + +FAKER = Faker() +FAKER.add_provider(EmlFileProvider) + +eml_file = FAKER.eml_file( + options={"create_inner_file_args": {"content": "Lorem ipsum"}} +) diff --git a/docs/_static/examples/recipes/eml_file_2.py b/docs/_static/examples/recipes/eml_file_2.py new file mode 100644 index 00000000..09c79ccd --- /dev/null +++ b/docs/_static/examples/recipes/eml_file_2.py @@ -0,0 +1,18 @@ +from faker import Faker +from faker_file.providers.eml_file import EmlFileProvider +from faker_file.providers.helpers.inner import create_inner_docx_file + +FAKER = Faker() +FAKER.add_provider(EmlFileProvider) + +eml_file = FAKER.eml_file( + prefix="zzz", + options={ + "count": 3, + "create_inner_file_func": create_inner_docx_file, + "create_inner_file_args": { + "prefix": "xxx_", + "max_nb_chars": 1_024, + }, + }, +) diff --git a/docs/_static/examples/recipes/eml_file_3.py b/docs/_static/examples/recipes/eml_file_3.py new file mode 100644 index 00000000..ba5daa1f --- /dev/null +++ b/docs/_static/examples/recipes/eml_file_3.py @@ -0,0 +1,28 @@ +from faker import Faker +from faker_file.providers.eml_file import EmlFileProvider +from faker_file.providers.helpers.inner import ( + create_inner_docx_file, + create_inner_eml_file, +) + +FAKER = Faker() +FAKER.add_provider(EmlFileProvider) + +eml_file = FAKER.eml_file( + prefix="nested_level_0_", + options={ + "create_inner_file_func": create_inner_eml_file, + "create_inner_file_args": { + "prefix": "nested_level_1_", + "options": { + "create_inner_file_func": create_inner_eml_file, + "create_inner_file_args": { + "prefix": "nested_level_2_", + "options": { + "create_inner_file_func": create_inner_docx_file, + }, + }, + }, + }, + }, +) diff --git a/docs/_static/examples/recipes/eml_file_4.py b/docs/_static/examples/recipes/eml_file_4.py new file mode 100644 index 00000000..ef243ded --- /dev/null +++ b/docs/_static/examples/recipes/eml_file_4.py @@ -0,0 +1,31 @@ +from faker import Faker +from faker_file.providers.eml_file import EmlFileProvider +from faker_file.providers.helpers.inner import ( + create_inner_docx_file, + create_inner_epub_file, + create_inner_txt_file, + fuzzy_choice_create_inner_file, +) +from faker_file.storages.filesystem import FileSystemStorage + +FAKER = Faker() +FAKER.add_provider(EmlFileProvider) + +STORAGE = FileSystemStorage() + +kwargs = {"storage": STORAGE, "generator": FAKER} + +eml_file = FAKER.eml_file( + prefix="zzz", + options={ + "count": 10, + "create_inner_file_func": fuzzy_choice_create_inner_file, + "create_inner_file_args": { + "func_choices": [ + (create_inner_docx_file, kwargs), + (create_inner_epub_file, kwargs), + (create_inner_txt_file, kwargs), + ], + }, + }, +) diff --git a/docs/_static/examples/recipes/factory_boy_factory_1.py b/docs/_static/examples/recipes/factory_boy_factory_1.py new file mode 100644 index 00000000..3c64c65b --- /dev/null +++ b/docs/_static/examples/recipes/factory_boy_factory_1.py @@ -0,0 +1,94 @@ +from django.conf import settings +from factory import Faker, Trait +from factory.django import DjangoModelFactory + +# Import all providers we want to use +from faker_file.providers.bin_file import BinFileProvider +from faker_file.providers.csv_file import CsvFileProvider +from faker_file.providers.docx_file import DocxFileProvider +from faker_file.providers.eml_file import EmlFileProvider +from faker_file.providers.epub_file import EpubFileProvider +from faker_file.providers.ico_file import IcoFileProvider +from faker_file.providers.jpeg_file import JpegFileProvider +from faker_file.providers.mp3_file import Mp3FileProvider +from faker_file.providers.ods_file import OdsFileProvider +from faker_file.providers.odt_file import OdtFileProvider +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.png_file import PngFileProvider +from faker_file.providers.pptx_file import PptxFileProvider +from faker_file.providers.rtf_file import RtfFileProvider +from faker_file.providers.svg_file import SvgFileProvider +from faker_file.providers.txt_file import TxtFileProvider +from faker_file.providers.webp_file import WebpFileProvider +from faker_file.providers.xlsx_file import XlsxFileProvider +from faker_file.providers.zip_file import ZipFileProvider + +# Import file storage, because we need to customize things in order for it +# to work with Django. +from faker_file.storages.filesystem import FileSystemStorage + +from upload.models import Upload + +# Add all providers we want to use +Faker.add_provider(BinFileProvider) +Faker.add_provider(CsvFileProvider) +Faker.add_provider(DocxFileProvider) +Faker.add_provider(EmlFileProvider) +Faker.add_provider(EpubFileProvider) +Faker.add_provider(IcoFileProvider) +Faker.add_provider(JpegFileProvider) +Faker.add_provider(Mp3FileProvider) +Faker.add_provider(OdsFileProvider) +Faker.add_provider(OdtFileProvider) +Faker.add_provider(PdfFileProvider) +Faker.add_provider(PngFileProvider) +Faker.add_provider(PptxFileProvider) +Faker.add_provider(RtfFileProvider) +Faker.add_provider(SvgFileProvider) +Faker.add_provider(TxtFileProvider) +Faker.add_provider(WebpFileProvider) +Faker.add_provider(XlsxFileProvider) +Faker.add_provider(ZipFileProvider) + +# Define a file storage. When working with Django and FileSystemStorage +# you need to set the value of `root_path` argument to +# `settings.MEDIA_ROOT`. +STORAGE = FileSystemStorage(root_path=settings.MEDIA_ROOT, rel_path="tmp") + + +class UploadFactory(DjangoModelFactory): + """Upload factory.""" + + name = Faker("text", max_nb_chars=100) + description = Faker("text", max_nb_chars=1000) + + class Meta: + model = Upload + + class Params: + bin_file = Trait(file=Faker("bin_file", storage=STORAGE)) + csv_file = Trait(file=Faker("csv_file", storage=STORAGE)) + docx_file = Trait(file=Faker("docx_file", storage=STORAGE)) + eml_file = Trait(file=Faker("eml_file", storage=STORAGE)) + epub_file = Trait(file=Faker("epub_file", storage=STORAGE)) + ico_file = Trait(file=Faker("ico_file", storage=STORAGE)) + jpeg_file = Trait(file=Faker("jpeg_file", storage=STORAGE)) + mp3_file = Trait(file=Faker("mp3_file", storage=STORAGE)) + ods_file = Trait(file=Faker("ods_file", storage=STORAGE)) + odt_file = Trait(file=Faker("odt_file", storage=STORAGE)) + pdf_file = Trait(file=Faker("pdf_file", storage=STORAGE)) + png_file = Trait(file=Faker("png_file", storage=STORAGE)) + pptx_file = Trait(file=Faker("pptx_file", storage=STORAGE)) + rtf_file = Trait(file=Faker("rtf_file", storage=STORAGE)) + svg_file = Trait(file=Faker("svg_file", storage=STORAGE)) + txt_file = Trait(file=Faker("txt_file", storage=STORAGE)) + webp_file = Trait(file=Faker("webp_file", storage=STORAGE)) + xlsx_file = Trait(file=Faker("xlsx_file", storage=STORAGE)) + zip_file = Trait(file=Faker("zip_file", storage=STORAGE)) + + +# Usage examples +UploadFactory(bin_file=True) # Upload with BIN file +UploadFactory(docx_file=True) # Upload with DOCX file +UploadFactory(jpeg_file=True) # Upload with JPEG file +UploadFactory(zip_file=True) # Upload with ZIP file diff --git a/docs/_static/examples/recipes/factory_boy_factory_2.py b/docs/_static/examples/recipes/factory_boy_factory_2.py new file mode 100644 index 00000000..75bd6902 --- /dev/null +++ b/docs/_static/examples/recipes/factory_boy_factory_2.py @@ -0,0 +1,99 @@ +from random import choice + +from django.conf import settings +from factory import Faker, LazyAttribute, Trait +from factory.django import DjangoModelFactory +from faker import Faker as OriginalFaker +from faker_file.providers.bin_file import BinFileProvider +from faker_file.providers.csv_file import CsvFileProvider +from faker_file.providers.docx_file import DocxFileProvider +from faker_file.providers.eml_file import EmlFileProvider +from faker_file.providers.epub_file import EpubFileProvider +from faker_file.providers.ico_file import IcoFileProvider +from faker_file.providers.jpeg_file import JpegFileProvider +from faker_file.providers.mp3_file import Mp3FileProvider +from faker_file.providers.ods_file import OdsFileProvider +from faker_file.providers.odt_file import OdtFileProvider +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.png_file import PngFileProvider +from faker_file.providers.pptx_file import PptxFileProvider +from faker_file.providers.rtf_file import RtfFileProvider +from faker_file.providers.svg_file import SvgFileProvider +from faker_file.providers.txt_file import TxtFileProvider +from faker_file.providers.webp_file import WebpFileProvider +from faker_file.providers.xlsx_file import XlsxFileProvider +from faker_file.providers.zip_file import ZipFileProvider +from faker_file.storages.filesystem import FileSystemStorage + +from upload.models import Upload + +FAKER = OriginalFaker() +FAKER.add_provider(BinFileProvider) +FAKER.add_provider(CsvFileProvider) +FAKER.add_provider(DocxFileProvider) +FAKER.add_provider(EmlFileProvider) +FAKER.add_provider(EpubFileProvider) +FAKER.add_provider(IcoFileProvider) +FAKER.add_provider(JpegFileProvider) +FAKER.add_provider(Mp3FileProvider) +FAKER.add_provider(OdsFileProvider) +FAKER.add_provider(OdtFileProvider) +FAKER.add_provider(PdfFileProvider) +FAKER.add_provider(PngFileProvider) +FAKER.add_provider(PptxFileProvider) +FAKER.add_provider(RtfFileProvider) +FAKER.add_provider(SvgFileProvider) +FAKER.add_provider(TxtFileProvider) +FAKER.add_provider(WebpFileProvider) +FAKER.add_provider(XlsxFileProvider) +FAKER.add_provider(ZipFileProvider) + +# Define a file storage. When working with Django and FileSystemStorage +# you need to set the value of `root_path` argument to +# `settings.MEDIA_ROOT`. +STORAGE = FileSystemStorage(root_path=settings.MEDIA_ROOT, rel_path="tmp") + + +def random_file_generator(*args, **kwargs): + random_provider = choice( + [ + "bin_file", + "csv_file", + "docx_file", + "eml_file", + "epub_file", + "ico_file", + "jpeg_file", + "mp3_file", + "ods_file", + "odt_file", + "pdf_file", + "png_file", + "pptx_file", + "rtf_file", + "svg_file", + "txt_file", + "webp_file", + "xlsx_file", + "zip_file", + ] + ) + func = getattr(FAKER, random_provider) + return func(storage=STORAGE) + + +class UploadFactory(DjangoModelFactory): + """Upload factory.""" + + name = Faker("text", max_nb_chars=100) + description = Faker("text", max_nb_chars=1000) + + class Meta: + model = Upload + + class Params: + random_file = Trait(file=LazyAttribute(random_file_generator)) + + +# Upload with randon file +upload = UploadFactory(random_file=True) diff --git a/docs/_static/examples/recipes/factory_boy_factory_3.py b/docs/_static/examples/recipes/factory_boy_factory_3.py new file mode 100644 index 00000000..fb20939c --- /dev/null +++ b/docs/_static/examples/recipes/factory_boy_factory_3.py @@ -0,0 +1,24 @@ +from factory import Faker +from factory.django import DjangoModelFactory +from faker_file.providers.odt_file import OdtFileProvider + +from upload.models import Upload + + +class UploadFactory(DjangoModelFactory): + """Base Upload factory.""" + + name = Faker("text", max_nb_chars=100) + description = Faker("text", max_nb_chars=1000) + file = Faker("odt_file") + + class Meta: + """Meta class.""" + + model = Upload + + +# Example usage +with Faker.override_default_locale("hy_AM"): # Set locale to Armenian + Faker.add_provider(OdtFileProvider) + upload = UploadFactory() diff --git a/docs/_static/examples/recipes/factory_boy_models_1.py b/docs/_static/examples/recipes/factory_boy_models_1.py new file mode 100644 index 00000000..33bcf170 --- /dev/null +++ b/docs/_static/examples/recipes/factory_boy_models_1.py @@ -0,0 +1,19 @@ +from django.db import models + + +class Upload(models.Model): + """Upload model.""" + + name = models.CharField(max_length=255, unique=True) + description = models.TextField(null=True, blank=True) + + # File + file = models.FileField(null=True) + + class Meta: + app_label = "uploads" # Ignore this line when copying + verbose_name = "Upload" + verbose_name_plural = "Upload" + + def __str__(self): + return self.name diff --git a/docs/_static/examples/recipes/file_from_path_1.py b/docs/_static/examples/recipes/file_from_path_1.py new file mode 100644 index 00000000..a69ed9de --- /dev/null +++ b/docs/_static/examples/recipes/file_from_path_1.py @@ -0,0 +1,16 @@ +from faker import Faker +from faker_file.providers.docx_file import DocxFileProvider +from faker_file.providers.file_from_path import FileFromPathProvider + +FAKER = Faker() +FAKER.add_provider(DocxFileProvider) +FAKER.add_provider(FileFromPathProvider) + +# Create a file to test `file_from_path` with. +FAKER.docx_file(basename="file") + +# We assume that the file "/tmp/tmp/file.docx" exists. +docx_file = FAKER.file_from_path( + path="/tmp/tmp/file.docx", + prefix="zzz", +) diff --git a/docs/_static/examples/recipes/file_of_size_bin_1.py b/docs/_static/examples/recipes/file_of_size_bin_1.py new file mode 100644 index 00000000..3432013d --- /dev/null +++ b/docs/_static/examples/recipes/file_of_size_bin_1.py @@ -0,0 +1,13 @@ +from faker import Faker +from faker_file.providers.bin_file import BinFileProvider + +FAKER = Faker() +FAKER.add_provider(BinFileProvider) + +bin_file = FAKER.bin_file(length=1024**2) # 1 Mb +bin_file = FAKER.bin_file(length=3 * 1024**2) # 3 Mb +bin_file = FAKER.bin_file(length=10 * 1024**2) # 10 Mb + +bin_file = FAKER.bin_file(length=1024) # 1 Kb +bin_file = FAKER.bin_file(length=3 * 1024) # 3 Kb +bin_file = FAKER.bin_file(length=10 * 1024) # 10 Kb diff --git a/docs/_static/examples/recipes/file_of_size_txt_1.py b/docs/_static/examples/recipes/file_of_size_txt_1.py new file mode 100644 index 00000000..68d4f676 --- /dev/null +++ b/docs/_static/examples/recipes/file_of_size_txt_1.py @@ -0,0 +1,13 @@ +from faker import Faker +from faker_file.providers.txt_file import TxtFileProvider + +FAKER = Faker() +FAKER.add_provider(TxtFileProvider) + +txt_file = FAKER.txt_file(max_nb_chars=1024**2) # 1 Mb +txt_file = FAKER.txt_file(max_nb_chars=3 * 1024**2) # 3 Mb +txt_file = FAKER.txt_file(max_nb_chars=10 * 1024**2) # 10 Mb + +txt_file = FAKER.txt_file(max_nb_chars=1024) # 1 Kb +txt_file = FAKER.txt_file(max_nb_chars=3 * 1024) # 3 Kb +txt_file = FAKER.txt_file(max_nb_chars=10 * 1024) # 10 Kb diff --git a/docs/_static/examples/recipes/files_multiprocessing_1.py b/docs/_static/examples/recipes/files_multiprocessing_1.py new file mode 100644 index 00000000..bdbc9b6b --- /dev/null +++ b/docs/_static/examples/recipes/files_multiprocessing_1.py @@ -0,0 +1,22 @@ +from multiprocessing import Pool + +from faker import Faker +from faker_file.providers.helpers.inner import create_inner_docx_file +from faker_file.storages.filesystem import FileSystemStorage + +FAKER = Faker() +STORAGE = FileSystemStorage() + +# Document template +TEMPLATE = "Hey {{name}},\n{{text}},\nBest regards\n{{name}}" + +with Pool(processes=2) as pool: + for _ in range(10): # Number of times we want to run our function + pool.apply_async( + create_inner_docx_file, + # Apply async doesn't support kwargs. We have to pass all + # arguments. + [STORAGE, "mp", FAKER, None, None, TEMPLATE], + ) + pool.close() + pool.join() diff --git a/docs/_static/examples/recipes/files_multiprocessing_2.py b/docs/_static/examples/recipes/files_multiprocessing_2.py new file mode 100644 index 00000000..cd8d4806 --- /dev/null +++ b/docs/_static/examples/recipes/files_multiprocessing_2.py @@ -0,0 +1,53 @@ +from multiprocessing import Pool + +from faker import Faker +from faker_file.providers.helpers.inner import ( + create_inner_docx_file, + create_inner_epub_file, + create_inner_pdf_file, + create_inner_txt_file, + fuzzy_choice_create_inner_file, +) +from faker_file.storages.filesystem import FileSystemStorage + +FAKER = Faker() +STORAGE = FileSystemStorage() + +# Document template +TEMPLATE = """ +{{date}} {{city}}, {{country}} + +Hello {{name}}, + +{{text}} {{text}} {{text}} + +{{text}} {{text}} {{text}} + +{{text}} {{text}} {{text}} + +Address: {{address}} + +Best regards, + +{{name}} +{{address}} +{{phone_number}} +""" + +kwargs = {"storage": STORAGE, "generator": FAKER, "content": TEMPLATE} + +with Pool(processes=2) as pool: + for _ in range(10): # Number of times we want to run our function + pool.apply_async( + fuzzy_choice_create_inner_file, + [ + [ + (create_inner_docx_file, kwargs), + (create_inner_epub_file, kwargs), + (create_inner_pdf_file, kwargs), + (create_inner_txt_file, kwargs), + ] + ], + ) + pool.close() + pool.join() diff --git a/docs/_static/examples/recipes/flexible_storage_1.py b/docs/_static/examples/recipes/flexible_storage_1.py new file mode 100644 index 00000000..d9c158a9 --- /dev/null +++ b/docs/_static/examples/recipes/flexible_storage_1.py @@ -0,0 +1,28 @@ +from django.conf import settings +from django.core.files.storage import default_storage +from faker_file.storages.aws_s3 import AWSS3Storage +from faker_file.storages.filesystem import FileSystemStorage +from storages.backends.s3boto3 import S3Boto3Storage + +# Faker doesn't know anything about Django. That's why, if we want to +# support remote storages, we need to manually check which file storage +# backend is used. If `Boto3` storage backend (of the `django-storages` +# package) is used we use the correspondent `AWSS3Storage` class of the +# `faker-file`. +# Otherwise, fall back to native file system storage (`FileSystemStorage`) +# of the `faker-file`. +if isinstance(default_storage, S3Boto3Storage): + STORAGE = AWSS3Storage( + bucket_name=settings.AWS_STORAGE_BUCKET_NAME, + credentials={ + "key_id": settings.AWS_ACCESS_KEY_ID, + "key_secret": settings.AWS_SECRET_ACCESS_KEY, + }, + root_path="", + rel_path="tmp", + ) +else: + STORAGE = FileSystemStorage( + root_path=settings.MEDIA_ROOT, + rel_path="tmp", + ) diff --git a/docs/_static/examples/recipes/generic_file_1.py b/docs/_static/examples/recipes/generic_file_1.py new file mode 100644 index 00000000..8943d0a3 --- /dev/null +++ b/docs/_static/examples/recipes/generic_file_1.py @@ -0,0 +1,10 @@ +from faker import Faker +from faker_file.providers.generic_file import GenericFileProvider + +FAKER = Faker() +FAKER.add_provider(GenericFileProvider) + +generic_file = FAKER.generic_file( + content="

{{text}}

", + extension="html", +) diff --git a/docs/_static/examples/recipes/google_cloud_storage_1.py b/docs/_static/examples/recipes/google_cloud_storage_1.py new file mode 100644 index 00000000..ea27b0bc --- /dev/null +++ b/docs/_static/examples/recipes/google_cloud_storage_1.py @@ -0,0 +1,14 @@ +from faker import Faker +from faker_file.providers.txt_file import TxtFileProvider +from faker_file.storages.google_cloud_storage import GoogleCloudStorage + +FAKER = Faker() +FAKER.add_provider(TxtFileProvider) + +GC_STORAGE = GoogleCloudStorage( + bucket_name="your-bucket-name", + root_path="", + rel_path="", +) + +# txt_file = FAKER.txt_file(storage=GC_STORAGE) diff --git a/docs/_static/examples/recipes/google_cloud_storage_2.py b/docs/_static/examples/recipes/google_cloud_storage_2.py new file mode 100644 index 00000000..e1464bbc --- /dev/null +++ b/docs/_static/examples/recipes/google_cloud_storage_2.py @@ -0,0 +1,14 @@ +from faker import Faker +from faker_file.providers.txt_file import TxtFileProvider +from faker_file.storages.google_cloud_storage import GoogleCloudStorage + +FAKER = Faker() +FAKER.add_provider(TxtFileProvider) + +GC_STORAGE = GoogleCloudStorage( + bucket_name="your-bucket-name", + root_path="", + rel_path="user/uploads", +) + +# txt_file = FAKER.txt_file(storage=GC_STORAGE) diff --git a/docs/_static/examples/recipes/graphic_ico_file_1.py b/docs/_static/examples/recipes/graphic_ico_file_1.py new file mode 100644 index 00000000..d0a4f797 --- /dev/null +++ b/docs/_static/examples/recipes/graphic_ico_file_1.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.ico_file import GraphicIcoFileProvider + +FAKER = Faker() +FAKER.add_provider(GraphicIcoFileProvider) + +ico_file = FAKER.graphic_ico_file(size=(800, 800)) diff --git a/docs/_static/examples/recipes/graphic_jpeg_file_1.py b/docs/_static/examples/recipes/graphic_jpeg_file_1.py new file mode 100644 index 00000000..ebd5a9f5 --- /dev/null +++ b/docs/_static/examples/recipes/graphic_jpeg_file_1.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.jpeg_file import GraphicJpegFileProvider + +FAKER = Faker() +FAKER.add_provider(GraphicJpegFileProvider) + +jpeg_file = FAKER.graphic_jpeg_file(size=(800, 800)) diff --git a/docs/_static/examples/recipes/graphic_png_file_1.py b/docs/_static/examples/recipes/graphic_png_file_1.py new file mode 100644 index 00000000..bb0f5523 --- /dev/null +++ b/docs/_static/examples/recipes/graphic_png_file_1.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.png_file import GraphicPngFileProvider + +FAKER = Faker() +FAKER.add_provider(GraphicPngFileProvider) + +png_file = FAKER.graphic_png_file(size=(800, 800)) diff --git a/docs/_static/examples/recipes/graphic_webp_file_1.py b/docs/_static/examples/recipes/graphic_webp_file_1.py new file mode 100644 index 00000000..02f00036 --- /dev/null +++ b/docs/_static/examples/recipes/graphic_webp_file_1.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.webp_file import GraphicWebpFileProvider + +FAKER = Faker() +FAKER.add_provider(GraphicWebpFileProvider) + +webp_file = FAKER.graphic_webp_file(size=(800, 800)) diff --git a/docs/_static/examples/recipes/imports_and_init_1.py b/docs/_static/examples/recipes/imports_and_init_1.py new file mode 100644 index 00000000..82b87833 --- /dev/null +++ b/docs/_static/examples/recipes/imports_and_init_1.py @@ -0,0 +1,8 @@ +from faker import Faker +from faker_file.providers.txt_file import TxtFileProvider + +FAKER = Faker() +FAKER.add_provider(TxtFileProvider) + +# Usage example +txt_file = FAKER.txt_file(content="Lorem ipsum") diff --git a/docs/_static/examples/recipes/imports_and_init_2.py b/docs/_static/examples/recipes/imports_and_init_2.py new file mode 100644 index 00000000..44aac29a --- /dev/null +++ b/docs/_static/examples/recipes/imports_and_init_2.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.txt_file import TxtFileProvider + +FAKER = Faker() + +# Usage example +txt_file = TxtFileProvider(FAKER).txt_file(content="Lorem ipsum") diff --git a/docs/_static/examples/recipes/mp3_file_1.py b/docs/_static/examples/recipes/mp3_file_1.py new file mode 100644 index 00000000..924f9b51 --- /dev/null +++ b/docs/_static/examples/recipes/mp3_file_1.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.mp3_file import Mp3FileProvider + +FAKER = Faker() +FAKER.add_provider(Mp3FileProvider) + +mp3_file = FAKER.mp3_file() diff --git a/docs/_static/examples/recipes/mp3_file_custom_1.py b/docs/_static/examples/recipes/mp3_file_custom_1.py new file mode 100644 index 00000000..cfd8e9ad --- /dev/null +++ b/docs/_static/examples/recipes/mp3_file_custom_1.py @@ -0,0 +1,40 @@ +from faker import Faker +from faker_file.providers.base.mp3_generator import BaseMp3Generator +from faker_file.providers.mp3_file import Mp3FileProvider +from marytts import MaryTTS # Imaginary `marytts` Python library + +FAKER = Faker() +FAKER.add_provider(Mp3FileProvider) + + +# Define custom MP3 generator +class MaryTtsMp3Generator(BaseMp3Generator): + locale: str = "cmu-rms-hsmm" + voice: str = "en_US" + + def handle_kwargs(self, **kwargs) -> None: + # Since it's impossible to unify all TTS systems it's allowed + # to pass arbitrary arguments to the `BaseMp3Generator` + # constructor. Each implementation class contains its own + # additional tuning arguments. Check the source code of the + # implemented MP3 generators as an example. + if "locale" in kwargs: + self.locale = kwargs["locale"] + if "voice" in kwargs: + self.voice = kwargs["voice"] + + def generate(self) -> bytes: + # Your implementation here. Note, that `self.content` + # in this context is the text to make MP3 from. + # `self.generator` would be the `Faker` or `Generator` + # instance from which you could extract information on + # active locale. + # What comes below is pseudo implementation. + mary_tts = MaryTTS(locale=self.locale, voice=self.voice) + return mary_tts.synth_mp3(self.content) + + +# Generate MP3 file from random text +mp3_file = FAKER.mp3_file( + mp3_generator_cls=MaryTtsMp3Generator, +) diff --git a/docs/_static/examples/recipes/mp3_file_edge_tts_1.py b/docs/_static/examples/recipes/mp3_file_edge_tts_1.py new file mode 100644 index 00000000..4bcaa817 --- /dev/null +++ b/docs/_static/examples/recipes/mp3_file_edge_tts_1.py @@ -0,0 +1,10 @@ +from faker import Faker +from faker_file.providers.mp3_file import Mp3FileProvider +from faker_file.providers.mp3_file.generators.edge_tts_generator import ( + EdgeTtsMp3Generator, +) + +FAKER = Faker() +FAKER.add_provider(Mp3FileProvider) + +mp3_file = FAKER.mp3_file(mp3_generator_cls=EdgeTtsMp3Generator) diff --git a/docs/_static/examples/recipes/mp3_file_edge_tts_2.py b/docs/_static/examples/recipes/mp3_file_edge_tts_2.py new file mode 100644 index 00000000..01b5fb97 --- /dev/null +++ b/docs/_static/examples/recipes/mp3_file_edge_tts_2.py @@ -0,0 +1,15 @@ +from faker import Faker +from faker_file.providers.mp3_file import Mp3FileProvider +from faker_file.providers.mp3_file.generators.edge_tts_generator import ( + EdgeTtsMp3Generator, +) + +FAKER = Faker() +FAKER.add_provider(Mp3FileProvider) + +mp3_file = FAKER.mp3_file( + mp3_generator_cls=EdgeTtsMp3Generator, + mp3_generator_kwargs={ + "voice": "en-GB-LibbyNeural", + }, +) diff --git a/docs/_static/examples/recipes/mp3_file_gtts_1.py b/docs/_static/examples/recipes/mp3_file_gtts_1.py new file mode 100644 index 00000000..3d183663 --- /dev/null +++ b/docs/_static/examples/recipes/mp3_file_gtts_1.py @@ -0,0 +1,10 @@ +from faker import Faker +from faker_file.providers.mp3_file import Mp3FileProvider +from faker_file.providers.mp3_file.generators.gtts_generator import ( + GttsMp3Generator, +) + +FAKER = Faker() +FAKER.add_provider(Mp3FileProvider) + +mp3_file = FAKER.mp3_file(mp3_generator_cls=GttsMp3Generator) diff --git a/docs/_static/examples/recipes/mp3_file_gtts_2.py b/docs/_static/examples/recipes/mp3_file_gtts_2.py new file mode 100644 index 00000000..8903b1bc --- /dev/null +++ b/docs/_static/examples/recipes/mp3_file_gtts_2.py @@ -0,0 +1,16 @@ +from faker import Faker +from faker_file.providers.mp3_file import Mp3FileProvider +from faker_file.providers.mp3_file.generators.gtts_generator import ( + GttsMp3Generator, +) + +FAKER = Faker() +FAKER.add_provider(Mp3FileProvider) + +mp3_file = FAKER.mp3_file( + mp3_generator_cls=GttsMp3Generator, + mp3_generator_kwargs={ + "lang": "en", + "tld": "co.uk", + }, +) diff --git a/docs/_static/examples/recipes/odt_file_mixed_1.py b/docs/_static/examples/recipes/odt_file_mixed_1.py new file mode 100644 index 00000000..ca77916c --- /dev/null +++ b/docs/_static/examples/recipes/odt_file_mixed_1.py @@ -0,0 +1,30 @@ +from faker import Faker +from faker_file.base import DynamicTemplate +from faker_file.contrib.odt_file import ( + add_page_break, + add_paragraph, + add_picture, + add_table, +) +from faker_file.providers.odt_file import OdtFileProvider + +FAKER = Faker() # Initialize Faker +FAKER.add_provider(OdtFileProvider) # Register OdtFileProvider + +# Create a ODT file with paragraph, picture, table and manual page breaks +# in between the mentioned elements. The ``DynamicTemplate`` simply +# accepts a list of callables (such as ``add_paragraph``, +# ``add_page_break``) and dictionary to be later on fed to the callables +# as keyword arguments for customising the default values. +odt_file = FAKER.odt_file( + content=DynamicTemplate( + [ + (add_paragraph, {}), # Add paragraph + (add_page_break, {}), # Add page break + (add_picture, {}), # Add picture + (add_page_break, {}), # Add page break + (add_table, {}), # Add table + (add_page_break, {}), # Add page break + ] + ) +) diff --git a/docs/_static/examples/recipes/pdf_file_1.py b/docs/_static/examples/recipes/pdf_file_1.py new file mode 100644 index 00000000..04b51b41 --- /dev/null +++ b/docs/_static/examples/recipes/pdf_file_1.py @@ -0,0 +1,27 @@ +from faker import Faker +from faker_file.providers.pdf_file import PdfFileProvider + +FAKER = Faker() +FAKER.add_provider(PdfFileProvider) + +TEMPLATE = """ +{{date}} {{city}}, {{country}} + +Hello {{name}}, + +{{text}} {{text}} {{text}} + +{{text}} {{text}} {{text}} + +{{text}} {{text}} {{text}} + +Address: {{address}} + +Best regards, + +{{name}} +{{address}} +{{phone_number}} +""" + +pdf_file = FAKER.pdf_file(content=TEMPLATE, wrap_chars_after=80) diff --git a/docs/_static/examples/recipes/pdf_file_pdfkit_1.py b/docs/_static/examples/recipes/pdf_file_pdfkit_1.py new file mode 100644 index 00000000..ba070df0 --- /dev/null +++ b/docs/_static/examples/recipes/pdf_file_pdfkit_1.py @@ -0,0 +1,10 @@ +from faker import Faker +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.pdf_file.generators.pdfkit_generator import ( + PdfkitPdfGenerator, +) + +FAKER = Faker() +FAKER.add_provider(PdfFileProvider) + +pdf_file = FAKER.pdf_file(pdf_generator_cls=PdfkitPdfGenerator) diff --git a/docs/_static/examples/recipes/pdf_file_pillow_1.py b/docs/_static/examples/recipes/pdf_file_pillow_1.py new file mode 100644 index 00000000..30de0e19 --- /dev/null +++ b/docs/_static/examples/recipes/pdf_file_pillow_1.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.pdf_file import GraphicPdfFileProvider + +FAKER = Faker() +FAKER.add_provider(GraphicPdfFileProvider) + +pdf_file = FAKER.graphic_pdf_file() diff --git a/docs/_static/examples/recipes/pdf_file_pillow_2.py b/docs/_static/examples/recipes/pdf_file_pillow_2.py new file mode 100644 index 00000000..0cf4bbbd --- /dev/null +++ b/docs/_static/examples/recipes/pdf_file_pillow_2.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.pdf_file import GraphicPdfFileProvider + +FAKER = Faker() +FAKER.add_provider(GraphicPdfFileProvider) + +pdf_file = FAKER.graphic_pdf_file(size=(800, 800)) diff --git a/docs/_static/examples/recipes/pdf_file_reportlab_1.py b/docs/_static/examples/recipes/pdf_file_reportlab_1.py new file mode 100644 index 00000000..fc52e207 --- /dev/null +++ b/docs/_static/examples/recipes/pdf_file_reportlab_1.py @@ -0,0 +1,10 @@ +from faker import Faker +from faker_file.providers.pdf_file import PdfFileProvider +from faker_file.providers.pdf_file.generators.reportlab_generator import ( + ReportlabPdfGenerator, +) + +FAKER = Faker() +FAKER.add_provider(PdfFileProvider) + +pdf_file = FAKER.pdf_file(pdf_generator_cls=ReportlabPdfGenerator) diff --git a/docs/_static/examples/recipes/random_file_from_dir_1.py b/docs/_static/examples/recipes/random_file_from_dir_1.py new file mode 100644 index 00000000..3a8ddfdc --- /dev/null +++ b/docs/_static/examples/recipes/random_file_from_dir_1.py @@ -0,0 +1,17 @@ +from faker import Faker +from faker_file.providers.random_file_from_dir import RandomFileFromDirProvider +from faker_file.providers.txt_file import TxtFileProvider + +FAKER = Faker() +FAKER.add_provider(TxtFileProvider) +FAKER.add_provider(RandomFileFromDirProvider) + +# Create files to test `random_file_from_dir` with +for __i in range(5): + FAKER.txt_file() + +# We assume that directory "/tmp/tmp/" exists and contains files. +random_file = FAKER.random_file_from_dir( + source_dir_path="/tmp/tmp/", + prefix="zzz", +) diff --git a/docs/_static/examples/recipes/raw_1.py b/docs/_static/examples/recipes/raw_1.py new file mode 100644 index 00000000..8ebf547e --- /dev/null +++ b/docs/_static/examples/recipes/raw_1.py @@ -0,0 +1,44 @@ +import os +from io import BytesIO + +from django.test import TestCase +from django.urls import reverse +from faker import Faker +from faker_file.providers.docx_file import DocxFileProvider +from rest_framework.status import HTTP_201_CREATED + +from upload.models import Upload + +FAKER = Faker() +FAKER.add_provider(DocxFileProvider) + + +class UploadTestCase(TestCase): + """Upload test case.""" + + def test_create_docx_upload(self) -> None: + """Test create an Upload.""" + url = reverse("api:upload-list") + + raw = FAKER.docx_file(raw=True) + test_file = BytesIO(raw) + test_file.name = os.path.basename(raw.data["filename"]) + + payload = { + "name": FAKER.word(), + "description": FAKER.paragraph(), + "file": test_file, + } + + response = self.client.post(url, payload, format="json") + + # Test if request is handled properly (HTTP 201) + self.assertEqual(response.status_code, HTTP_201_CREATED) + + test_upload = Upload.objects.get(id=response.data["id"]) + + # Test if the name is properly recorded + self.assertEqual(str(test_upload.name), payload["name"]) + + # Test if file name recorded properly + self.assertEqual(str(test_upload.file.name), test_file.name) diff --git a/docs/_static/examples/recipes/sftp_storage_1.py b/docs/_static/examples/recipes/sftp_storage_1.py new file mode 100644 index 00000000..5182ee9d --- /dev/null +++ b/docs/_static/examples/recipes/sftp_storage_1.py @@ -0,0 +1,16 @@ +from faker import Faker +from faker_file.providers.txt_file import TxtFileProvider +from faker_file.storages.sftp_storage import SFTPStorage + +FAKER = Faker() +FAKER.add_provider(TxtFileProvider) + +SFTP_STORAGE = SFTPStorage( + host="your-sftp-host.domain", + port=22, + username="your-sftp-username", + password="your-sftp-password", + root_path="/dir-name", +) + +# txt_file = FAKER.txt_file(storage=SFTP_STORAGE) diff --git a/docs/_static/examples/recipes/txt_file_1.py b/docs/_static/examples/recipes/txt_file_1.py new file mode 100644 index 00000000..083ab3a7 --- /dev/null +++ b/docs/_static/examples/recipes/txt_file_1.py @@ -0,0 +1,7 @@ +from faker import Faker +from faker_file.providers.txt_file import TxtFileProvider + +FAKER = Faker() +FAKER.add_provider(TxtFileProvider) + +txt_file = FAKER.txt_file(content="Lorem ipsum") diff --git a/docs/_static/examples/recipes/zip_file_1.py b/docs/_static/examples/recipes/zip_file_1.py new file mode 100644 index 00000000..68f4345a --- /dev/null +++ b/docs/_static/examples/recipes/zip_file_1.py @@ -0,0 +1,9 @@ +from faker import Faker +from faker_file.providers.zip_file import ZipFileProvider + +FAKER = Faker() +FAKER.add_provider(ZipFileProvider) + +zip_file = FAKER.zip_file( + options={"create_inner_file_args": {"content": "Lorem ipsum"}} +) diff --git a/docs/_static/examples/recipes/zip_file_2.py b/docs/_static/examples/recipes/zip_file_2.py new file mode 100644 index 00000000..f3197726 --- /dev/null +++ b/docs/_static/examples/recipes/zip_file_2.py @@ -0,0 +1,19 @@ +from faker import Faker +from faker_file.providers.helpers.inner import create_inner_docx_file +from faker_file.providers.zip_file import ZipFileProvider + +FAKER = Faker() +FAKER.add_provider(ZipFileProvider) + +zip_file = FAKER.zip_file( + prefix="zzz", + options={ + "count": 3, + "create_inner_file_func": create_inner_docx_file, + "create_inner_file_args": { + "prefix": "xxx_", + "max_nb_chars": 1_024, + }, + "directory": "yyy", + }, +) diff --git a/docs/_static/examples/recipes/zip_file_3.py b/docs/_static/examples/recipes/zip_file_3.py new file mode 100644 index 00000000..bd2180d1 --- /dev/null +++ b/docs/_static/examples/recipes/zip_file_3.py @@ -0,0 +1,18 @@ +from faker import Faker +from faker_file.providers.helpers.inner import create_inner_docx_file +from faker_file.providers.zip_file import ZipFileProvider + +FAKER = Faker() +FAKER.add_provider(ZipFileProvider) + +TEMPLATE = "Hey {{name}},\n{{text}},\nBest regards\n{{name}}" + +zip_file = FAKER.zip_file( + options={ + "count": 9, + "create_inner_file_func": create_inner_docx_file, + "create_inner_file_args": { + "content": TEMPLATE, + }, + } +) diff --git a/docs/_static/examples/recipes/zip_file_4.py b/docs/_static/examples/recipes/zip_file_4.py new file mode 100644 index 00000000..2a93e313 --- /dev/null +++ b/docs/_static/examples/recipes/zip_file_4.py @@ -0,0 +1,28 @@ +from faker import Faker +from faker_file.providers.helpers.inner import ( + create_inner_docx_file, + create_inner_zip_file, +) +from faker_file.providers.zip_file import ZipFileProvider + +FAKER = Faker() +FAKER.add_provider(ZipFileProvider) + +zip_file = FAKER.zip_file( + prefix="nested_level_0_", + options={ + "create_inner_file_func": create_inner_zip_file, + "create_inner_file_args": { + "prefix": "nested_level_1_", + "options": { + "create_inner_file_func": create_inner_zip_file, + "create_inner_file_args": { + "prefix": "nested_level_2_", + "options": { + "create_inner_file_func": create_inner_docx_file, + }, + }, + }, + }, + }, +) diff --git a/docs/_static/examples/recipes/zip_file_5.py b/docs/_static/examples/recipes/zip_file_5.py new file mode 100644 index 00000000..898268ac --- /dev/null +++ b/docs/_static/examples/recipes/zip_file_5.py @@ -0,0 +1,32 @@ +from faker import Faker +from faker_file.providers.helpers.inner import ( + create_inner_docx_file, + create_inner_epub_file, + create_inner_txt_file, + fuzzy_choice_create_inner_file, +) +from faker_file.providers.zip_file import ZipFileProvider +from faker_file.storages.filesystem import FileSystemStorage + +FAKER = Faker() +FAKER.add_provider(ZipFileProvider) + +STORAGE = FileSystemStorage() + +kwargs = {"storage": STORAGE, "generator": FAKER} + +zip_file = FAKER.zip_file( + prefix="zzz_archive_", + options={ + "count": 50, + "create_inner_file_func": fuzzy_choice_create_inner_file, + "create_inner_file_args": { + "func_choices": [ + (create_inner_docx_file, kwargs), + (create_inner_epub_file, kwargs), + (create_inner_txt_file, kwargs), + ], + }, + "directory": "zzz", + }, +) diff --git a/docs/_static/examples/recipes/zip_file_6.py b/docs/_static/examples/recipes/zip_file_6.py new file mode 100644 index 00000000..027f8ad5 --- /dev/null +++ b/docs/_static/examples/recipes/zip_file_6.py @@ -0,0 +1,24 @@ +from faker import Faker +from faker_file.providers.helpers.inner import ( + create_inner_docx_file, + create_inner_xml_file, + list_create_inner_file, +) +from faker_file.providers.zip_file import ZipFileProvider + +FAKER = Faker() +FAKER.add_provider(ZipFileProvider) + +zip_file = FAKER.zip_file( + basename="alice-looking-through-the-glass", + options={ + "create_inner_file_func": list_create_inner_file, + "create_inner_file_args": { + "func_list": [ + (create_inner_docx_file, {"basename": "doc"}), + (create_inner_xml_file, {"basename": "doc_metadata"}), + (create_inner_xml_file, {"basename": "doc_isbn"}), + ], + }, + }, +) diff --git a/docs/_static/js/inline_code.js b/docs/_static/js/inline_code.js new file mode 100644 index 00000000..6cef6a9e --- /dev/null +++ b/docs/_static/js/inline_code.js @@ -0,0 +1,84 @@ +/** + * Sphinx `:download:` directive integration with PrismJS. + * + * Install the snippet by adding it to the sphinx conf.py configuration + * as shown below: + * + * prismjs_base = "//cdnjs.cloudflare.com/ajax/libs/prism/1.29.0" + * + * html_css_files = [ + * f"{prismjs_base}/themes/prism.min.css", + * f"{prismjs_base}/plugins/toolbar/prism-toolbar.min.css", + * f"{prismjs_base}/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.css", + * "css/prism_sphinx_rtd_theme.css", + * ] + * + * html_js_files = [ + * f"{prismjs_base}/prism.min.js", + * f"{prismjs_base}/plugins/autoloader/prism-autoloader.min.js", + * f"{prismjs_base}/plugins/toolbar/prism-toolbar.min.js", + * f"{prismjs_base}/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js", + * "js/inline_code.js", + * ] + * + * @author Artur Barseghyan (https://github.com/barseghyanartur) + * @version 1.0 + */ + +$(document).ready(function() { + // Find all download links by their class + $("a.reference.download.internal").each(function(index) { + // Create a unique id for the additional content div + let contentID = 'additional-content-' + index; + + // Get the file extension and set language class + let fileExtension = $(this).attr('href').split('.').pop(); + let langClass = fileExtension === 'py' ? 'language-python' : + fileExtension === 'js' ? 'language-javascript' : + 'language-plaintext'; + + // Append a new div for the additional content after the link + $(this).after( + `` + ); + + // Attach a click event to the download link + $(this).on('click', function(event) { + event.preventDefault(); // Stop the link from being followed + let additionalContentDiv = $(`#${contentID}`); + let additionalContent = $(`#${contentID} code`); + + if (additionalContentDiv.is(":visible")) { + additionalContentDiv.hide(); + } else { + // Check if content has been fetched + if (!additionalContentDiv.hasClass('fetched')) { + let retries = 3; + let url = $(this).attr('href'); + function fetchContent() { + // Fetch the content of the file and display it + $.ajax({ + url: url, + dataType: 'text', + success: function (data) { + additionalContent.text(data); + Prism.highlightElement(additionalContent[0]); + additionalContentDiv.show(); + // Add fetched class + additionalContentDiv.addClass('fetched'); + }, + error: function () { + additionalContent.text('Error fetching content.'); + additionalContentDiv.show(); + } + }); + } + fetchContent(); + } else { + // Content has been fetched, just show it + additionalContentDiv.show(); + } + } + }); + }); +}); diff --git a/docs/conf.py b/docs/conf.py index 6883bb33..3675b77b 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -196,6 +196,22 @@ # Output file base name for HTML help builder. htmlhelp_basename = "faker-filedoc" +prismjs_base = "//cdnjs.cloudflare.com/ajax/libs/prism/1.29.0" + +html_css_files = [ + f"{prismjs_base}/themes/prism.min.css", + f"{prismjs_base}/plugins/toolbar/prism-toolbar.min.css", + f"{prismjs_base}/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.css", + "css/prism_sphinx_rtd_theme.css", +] + +html_js_files = [ + f"{prismjs_base}/prism.min.js", + f"{prismjs_base}/plugins/autoloader/prism-autoloader.min.js", + f"{prismjs_base}/plugins/toolbar/prism-toolbar.min.js", + f"{prismjs_base}/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js", + "js/inline_code.js", +] # -- Options for LaTeX output -------------------------------------------------- diff --git a/docs/conf.py.distrib b/docs/conf.py.distrib index 6883bb33..3675b77b 100755 --- a/docs/conf.py.distrib +++ b/docs/conf.py.distrib @@ -196,6 +196,22 @@ html_static_path = ["_static"] # Output file base name for HTML help builder. htmlhelp_basename = "faker-filedoc" +prismjs_base = "//cdnjs.cloudflare.com/ajax/libs/prism/1.29.0" + +html_css_files = [ + f"{prismjs_base}/themes/prism.min.css", + f"{prismjs_base}/plugins/toolbar/prism-toolbar.min.css", + f"{prismjs_base}/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.css", + "css/prism_sphinx_rtd_theme.css", +] + +html_js_files = [ + f"{prismjs_base}/prism.min.js", + f"{prismjs_base}/plugins/autoloader/prism-autoloader.min.js", + f"{prismjs_base}/plugins/toolbar/prism-toolbar.min.js", + f"{prismjs_base}/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js", + "js/inline_code.js", +] # -- Options for LaTeX output -------------------------------------------------- diff --git a/docs/creating_docx.rst b/docs/creating_docx.rst index 8a3c07c7..1504f8ea 100644 --- a/docs/creating_docx.rst +++ b/docs/creating_docx.rst @@ -3,18 +3,11 @@ Creating DOCX See the following full functional snippet for generating DOCX. -.. code-block:: python - :name: test_creating_docx +.. literalinclude:: _static/examples/creating_docx/docx_1.py + :language: python - # Imports - from faker import Faker - from faker_file.providers.docx_file import DocxFileProvider - - FAKER = Faker() # Initialize Faker - FAKER.add_provider(DocxFileProvider) # Register DocxFileProvider - - # Generate DOCX file - docx_file = FAKER.docx_file() +*See the full example* +:download:`here <_static/examples/creating_docx/docx_1.py>` The generated DOCX will have 10,000 characters of text, which is about 5 pages. @@ -24,19 +17,29 @@ If you want DOCX with more pages, you could either: - Set value of ``wrap_chars_after`` to 80 characters to force longer pages. - Insert manual page breaks and other content. +---- + See the example below for ``max_nb_chars`` tweak: -.. code-block:: python +.. literalinclude:: _static/examples/creating_docx/docx_2.py + :language: python + :lines: 8- - # Generate DOCX file of 20,000 characters - docx_file = FAKER.docx_file(max_nb_chars=20_000) +*See the full example* +:download:`here <_static/examples/creating_docx/docx_2.py>` + +---- See the example below for ``wrap_chars_after`` tweak: -.. code-block:: python +.. literalinclude:: _static/examples/creating_docx/docx_3.py + :language: python + :lines: 8- + +*See the full example* +:download:`here <_static/examples/creating_docx/docx_3.py>` - # Generate DOCX file, wrapping each line after 80 characters - docx_file = FAKER.docx_file(wrap_chars_after=80) +---- As mentioned above, it's possible to diversify the generated context with images, paragraphs, tables, manual text break and pretty much everything that @@ -45,46 +48,9 @@ paragraphs, tables and manual text breaks are supported out of the box. In order to customise the blocks DOCX file is built from, the ``DynamicTemplate`` class is used. See the example below for usage examples: -.. code-block:: python - - # Additional imports - from faker_file.base import DynamicTemplate - from faker_file.contrib.docx_file import ( - add_page_break, - add_paragraph, - add_picture, - add_table, - ) - - # Create a DOCX file with paragraph, picture, table and manual page breaks - # in between the mentioned elements. The ``DynamicTemplate`` simply - # accepts a list of callables (such as ``add_paragraph``, - # ``add_page_break``) and dictionary to be later on fed to the callables - # as keyword arguments for customising the default values. - docx_file = FAKER.docx_file( - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_page_break, {}), # Add page break - (add_picture, {}), # Add picture - (add_page_break, {}), # Add page break - (add_table, {}), # Add table - (add_page_break, {}), # Add page break - ] - ) - ) - - # You could make the list as long as you like or simply multiply for - # easier repetition as follows: - docx_file = FAKER.docx_file( - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_page_break, {}), # Add page break - (add_picture, {}), # Add picture - (add_page_break, {}), # Add page break - (add_table, {}), # Add table - (add_page_break, {}), # Add page break - ] * 100 # Will repeat your config 100 times - ) - ) +.. literalinclude:: _static/examples/creating_docx/docx_4.py + :language: python + :lines: 3-9, 14- + +*See the full example* +:download:`here <_static/examples/creating_docx/docx_4.py>` diff --git a/docs/creating_images.rst b/docs/creating_images.rst index a3a958eb..d1f70ba9 100644 --- a/docs/creating_images.rst +++ b/docs/creating_images.rst @@ -62,44 +62,41 @@ or unicode characters. See the following full functional snippet for generating images using `imgkit`_. -.. code-block:: python - :name: test_building_images_using_imgkit +.. literalinclude:: _static/examples/creating_images/imgkit_1.py + :language: python - from faker import Faker - from faker_file.providers.png_file import PngFileProvider - from faker_file.providers.image.imgkit_generator import ( - ImgkitImageGenerator, - ) - - FAKER = Faker() # Initialize Faker - FAKER.add_provider(PngFileProvider) # Register PngFileProvider - - # Generate PNG file using `imgkit` - pdf_file = FAKER.png_file(image_generator_cls=ImgkitImageGenerator) +*See the full example* +:download:`here <_static/examples/creating_images/imgkit_1.py>` The generated PNG image will have 10,000 characters of text. The generated image will be as wide as needed to fit those 10,000 characters, but newlines are respected. +---- + If you want image to be less wide, set value of ``wrap_chars_after`` to 80 characters (or any other number that fits your needs). See the example below: -.. code-block:: python +.. literalinclude:: _static/examples/creating_images/imgkit_2.py + :language: python + :lines: 8- + +*See the full example* +:download:`here <_static/examples/creating_images/imgkit_2.py>` - # Generate an image file, wrapping each line after 80 characters - png_file = FAKER.png_file( - image_generator_cls=ImgkitImageGenerator, wrap_chars_after=80 - ) +---- To have a longer text, increase the value of ``max_nb_chars`` accordingly. See the example below: -.. code-block:: python +.. literalinclude:: _static/examples/creating_images/imgkit_3.py + :language: python + :lines: 8- - # Generate an image file of 20,000 characters - png_file = FAKER.png_file( - image_generator_cls=ImgkitImageGenerator, max_nb_chars=20_000 - ) +*See the full example* +:download:`here <_static/examples/creating_images/imgkit_3.py>` + +---- As mentioned above, it's possible to diversify the generated context with images, paragraphs, tables and pretty much everything that you could think of, @@ -108,44 +105,12 @@ the box. In order to customise the blocks image file is built from, the ``DynamicTemplate`` class is used. See the example below for usage examples: -.. code-block:: python - - # Additional imports - from faker_file.base import DynamicTemplate - from faker_file.contrib.image.imgkit_snippets import ( - add_paragraph, - add_picture, - add_table, - ) - - # Create an image file with a paragraph, a picture and a table. - # The ``DynamicTemplate`` simply accepts a list of callables (such - # as ``add_paragraph``, ``add_picture``) and dictionary to be later on - # fed to the callables as keyword arguments for customising the default - # values. - png_file = FAKER.png_file( - image_generator_cls=ImgkitImageGenerator, - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_picture, {}), # Add picture - (add_table, {}), # Add table - ] - ) - ) - - # You could make the list as long as you like or simply multiply for - # easier repetition as follows: - png_file = FAKER.png_file( - image_generator_cls=ImgkitImageGenerator, - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_picture, {}), # Add picture - (add_table, {}), # Add table - ] * 100 # Will repeat your config 100 times - ) - ) +.. literalinclude:: _static/examples/creating_images/imgkit_4.py + :language: python + :lines: 2-7, 13- + +*See the full example* +:download:`here <_static/examples/creating_images/imgkit_4.py>` Building mixed-content images using `WeasyPrint`_ ------------------------------------------------- @@ -155,20 +120,14 @@ good alternative to. See the following snippet for generating images using `WeasyPrint`_. -.. code-block:: python - :name: test_building_images_using_weasyprint +.. literalinclude:: _static/examples/creating_images/weasyprint_1.py + :language: python + :lines: 2-4, 9- - from faker import Faker - from faker_file.providers.png_file import PngFileProvider - from faker_file.providers.image.weasyprint_generator import ( - WeasyPrintImageGenerator, - ) +*See the full example* +:download:`here <_static/examples/creating_images/weasyprint_1.py>` - FAKER = Faker() # Initialize Faker - FAKER.add_provider(PngFileProvider) # Register provider - - # Generate image file using `WeasyPrint` - png_file = FAKER.png_file(image_generator_cls=WeasyPrintImageGenerator) +---- All examples shown for `imgkit`_ apply for `WeasyPrint`_ generator, however when building images files from blocks (paragraphs, images and tables), the @@ -180,120 +139,47 @@ think of, although currently only images, paragraphs and tables are supported. In order to customise the blocks image file is built from, the ``DynamicTemplate`` class is used. See the example below for usage examples: -.. code-block:: python - - # Additional imports - from faker_file.base import DynamicTemplate - from faker_file.contrib.image.weasyprint_snippets import ( - add_paragraph, - add_picture, - add_table, - ) - - # Create an image file with paragraph, picture and table. - # The ``DynamicTemplate`` simply accepts a list of callables (such - # as ``add_paragraph``, ``add_picture``) and dictionary to be later on - # fed to the callables as keyword arguments for customising the default - # values. - png_file = FAKER.png_file( - image_generator_cls=WeasyPrintImageGenerator, - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_picture, {}), # Add picture - (add_table, {}), # Add table - ] - ) - ) - - # You could make the list as long as you like or simply multiply for - # easier repetition as follows: - png_file = FAKER.png_file( - image_generator_cls=WeasyPrintImageGenerator, - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_picture, {}), # Add picture - (add_table, {}), # Add table - ] * 100 - ) - ) +.. literalinclude:: _static/examples/creating_images/weasyprint_2.py + :language: python + :lines: 3-7, 15- + +*See the full example* +:download:`here <_static/examples/creating_images/weasyprint_2.py>` Building mixed-content images using `Pillow`_ --------------------------------------------- Usage example: -.. code-block:: python - :name: test_building_images_using_pillow +.. literalinclude:: _static/examples/creating_images/pillow_1.py + :language: python + :lines: 2, 7- - from faker import Faker - from faker_file.providers.png_file import PngFileProvider - from faker_file.providers.image.pil_generator import PilImageGenerator +*See the full example* +:download:`here <_static/examples/creating_images/pillow_1.py>` - FAKER = Faker() - FAKER.add_provider(PngFileProvider) - - png_file = FAKER.png_file(image_generator_cls=PilImageGenerator) +---- With options: -.. code-block:: python - - png_file = FAKER.png_file( - image_generator_cls=PilImageGenerator, - image_generator_kwargs={ - "encoding": "utf8", - "font_size": 14, - "page_width": 800, - "page_height": 1200, - "line_height": 16, - "spacing": 5, - }, - wrap_chars_after=100, - ) +.. literalinclude:: _static/examples/creating_images/pillow_2.py + :language: python + :lines: 8- + +*See the full example* +:download:`here <_static/examples/creating_images/pillow_2.py>` + +---- All examples shown for `imgkit`_ and `WeasyPrint`_ apply to `Pillow`_ generator, however when building image files from blocks (paragraphs, images and tables), the imports shall be adjusted. See the example below: -.. code-block:: python - - # Additional imports - from faker_file.base import DynamicTemplate - from faker_file.contrib.png_file.pil_snippets import ( - add_paragraph, - add_picture, - add_table, - ) - - # Create an image file with paragraph, picture and table. - # The ``DynamicTemplate`` simply accepts a list of callables (such as - # ``add_paragraph``, ``add_picture``) and dictionary to be later on fed - # to the callables as keyword arguments for customising the default - # values. - png_file = FAKER.png_file( - image_generator_cls=PilImageGenerator, - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_picture, {}), # Add picture - (add_table, {}), # Add table - ] - ) - ) - - # You could make the list as long as you like or simply multiply for - # easier repetition as follows: - png_file = FAKER.png_file( - image_generator_cls=PilImageGenerator, - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_picture, {}), # Add picture - (add_table, {}), # Add table - ] * 100 - ) - ) +.. literalinclude:: _static/examples/creating_images/pillow_3.py + :language: python + :lines: 3-7, 13- + +*See the full example* +:download:`here <_static/examples/creating_images/pillow_3.py>` Creating graphics-only images using `Pillow`_ --------------------------------------------- @@ -302,98 +188,34 @@ files would not contain text, so don't use it when you need text based content. However, sometimes you just need a valid image file, without caring much about the content. That's where graphic image providers comes to rescue: -.. code-block:: python - :name: test_building_images_with_graphics_using_pillow +.. literalinclude:: _static/examples/creating_images/pillow_4.py + :language: python + :lines: 2-3, 5- - from faker import Faker - from faker_file.providers.png_file import GraphicPngFileProvider +*See the full example* +:download:`here <_static/examples/creating_images/pillow_4.py>` - FAKER = Faker() # Initialize Faker - FAKER.add_provider(GraphicPngFileProvider) # Register provider +The generated file will contain a random graphic (consisting of lines and +shapes of different colours). - png_file = FAKER.graphic_png_file() +---- -The generated file will contain a random graphic (consisting of lines and -shapes of different colours). One of the most useful arguments supported is -``size``. +One of the most useful arguments supported is ``size``. -.. code-block:: python +.. literalinclude:: _static/examples/creating_images/pillow_5.py + :language: python + :lines: 7- - png_file = FAKER.graphic_png_file( - size=(800, 800), - ) +*See the full example* +:download:`here <_static/examples/creating_images/pillow_5.py>` Augment existing images ----------------------- Augment the input image with a series of random augmentation methods. -.. code-block:: python - :name: test_augment_images_using_pillow - - from faker import Faker - from faker_file.base import DynamicTemplate - from faker_file.contrib.pdf_file.pil_snippets import * - from faker_file.providers.image.augment import ( - flip_horizontal, - flip_vertical, - decrease_contrast, - add_brightness, - resize_width, - resize_height, - ) - from faker_file.providers.image.pil_generator import PilImageGenerator - from faker_file.providers.png_file import ( - GraphicPngFileProvider, - PngFileProvider, - ) - from faker_file.providers.augment_image_from_path import ( - AugmentImageFromPathProvider - ) - from faker_file.providers.augment_random_image_from_dir import ( - AugmentRandomImageFromDirProvider - ) - - FAKER = Faker() - FAKER.add_provider(PngFileProvider) - FAKER.add_provider(GraphicPngFileProvider) - FAKER.add_provider(AugmentImageFromPathProvider) - FAKER.add_provider(AugmentRandomImageFromDirProvider) - - # Create a couple of graphic images to augment later on. - FAKER.graphic_png_file(basename="01") # One named 01.png - # And 5 more with random names. - for __ in range(5): - FAKER.graphic_png_file() - - # We could have also assumed that images directory exists and contains - # image files, amount which 01.png. Augmentations will be applied - # sequentially, one by one until all fulfilled. If you wish to apply only - # a random number of augmentations, but not all, pass the `num_steps` - # argument, with value less than the number of `augmentations` provided. - augmented_image_file = FAKER.augment_image_from_path( - path="/tmp/tmp/01.png", - augmentations=[ - (flip_horizontal, {}), - (flip_vertical, {}), - (decrease_contrast, {}), - (add_brightness, {}), - (resize_width, {"lower": 0.9, "upper": 1.1}), - (resize_height, {"lower": 0.9, "upper": 1.1}), - ], - prefix="augmented_image_01_", - # num_steps=3, - ) - - augmented_random_image_file = FAKER.augment_random_image_from_dir( - source_dir_path="/tmp/tmp/", - augmentations=[ - (flip_horizontal, {}), - (flip_vertical, {}), - (decrease_contrast, {}), - (add_brightness, {}), - (resize_width, {"lower": 0.9, "upper": 1.1}), - (resize_height, {"lower": 0.9, "upper": 1.1}), - ], - prefix="augmented_random_image_", - # num_steps=3, - ) +.. literalinclude:: _static/examples/creating_images/augment_1.py + :language: python + :lines: 2-15, 17, 19-20, 28- + +*See the full example* +:download:`here <_static/examples/creating_images/augment_1.py>` diff --git a/docs/creating_odt.rst b/docs/creating_odt.rst index c47b159c..3857bd93 100644 --- a/docs/creating_odt.rst +++ b/docs/creating_odt.rst @@ -3,18 +3,11 @@ Creating ODT See the following full functional snippet for generating ODT. -.. code-block:: python - :name: test_creating_odt +.. literalinclude:: _static/examples/creating_odt/odt_1.py + :language: python - # Imports - from faker import Faker - from faker_file.providers.odt_file import OdtFileProvider - - FAKER = Faker() # Initialize Faker - FAKER.add_provider(OdtFileProvider) # Register OdtFileProvider - - # Generate ODT file - odt_file = FAKER.odt_file() +*See the full example* +:download:`here <_static/examples/creating_odt/odt_1.py>` The generated ODT will have 10,000 characters of text, which is about 5 pages. @@ -24,19 +17,29 @@ If you want ODT with more pages, you could either: - Set value of ``wrap_chars_after`` to 80 characters to force longer pages. - Insert manual page breaks and other content. +---- + See the example below for ``max_nb_chars`` tweak: -.. code-block:: python +.. literalinclude:: _static/examples/creating_odt/odt_2.py + :language: python + :lines: 8- - # Generate ODT file of 20,000 characters - odt_file = FAKER.odt_file(max_nb_chars=20_000) +*See the full example* +:download:`here <_static/examples/creating_odt/odt_2.py>` + +---- See the example below for ``wrap_chars_after`` tweak: -.. code-block:: python +.. literalinclude:: _static/examples/creating_odt/odt_3.py + :language: python + :lines: 8- + +*See the full example* +:download:`here <_static/examples/creating_odt/odt_3.py>` - # Generate ODT file, wrapping each line after 80 characters - odt_file = FAKER.odt_file(wrap_chars_after=80) +---- As mentioned above, it's possible to diversify the generated context with images, paragraphs, tables, manual text break and pretty much everything that @@ -45,46 +48,9 @@ paragraphs, tables and manual text breaks are supported out of the box. In order to customise the blocks ODT file is built from, the ``DynamicTemplate`` class is used. See the example below for usage examples: -.. code-block:: python - - # Additional imports - from faker_file.base import DynamicTemplate - from faker_file.contrib.odt_file import ( - add_page_break, - add_paragraph, - add_picture, - add_table, - ) - - # Create a ODT file with paragraph, picture, table and manual page breaks - # in between the mentioned elements. The ``DynamicTemplate`` simply - # accepts a list of callables (such as ``add_paragraph``, - # ``add_page_break``) and dictionary to be later on fed to the callables - # as keyword arguments for customising the default values. - odt_file = FAKER.odt_file( - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_page_break, {}), # Add page break - (add_picture, {}), # Add picture - (add_page_break, {}), # Add page break - (add_table, {}), # Add table - (add_page_break, {}), # Add page break - ] - ) - ) - - # You could make the list as long as you like or simply multiply for - # easier repetition as follows: - odt_file = FAKER.odt_file( - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_page_break, {}), # Add page break - (add_picture, {}), # Add picture - (add_page_break, {}), # Add page break - (add_table, {}), # Add table - (add_page_break, {}), # Add page break - ] * 100 # Will repeat your config 100 times - ) - ) +.. literalinclude:: _static/examples/creating_odt/odt_4.py + :language: python + :lines: 3-9, 14- + +*See the full example* +:download:`here <_static/examples/creating_odt/odt_4.py>` diff --git a/docs/creating_pdf.rst b/docs/creating_pdf.rst index 07176466..8fb08d97 100644 --- a/docs/creating_pdf.rst +++ b/docs/creating_pdf.rst @@ -34,21 +34,11 @@ or unicode characters. See the following full functional snippet for generating PDF using `pdfkit`_. -.. code-block:: python - :name: test_building_pdf_using_pdfkit +.. literalinclude:: _static/examples/creating_pdf/pdfkit_1.py + :language: python - # Imports - from faker import Faker - from faker_file.providers.pdf_file import PdfFileProvider - from faker_file.providers.pdf_file.generators.pdfkit_generator import ( - PdfkitPdfGenerator, - ) - - FAKER = Faker() # Initialize Faker - FAKER.add_provider(PdfFileProvider) # Register PdfFileProvider - - # Generate PDF file using `pdfkit` - pdf_file = FAKER.pdf_file(pdf_generator_cls=PdfkitPdfGenerator) +*See the full example* +:download:`here <_static/examples/creating_pdf/pdfkit_1.py>` The generated PDF will have 10,000 characters of text, which is about 2 pages. @@ -58,23 +48,29 @@ If you want PDF with more pages, you could either: - Set value of ``wrap_chars_after`` to 80 characters to force longer pages. - Insert manual page breaks and other content. +---- + See the example below for ``max_nb_chars`` tweak: -.. code-block:: python +.. literalinclude:: _static/examples/creating_pdf/pdfkit_2.py + :language: python + :lines: 11- + +*See the full example* +:download:`here <_static/examples/creating_pdf/pdfkit_2.py>` - # Generate PDF file of 20,000 characters - pdf_file = FAKER.pdf_file( - pdf_generator_cls=PdfkitPdfGenerator, max_nb_chars=20_000 - ) +---- See the example below for ``wrap_chars_after`` tweak: -.. code-block:: python +.. literalinclude:: _static/examples/creating_pdf/pdfkit_3.py + :language: python + :lines: 11- - # Generate PDF file, wrapping each line after 80 characters - pdf_file = FAKER.pdf_file( - pdf_generator_cls=PdfkitPdfGenerator, wrap_chars_after=80 - ) +*See the full example* +:download:`here <_static/examples/creating_pdf/pdfkit_3.py>` + +---- As mentioned above, it's possible to diversify the generated context with images, paragraphs, tables, manual text break and pretty much everything that @@ -83,51 +79,12 @@ paragraphs, tables and manual text breaks are supported out of the box. In order to customise the blocks PDF file is built from, the ``DynamicTemplate`` class is used. See the example below for usage examples: -.. code-block:: python - - # Additional imports - from faker_file.base import DynamicTemplate - from faker_file.contrib.pdf_file.pdfkit_snippets import ( - add_page_break, - add_paragraph, - add_picture, - add_table, - ) - - # Create a PDF file with paragraph, picture, table and manual page breaks - # in between the mentioned elements. The ``DynamicTemplate`` simply - # accepts a list of callables (such as ``add_paragraph``, - # ``add_page_break``) and dictionary to be later on fed to the callables - # as keyword arguments for customising the default values. - pdf_file = FAKER.pdf_file( - pdf_generator_cls=PdfkitPdfGenerator, - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_page_break, {}), # Add page break - (add_picture, {}), # Add picture - (add_page_break, {}), # Add page break - (add_table, {}), # Add table - (add_page_break, {}), # Add page break - ] - ) - ) - - # You could make the list as long as you like or simply multiply for - # easier repetition as follows: - pdf_file = FAKER.pdf_file( - pdf_generator_cls=PdfkitPdfGenerator, - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_page_break, {}), # Add page break - (add_picture, {}), # Add picture - (add_page_break, {}), # Add page break - (add_table, {}), # Add table - (add_page_break, {}), # Add page break - ] * 100 # Will repeat your config 100 times - ) - ) +.. literalinclude:: _static/examples/creating_pdf/pdfkit_4.py + :language: python + :lines: 3-9, 17- + +*See the full example* +:download:`here <_static/examples/creating_pdf/pdfkit_4.py>` Building PDFs with text using `reportlab`_ ------------------------------------------ @@ -137,25 +94,18 @@ encoding when generating unicode text. See the following full functional snippet for generating PDF using `reportlab`_. -.. code-block:: python - :name: test_building_pdf_using_reportlab - - # Imports - from faker import Faker - from faker_file.providers.pdf_file import PdfFileProvider - from faker_file.providers.pdf_file.generators.reportlab_generator import ( - ReportlabPdfGenerator, - ) +.. literalinclude:: _static/examples/creating_pdf/reportlab_1.py + :language: python + :lines: 4-7, 11- - FAKER = Faker() # Initialize Faker - FAKER.add_provider(PdfFileProvider) # Register provider +*See the full example* +:download:`here <_static/examples/creating_pdf/reportlab_1.py>` - # Generate PDF file using `reportlab` - pdf_file = FAKER.pdf_file(pdf_generator_cls=ReportlabPdfGenerator) +---- All examples shown for `pdfkit`_ apply for `reportlab`_ generator, however when building PDF files from blocks (paragraphs, images, tables and page -breaks), the imports shall be adjusted: +breaks), the imports shall be adjusted. As mentioned above, it's possible to diversify the generated context with images, paragraphs, tables, manual text break and pretty much everything that @@ -164,90 +114,40 @@ paragraphs, tables and manual text breaks are supported. In order to customise the blocks PDF file is built from, the ``DynamicTemplate`` class is used. See the example below for usage examples: -.. code-block:: python - - # Additional imports - from faker_file.base import DynamicTemplate - from faker_file.contrib.pdf_file.reportlab_snippets import ( - add_page_break, - add_paragraph, - add_picture, - add_table, - ) - - # Create a PDF file with paragraph, picture, table and manual page breaks - # in between the mentioned elements. The ``DynamicTemplate`` simply - # accepts a list of callables (such as ``add_paragraph``, - # ``add_page_break``) and dictionary to be later on fed to the callables - # as keyword arguments for customising the default values. - pdf_file = FAKER.pdf_file( - pdf_generator_cls=ReportlabPdfGenerator, - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_page_break, {}), # Add page break - (add_picture, {}), # Add picture - (add_page_break, {}), # Add page break - (add_table, {}), # Add table - (add_page_break, {}), # Add page break - ] - ) - ) - - # You could make the list as long as you like or simply multiply for - # easier repetition as follows: - pdf_file = FAKER.pdf_file( - pdf_generator_cls=ReportlabPdfGenerator, - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_page_break, {}), # Add page break - (add_picture, {}), # Add picture - (add_page_break, {}), # Add page break - (add_table, {}), # Add table - (add_page_break, {}), # Add page break - ] * 100 - ) - ) +.. literalinclude:: _static/examples/creating_pdf/reportlab_2.py + :language: python + :lines: 4-9, 17- + +*See the full example* +:download:`here <_static/examples/creating_pdf/reportlab_2.py>` Building PDFs with text using `Pillow`_ --------------------------------------- Usage example: -.. code-block:: python - :name: test_building_pdfs_using_pillow - - from faker import Faker - from faker_file.providers.pdf_file import PdfFileProvider - from faker_file.providers.pdf_file.generators.pil_generator import ( - PilPdfGenerator - ) +.. literalinclude:: _static/examples/creating_pdf/pillow_1.py + :language: python + :lines: 3-6, 10- - FAKER = Faker() - FAKER.add_provider(PdfFileProvider) +*See the full example* +:download:`here <_static/examples/creating_pdf/pillow_1.py>` - file = FAKER.pdf_file(pdf_generator_cls=PilPdfGenerator) +---- With options: -.. code-block:: python - - file = FAKER.pdf_file( - pdf_generator_cls=PilPdfGenerator, - pdf_generator_kwargs={ - "encoding": "utf8", - "font_size": 14, - "page_width": 800, - "page_height": 1200, - "line_height": 16, - "spacing": 5, - }, - wrap_chars_after=100, - ) +.. literalinclude:: _static/examples/creating_pdf/pillow_2.py + :language: python + :lines: 10- + +*See the full example* +:download:`here <_static/examples/creating_pdf/pillow_2.py>` + +---- All examples shown for `pdfkit`_ and `reportlab`_ apply to `Pillow`_ generator, however when building PDF files from blocks (paragraphs, images, tables and page -breaks), the imports shall be adjusted: +breaks), the imports shall be adjusted. As mentioned above, it's possible to diversify the generated context with images, paragraphs, tables, manual text break and pretty much everything that @@ -256,51 +156,12 @@ paragraphs, tables and manual text breaks are supported. In order to customise the blocks PDF file is built from, the ``DynamicTemplate`` class is used. See the example below for usage examples: -.. code-block:: python - - # Additional imports - from faker_file.base import DynamicTemplate - from faker_file.contrib.pdf_file.pil_snippets import ( - add_page_break, - add_paragraph, - add_picture, - add_table, - ) - - # Create a PDF file with paragraph, picture, table and manual page breaks - # in between the mentioned elements. The ``DynamicTemplate`` simply - # accepts a list of callables (such as ``add_paragraph``, - # ``add_page_break``) and dictionary to be later on fed to the callables - # as keyword arguments for customising the default values. - pdf_file = FAKER.pdf_file( - pdf_generator_cls=PilPdfGenerator, - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_page_break, {}), # Add page break - (add_picture, {}), # Add picture - (add_page_break, {}), # Add page break - (add_table, {}), # Add table - (add_page_break, {}), # Add page break - ] - ) - ) - - # You could make the list as long as you like or simply multiply for - # easier repetition as follows: - pdf_file = FAKER.pdf_file( - pdf_generator_cls=PilPdfGenerator, - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_page_break, {}), # Add page break - (add_picture, {}), # Add picture - (add_page_break, {}), # Add page break - (add_table, {}), # Add table - (add_page_break, {}), # Add page break - ] * 100 - ) - ) +.. literalinclude:: _static/examples/creating_pdf/pillow_3.py + :language: python + :lines: 3-8, 16- + +*See the full example* +:download:`here <_static/examples/creating_pdf/pillow_3.py>` Creating PDFs with graphics using `Pillow`_ ------------------------------------------- @@ -310,23 +171,23 @@ However, sometimes you just need a valid file in PDF format, without caring much about the content. That's where a GraphicPdfFileProvider comes to rescue: -.. code-block:: python - :name: test_building_pdfs_with_graphics_using_pillow +.. literalinclude:: _static/examples/creating_pdf/pillow_4.py + :language: python + :lines: 2-3, 7- - from faker import Faker - from faker_file.providers.pdf_file import GraphicPdfFileProvider +*See the full example* +:download:`here <_static/examples/creating_pdf/pillow_4.py>` - FAKER = Faker() # Initialize Faker - FAKER.add_provider(GraphicPdfFileProvider) # Register provider +The generated file will contain a random graphic (consisting of lines and +shapes of different colours). - file = FAKER.graphic_pdf_file() +---- -The generated file will contain a random graphic (consisting of lines and -shapes of different colours). One of the most useful arguments supported is -``size``. +One of the most useful arguments supported is ``size``. -.. code-block:: python +.. literalinclude:: _static/examples/creating_pdf/pillow_5.py + :language: python + :lines: 7- - file = FAKER.graphic_pdf_file( - size=(800, 800), - ) +*See the full example* +:download:`here <_static/examples/creating_pdf/pillow_5.py>` diff --git a/docs/documentation.rst b/docs/documentation.rst index 88523dcc..7466ebb1 100755 --- a/docs/documentation.rst +++ b/docs/documentation.rst @@ -8,9 +8,10 @@ Contents: .. toctree:: :maxdepth: 20 - index + readme quick_start recipes + creating_images creating_pdf creating_docx creating_odt diff --git a/docs/marytts.py b/docs/marytts.py new file mode 100644 index 00000000..095272aa --- /dev/null +++ b/docs/marytts.py @@ -0,0 +1,13 @@ +""" +Created for testing purposes to mock out imaginary MaryTTS module +that is referenced in documentation examples. +""" + + +class MaryTTS: + def __init__(self, locale: str, voice: str) -> None: + self.locale = locale + self.voice = voice + + def synth_mp3(self, content: str) -> bytes: + return bytes() diff --git a/docs/methodology.rst b/docs/methodology.rst index 4307f455..26495467 100644 --- a/docs/methodology.rst +++ b/docs/methodology.rst @@ -81,28 +81,34 @@ can be generally broken down by 2 categories: Image providers: -+------+-------------------------+------------------+-------------------------------+ -| File | Graphic | Text | Generator | -| type | | | | -+======+=========================+==================+===============================+ -| BMP | GraphicBmpFileProvider | BmpFileProvider | Pillow, WeasyPrint | -+------+-------------------------+------------------+-------------------------------+ -| GIF | GraphicGifFileProvider | GifFileProvider | Pillow, WeasyPrint | -+------+-------------------------+------------------+-------------------------------+ -| ICO | GraphicIcoFileProvider | IcoFileProvider | Pillow, Imagekit, WeasyPrint | -+------+-------------------------+------------------+-------------------------------+ -| JPEG | GraphicJpegFileProvider | JpegFileProvider | Pillow, Imagekit, WeasyPrint | -+------+-------------------------+------------------+-------------------------------+ -| PDF | GraphicPdfFileProvider | PdfFileProvider | Pillow, Imagekit, WeasyPrint | -+------+-------------------------+------------------+-------------------------------+ -| PNG | GraphicPngFileProvider | PngFileProvider | Pillow, Imagekit, WeasyPrint | -+------+-------------------------+------------------+-------------------------------+ -| SVG | (not supported) | SvgFileProvider | Imagekit | -+------+-------------------------+------------------+-------------------------------+ -| TIFF | GraphicTiffFileProvider | TiffFileProvider | Pillow, Imagekit*, WeasyPrint | -+------+-------------------------+------------------+-------------------------------+ -| WEBP | GraphicWebpFileProvider | WebpFileProvider | Pillow, Imagekit*, WeasyPrint | -+------+-------------------------+------------------+-------------------------------+ ++------+-------------------------+------------------+-------------------------+ +| File | Graphic | Text | Generator | +| type | | | | ++======+=========================+==================+=========================+ +| BMP | GraphicBmpFileProvider | BmpFileProvider | Pillow, WeasyPrint | ++------+-------------------------+------------------+-------------------------+ +| GIF | GraphicGifFileProvider | GifFileProvider | Pillow, WeasyPrint | ++------+-------------------------+------------------+-------------------------+ +| ICO | GraphicIcoFileProvider | IcoFileProvider | Pillow, Imagekit, | +| | | | WeasyPrint | ++------+-------------------------+------------------+-------------------------+ +| JPEG | GraphicJpegFileProvider | JpegFileProvider | Pillow, Imagekit, | +| | | | WeasyPrint | ++------+-------------------------+------------------+-------------------------+ +| PDF | GraphicPdfFileProvider | PdfFileProvider | Pillow, Imagekit, | +| | | | WeasyPrint | ++------+-------------------------+------------------+-------------------------+ +| PNG | GraphicPngFileProvider | PngFileProvider | Pillow, Imagekit, | +| | | | WeasyPrint | ++------+-------------------------+------------------+-------------------------+ +| SVG | (not supported) | SvgFileProvider | Imagekit | ++------+-------------------------+------------------+-------------------------+ +| TIFF | GraphicTiffFileProvider | TiffFileProvider | Pillow, Imagekit*, | +| | | | WeasyPrint | ++------+-------------------------+------------------+-------------------------+ +| WEBP | GraphicWebpFileProvider | WebpFileProvider | Pillow, Imagekit*, | +| | | | WeasyPrint | ++------+-------------------------+------------------+-------------------------+ .. note:: @@ -174,97 +180,34 @@ Create a simple DOCX file Let's imagine we need to generate a DOCX file with text 50 chars long (just for observability). -.. code-block:: python - :name: test_crate_a_simple_docx_file +.. literalinclude:: _static/examples/methodology/create_docx_file_1.py + :language: python - from faker import Faker - from faker_file.providers.docx_file import DocxFileProvider - - FAKER = Faker() - FAKER.add_provider(DocxFileProvider) - - file = FAKER.docx_file(max_nb_chars=50) - print(file) # Sample value: 'tmp/tmpgdctmfbp.docx' - print(file.data["content"]) # Sample value: 'Learn where receive social.' - print(file.data["filename"]) # Sample value: '/tmp/tmp/tmpgdctmfbp.docx' +*See the full example* +:download:`here <_static/examples/methodology/create_docx_file_1.py>` Create a more structured DOCX file ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Imagine, you need a letter sample. It contains -.. code-block:: python - - TEMPLATE = """ - {{date}} {{city}}, {{country}} - - Hello {{name}}, - - {{text}} - - Address: {{address}} - - Best regards, - - {{name}} - {{address}} - {{phone_number}} - """ - - file = FAKER.docx_file(content=TEMPLATE) +.. literalinclude:: _static/examples/methodology/create_docx_file_2.py + :language: python + :lines: 7- - print(file) # Sample value: 'tmp/tmpgdctmfbp.docx' - print(file.data["content"]) - # Sample value below: - # 2009-05-14 Pettyberg, Puerto Rico - # Hello Lauren Williams, - # - # Everyone bill I information. Put particularly note language support - # green. Game free family probably case day vote. - # Commercial especially game heart. - # - # Address: 19017 Jennifer Drives - # Jamesbury, MI 39121 - # - # Best regards, - # - # Robin Jones - # 4650 Paul Extensions - # Port Johnside, VI 78151 - # 001-704-255-3093 +*See the full example* +:download:`here <_static/examples/methodology/create_docx_file_2.py>` Create even more structured DOCX file ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Imagine, you need to generate a highly custom document with types of data, such as images, tables, manual page breaks, paragraphs, etc. -.. code-block:: python - - # Additional imports - from faker_file.base import DynamicTemplate - from faker_file.contrib.docx_file import ( - add_page_break, - add_paragraph, - add_picture, - add_table, - ) - - # Create a DOCX file with paragraph, picture, table and manual page breaks - # in between the mentioned elements. The ``DynamicTemplate`` simply - # accepts a list of callables (such as ``add_paragraph``, - # ``add_page_break``) and dictionary to be later on fed to the callables - # as keyword arguments for customising the default values. - file = FAKER.docx_file( - content=DynamicTemplate( - [ - (add_paragraph, {}), # Add paragraph - (add_page_break, {}), # Add page break - (add_picture, {}), # Add picture - (add_page_break, {}), # Add page break - (add_table, {}), # Add table - (add_page_break, {}), # Add page break - ] - ) - ) +.. literalinclude:: _static/examples/methodology/create_docx_file_3.py + :language: python + :lines: 2-8, 13- + +*See the full example* +:download:`here <_static/examples/methodology/create_docx_file_3.py>` .. note:: @@ -292,18 +235,12 @@ Create a file by copying it from the given path. - Prefix of the destination file would be ``zzz``. - ``path`` is the absolute path to the file to copy. -.. code-block:: python - - from faker import Faker - from faker_file.providers.file_from_path import FileFromPathProvider +.. literalinclude:: _static/examples/methodology/file_from_path_provider.py + :language: python + :lines: 3-4, 6, 11- - FAKER = Faker() - FAKER.add_provider(FileFromPathProvider) - - file = FAKER.file_from_path( - path="/path/to/file.docx", - prefix="zzz", - ) +*See the full example* +:download:`here <_static/examples/methodology/file_from_path_provider.py>` Now you don't have to copy-paste your file from one place to another. It will be done for you in a convenient way. @@ -316,27 +253,18 @@ Create a file by copying it randomly from the given directory. - Prefix of the destination file would be ``zzz``. - ``source_dir_path`` is the absolute path to the directory to pick files from. -.. code-block:: python - :name: __test_random_file_from_dir_provider - - from faker import Faker - from faker_file.providers.random_file_from_dir import ( - RandomFileFromDirProvider, - ) +.. literalinclude:: _static/examples/methodology/rand_file_from_dir_provider.py + :language: python + :lines: 3-4, 6, 12- - FAKER = Faker() - FAKER.add_provider(RandomFileFromDirProvider) - - file = FAKER.random_file_from_dir( - source_dir_path="/tmp/tmp/", - prefix="zzz", - ) +*See the full example* +:download:`here <_static/examples/methodology/rand_file_from_dir_provider.py>` Now you don't have to copy-paste your file from one place to another. It will be done for you in a convenient way. -Cleaning up files -~~~~~~~~~~~~~~~~~ +Clean up files +~~~~~~~~~~~~~~ ``FileSystemStorage`` is the default storage and by default files are stored inside a ``tmp`` directory within the system's temporary directory, which is commonly cleaned up after system restart. However, there's a mechanism of @@ -344,25 +272,33 @@ cleaning up files after the tests run. At any time, to clean up all files created by that moment, call ``clean_up`` method of the ``FileRegistry`` class instance, as shown below: -.. code-block:: python +.. literalinclude:: _static/examples/methodology/clean_up_files_1.py + :language: python - from faker_file.registry import FILE_REGISTRY # Import instance at once - FILE_REGISTRY.clean_up() +*See the full example* +:download:`here <_static/examples/methodology/clean_up_files_1.py>` Typically you would call the ``clean_up`` method in the ``tearDown``. +---- + To remove a single file, use ``remove`` method of ``FileRegistry`` instance. -.. code-block:: python +.. literalinclude:: _static/examples/methodology/clean_up_files_2.py + :language: python + :lines: 11- + +*See the full example* +:download:`here <_static/examples/methodology/clean_up_files_2.py>` - from faker_file.registry import FILE_REGISTRY # Import instance at once - FILE_REGISTRY.remove(file) # Where file is an instance of ``StringValue`` +---- If you only have a string representation of the ``StringValue``, try to search for its' correspondent ``StringValue`` instance first using ``search`` method. -.. code-block:: python +.. literalinclude:: _static/examples/methodology/clean_up_files_3.py + :language: python + :lines: 11- - file = FILE_REGISTRY.search(filename) - if file: - FILE_REGISTRY.remove(file) +*See the full example* +:download:`here <_static/examples/methodology/clean_up_files_3.py>` diff --git a/docs/prismjs.rst b/docs/prismjs.rst new file mode 100644 index 00000000..b983994a --- /dev/null +++ b/docs/prismjs.rst @@ -0,0 +1,13 @@ +.. literalinclude:: _static/examples/prismjs/sample.py + :language: python + +*See the full example* +:download:`here <_static/examples/prismjs/sample.py>` + +---- + +.. literalinclude:: _static/examples/prismjs/sample.js + :language: javascript + +*See the full example* +:download:`here <_static/examples/prismjs/sample.js>` diff --git a/docs/quick_start.rst b/docs/quick_start.rst index 552ee472..b83a4b1d 100644 --- a/docs/quick_start.rst +++ b/docs/quick_start.rst @@ -13,349 +13,57 @@ With ``Faker`` ~~~~~~~~~~~~~~ **Imports and initialization** -.. code-block:: python - :name: test_usage_with_faker_imports_and_init - - from faker import Faker - from faker_file.providers.augment_file_from_dir import AugmentFileFromDirProvider - from faker_file.providers.bin_file import BinFileProvider - from faker_file.providers.bmp_file import BmpFileProvider - from faker_file.providers.csv_file import CsvFileProvider - from faker_file.providers.docx_file import DocxFileProvider - from faker_file.providers.eml_file import EmlFileProvider - from faker_file.providers.epub_file import EpubFileProvider - from faker_file.providers.gif_file import GifFileProvider - from faker_file.providers.ico_file import GraphicIcoFileProvider, IcoFileProvider - from faker_file.providers.jpeg_file import GraphicJpegFileProvider, JpegFileProvider - from faker_file.providers.mp3_file import Mp3FileProvider - from faker_file.providers.odp_file import OdpFileProvider - from faker_file.providers.ods_file import OdsFileProvider - from faker_file.providers.odt_file import OdtFileProvider - from faker_file.providers.pdf_file import GraphicPdfFileProvider, PdfFileProvider - from faker_file.providers.png_file import GraphicPngFileProvider, PngFileProvider - from faker_file.providers.pptx_file import PptxFileProvider - from faker_file.providers.random_file_from_dir import RandomFileFromDirProvider - from faker_file.providers.rtf_file import RtfFileProvider - from faker_file.providers.svg_file import SvgFileProvider - from faker_file.providers.tar_file import TarFileProvider - from faker_file.providers.tiff_file import TiffFileProvider - from faker_file.providers.txt_file import TxtFileProvider - from faker_file.providers.webp_file import GraphicWebpFileProvider, WebpFileProvider - from faker_file.providers.xlsx_file import XlsxFileProvider - from faker_file.providers.zip_file import ZipFileProvider - - FAKER = Faker() - FAKER.add_provider(AugmentFileFromDirProvider) - FAKER.add_provider(BinFileProvider) - FAKER.add_provider(BmpFileProvider) - FAKER.add_provider(CsvFileProvider) - FAKER.add_provider(DocxFileProvider) - FAKER.add_provider(EmlFileProvider) - FAKER.add_provider(EpubFileProvider) - FAKER.add_provider(GifFileProvider) - FAKER.add_provider(GraphicIcoFileProvider) - FAKER.add_provider(GraphicJpegFileProvider) - FAKER.add_provider(GraphicPdfFileProvider) - FAKER.add_provider(GraphicPngFileProvider) - FAKER.add_provider(GraphicWebpFileProvider) - FAKER.add_provider(IcoFileProvider) - FAKER.add_provider(JpegFileProvider) - FAKER.add_provider(Mp3FileProvider) - FAKER.add_provider(OdpFileProvider) - FAKER.add_provider(OdsFileProvider) - FAKER.add_provider(OdtFileProvider) - FAKER.add_provider(PdfFileProvider) - FAKER.add_provider(PngFileProvider) - FAKER.add_provider(PptxFileProvider) - FAKER.add_provider(RandomFileFromDirProvider) - FAKER.add_provider(RtfFileProvider) - FAKER.add_provider(SvgFileProvider) - FAKER.add_provider(TarFileProvider) - FAKER.add_provider(TiffFileProvider) - FAKER.add_provider(TxtFileProvider) - FAKER.add_provider(WebpFileProvider) - FAKER.add_provider(XlsxFileProvider) - FAKER.add_provider(ZipFileProvider) +.. literalinclude:: _static/examples/quick_start/import_and_init_1.py + :language: python + :lines: 2-78 **Usage examples** -.. code-block:: python - - augmented_file = FAKER.augment_file_from_dir(source_dir_path="/path/to/source/",) - bin_file = FAKER.bin_file() - bmp_file = FAKER.bmp_file() - csv_file = FAKER.csv_file() - docx_file = FAKER.docx_file() - eml_file = FAKER.eml_file() - epub_file = FAKER.epub_file() - gif_file = FAKER.gif_file() - graphic_ico_file = FAKER.graphic_ico_file() - graphic_jpeg_file = FAKER.graphic_jpeg_file() - graphic_pdf_file = FAKER.graphic_pdf_file() - graphic_png_file = FAKER.graphic_png_file() - graphic_webp_file = FAKER.graphic_webp_file() - ico_file = FAKER.ico_file() - jpeg_file = FAKER.jpeg_file() - mp3_file = FAKER.mp3_file() - odp_file = FAKER.odp_file() - ods_file = FAKER.ods_file() - odt_file = FAKER.odt_file() - pdf_file = FAKER.pdf_file() - png_file = FAKER.png_file() - pptx_file = FAKER.pptx_file() - random_file = FAKER.random_file_from_dir(source_dir_path="/path/to/source/",) - rtf_file = FAKER.rtf_file() - svg_file = FAKER.svg_file() - tar_file = FAKER.tar_file() - tiff_file = FAKER.tiff_file() - txt_file = FAKER.txt_file() - webp_file = FAKER.webp_file() - xlsx_file = FAKER.xlsx_file() - zip_file = FAKER.zip_file() +.. literalinclude:: _static/examples/quick_start/import_and_init_1.py + :language: python + :lines: 87-121 If you just need bytes back (instead of creating the file), provide the ``raw=True`` argument (works with all provider classes and inner functions): -.. code-block:: python +.. literalinclude:: _static/examples/quick_start/import_and_init_1.py + :language: python + :lines: 124- - augmented_raw = FAKER.augment_file_from_dir( - source_dir_path="/path/to/source/", - raw=True, - ) - bin_raw = FAKER.bin_file(raw=True) - bmp_raw = FAKER.bmp_file(raw=True) - csv_raw = FAKER.csv_file(raw=True) - docx_raw = FAKER.docx_file(raw=True) - eml_raw = FAKER.eml_file(raw=True) - epub_raw = FAKER.epub_file(raw=True) - gif_raw = FAKER.gif_file(raw=True) - ico_raw = FAKER.ico_file(raw=True) - jpeg_raw = FAKER.jpeg_file(raw=True) - mp3_raw = FAKER.mp3_file(raw=True) - odp_raw = FAKER.odp_file(raw=True) - ods_raw = FAKER.ods_file(raw=True) - odt_raw = FAKER.odt_file(raw=True) - pdf_raw = FAKER.pdf_file(raw=True) - png_raw = FAKER.png_file(raw=True) - pptx_raw = FAKER.pptx_file(raw=True) - random_raw = FAKER.random_file_from_dir( - source_dir_path="/path/to/source/", - raw=True, - ) - rtf_raw = FAKER.rtf_file(raw=True) - svg_raw = FAKER.svg_file(raw=True) - tar_raw = FAKER.tar_file(raw=True) - tiff_raw = FAKER.tiff_file(raw=True) - txt_raw = FAKER.txt_file(raw=True) - webp_raw = FAKER.webp_file(raw=True) - xlsx_raw = FAKER.xlsx_file(raw=True) - zip_raw = FAKER.zip_file(raw=True) +*See the full example* +:download:`here <_static/examples/quick_start/import_and_init_1.py>` + +---- With ``factory_boy`` ~~~~~~~~~~~~~~~~~~~~ **Imports and initialization** -.. code-block:: python - :name: test_usage_with_factory_boy_imports_and_init - - from factory import Faker - - from faker_file.providers.augment_file_from_dir import AugmentFileFromDirProvider - from faker_file.providers.bin_file import BinFileProvider - from faker_file.providers.bmp_file import BmpFileProvider - from faker_file.providers.csv_file import CsvFileProvider - from faker_file.providers.docx_file import DocxFileProvider - from faker_file.providers.eml_file import EmlFileProvider - from faker_file.providers.epub_file import EpubFileProvider - from faker_file.providers.ico_file import GraphicIcoFileProvider, IcoFileProvider - from faker_file.providers.jpeg_file import GraphicJpegFileProvider, JpegFileProvider - from faker_file.providers.mp3_file import Mp3FileProvider - from faker_file.providers.odp_file import OdpFileProvider - from faker_file.providers.ods_file import OdsFileProvider - from faker_file.providers.odt_file import OdtFileProvider - from faker_file.providers.pdf_file import GraphicPdfFileProvider, PdfFileProvider - from faker_file.providers.png_file import GraphicPngFileProvider, PngFileProvider - from faker_file.providers.pptx_file import PptxFileProvider - from faker_file.providers.random_file_from_dir import RandomFileFromDirProvider - from faker_file.providers.rtf_file import RtfFileProvider - from faker_file.providers.svg_file import SvgFileProvider - from faker_file.providers.tar_file import TarFileProvider - from faker_file.providers.txt_file import TxtFileProvider - from faker_file.providers.webp_file import GraphicWebpFileProvider, WebpFileProvider - from faker_file.providers.xlsx_file import XlsxFileProvider - from faker_file.providers.zip_file import ZipFileProvider - - Faker.add_provider(AugmentFileFromDirProvider) - Faker.add_provider(BinFileProvider) - Faker.add_provider(BmpFileProvider) - Faker.add_provider(CsvFileProvider) - Faker.add_provider(DocxFileProvider) - Faker.add_provider(EmlFileProvider) - Faker.add_provider(EpubFileProvider) - Faker.add_provider(GraphicIcoFileProvider) - Faker.add_provider(GraphicJpegFileProvider) - Faker.add_provider(GraphicPdfFileProvider) - Faker.add_provider(GraphicPngFileProvider) - Faker.add_provider(GraphicWebpFileProvider) - Faker.add_provider(IcoFileProvider) - Faker.add_provider(JpegFileProvider) - Faker.add_provider(Mp3FileProvider) - Faker.add_provider(OdpFileProvider) - Faker.add_provider(OdsFileProvider) - Faker.add_provider(OdtFileProvider) - Faker.add_provider(PdfFileProvider) - Faker.add_provider(PngFileProvider) - Faker.add_provider(PptxFileProvider) - Faker.add_provider(RandomFileFromDirProvider) - Faker.add_provider(RtfFileProvider) - Faker.add_provider(SvgFileProvider) - Faker.add_provider(TarFileProvider) - Faker.add_provider(TxtFileProvider) - Faker.add_provider(WebpFileProvider) - Faker.add_provider(XlsxFileProvider) - Faker.add_provider(ZipFileProvider) - -upload/models.py -^^^^^^^^^^^^^^^^ -.. code-block:: python - - from django.db import models - - class Upload(models.Model): - """Upload model.""" - - name = models.CharField(max_length=255, unique=True) - description = models.TextField(null=True, blank=True) - - # File - file = models.FileField(null=True) - - class Meta: - verbose_name = "Upload" - verbose_name_plural = "Upload" - - def __str__(self): - return self.name - -upload/factories.py -^^^^^^^^^^^^^^^^^^^ -.. code-block:: python - - from django.conf import settings - - from factory import Faker - from factory.django import DjangoModelFactory - - from factory import Faker - - # Import all needed providers - from faker_file.providers.augment_file_from_dir import ( - AugmentFileFromDirProvider, - ) - from faker_file.providers.bin_file import BinFileProvider - from faker_file.providers.bmp_file import BmpFileProvider - from faker_file.providers.csv_file import CsvFileProvider - from faker_file.providers.docx_file import DocxFileProvider - from faker_file.providers.eml_file import EmlFileProvider - from faker_file.providers.epub_file import EpubFileProvider - from faker_file.providers.ico_file import IcoFileProvider - from faker_file.providers.jpeg_file import JpegFileProvider - from faker_file.providers.mp3_file import Mp3FileProvider - from faker_file.providers.odp_file import OdpFileProvider - from faker_file.providers.ods_file import OdsFileProvider - from faker_file.providers.odt_file import OdtFileProvider - from faker_file.providers.pdf_file import PdfFileProvider - from faker_file.providers.png_file import PngFileProvider - from faker_file.providers.pptx_file import PptxFileProvider - from faker_file.providers.random_file_from_dir import ( - RandomFileFromDirProvider, - ) - from faker_file.providers.rtf_file import RtfFileProvider - from faker_file.providers.svg_file import SvgFileProvider - from faker_file.providers.tar_file import TarFileProvider - from faker_file.providers.txt_file import TxtFileProvider - from faker_file.providers.webp_file import WebpFileProvider - from faker_file.providers.xlsx_file import XlsxFileProvider - from faker_file.providers.zip_file import ZipFileProvider - - # Import file storage, because we need to customize things in - # order for it to work with Django. - from faker_file.storages.filesystem import FileSystemStorage - - from upload.models import Upload +.. literalinclude:: _static/examples/quick_start/factory_import_and_init_1.py + :language: python + :lines: 3, 5-45, 49-78 - # Add all needed providers - Faker.add_provider(AugmentFileFromDirProvider) - Faker.add_provider(BinFileProvider) - Faker.add_provider(BmpFileProvider) - Faker.add_provider(CsvFileProvider) - Faker.add_provider(DocxFileProvider) - Faker.add_provider(EmlFileProvider) - Faker.add_provider(EpubFileProvider) - Faker.add_provider(IcoFileProvider) - Faker.add_provider(JpegFileProvider) - Faker.add_provider(Mp3FileProvider) - Faker.add_provider(OdpFileProvider) - Faker.add_provider(OdsFileProvider) - Faker.add_provider(OdtFileProvider) - Faker.add_provider(PdfFileProvider) - Faker.add_provider(PngFileProvider) - Faker.add_provider(PptxFileProvider) - Faker.add_provider(RandomFileFromDirProvider) - Faker.add_provider(RtfFileProvider) - Faker.add_provider(SvgFileProvider) - Faker.add_provider(TarFileProvider) - Faker.add_provider(TxtFileProvider) - Faker.add_provider(WebpFileProvider) - Faker.add_provider(XlsxFileProvider) - Faker.add_provider(ZipFileProvider) +**upload/models.py** - # Define a file storage. - STORAGE = FileSystemStorage( - root_path=settings.MEDIA_ROOT, - rel_path="tmp" - ) +.. literalinclude:: _static/examples/quick_start/factory_models_1.py + :language: python + :lines: 1, 3-11 - # Define the upload factory - class UploadFactory(DjangoModelFactory): - """Upload factory.""" +*See the full example* +:download:`here <_static/examples/quick_start/factory_models_1.py>` - name = Faker("text", max_nb_chars=100) - description = Faker("text", max_nb_chars=1000) +**upload/factories.py** - class Meta: - model = Upload +.. literalinclude:: _static/examples/quick_start/factory_import_and_init_1.py + :language: python + :lines: 2-4, 46-49, 80-118 - class Params: - bin_file = Trait(file=Faker("bin_file", storage=STORAGE)) - bmp_file = Trait(file=Faker("bmp_file", storage=STORAGE)) - csv_file = Trait(file=Faker("csv_file", storage=STORAGE)) - docx_file = Trait(file=Faker("docx_file", storage=STORAGE)) - eml_file = Trait(file=Faker("eml_file", storage=STORAGE)) - epub_file = Trait(file=Faker("epub_file", storage=STORAGE)) - ico_file = Trait(file=Faker("ico_file", storage=STORAGE)) - jpeg_file = Trait(file=Faker("jpeg_file", storage=STORAGE)) - mp3_file = Trait(file=Faker("mp3_file", storage=STORAGE)) - odp_file = Trait(file=Faker("odp_file", storage=STORAGE)) - ods_file = Trait(file=Faker("ods_file", storage=STORAGE)) - odt_file = Trait(file=Faker("odt_file", storage=STORAGE)) - pdf_file = Trait(file=Faker("pdf_file", storage=STORAGE)) - png_file = Trait(file=Faker("png_file", storage=STORAGE)) - pptx_file = Trait(file=Faker("pptx_file", storage=STORAGE)) - rtf_file = Trait(file=Faker("rtf_file", storage=STORAGE)) - svg_file = Trait(file=Faker("svg_file", storage=STORAGE)) - tar_file = Trait(file=Faker("tar_file", storage=STORAGE)) - txt_file = Trait(file=Faker("txt_file", storage=STORAGE)) - webp_file = Trait(file=Faker("webp_file", storage=STORAGE)) - xlsx_file = Trait(file=Faker("xlsx_file", storage=STORAGE)) - zip_file = Trait(file=Faker("zip_file", storage=STORAGE)) +**Usage example** -Usage example -^^^^^^^^^^^^^ -.. code-block:: python +.. literalinclude:: _static/examples/quick_start/factory_import_and_init_1.py + :language: python + :lines: 122- - UploadFactory(bin_file=True) # Upload with BIN file - UploadFactory(docx_file=True) # Upload with DOCX file - UploadFactory(jpeg_file=True) # Upload with JPEG file - UploadFactory(zip_file=True) # Upload with ZIP file +*See the full example* +:download:`here <_static/examples/quick_start/factory_import_and_init_1.py>` diff --git a/docs/readme.rst b/docs/readme.rst new file mode 100644 index 00000000..72a33558 --- /dev/null +++ b/docs/readme.rst @@ -0,0 +1 @@ +.. include:: ../README.rst diff --git a/docs/recipes.rst b/docs/recipes.rst index f8ec70e5..b4f96188 100644 --- a/docs/recipes.rst +++ b/docs/recipes.rst @@ -8,43 +8,19 @@ Imports and initializations ~~~~~~~~~~~~~~~~~~~~~~~~~~~ **Recommended way** -.. code-block:: python - :name: test_when_using_with_faker_imports_and_init_recommended_way - - from faker import Faker - from faker_file.providers.docx_file import DocxFileProvider - from faker_file.providers.pdf_file import PdfFileProvider - from faker_file.providers.pptx_file import PptxFileProvider - from faker_file.providers.txt_file import TxtFileProvider - from faker_file.providers.zip_file import ZipFileProvider - - FAKER = Faker() - FAKER.add_provider(DocxFileProvider) - FAKER.add_provider(PdfFileProvider) - FAKER.add_provider(PptxFileProvider) - FAKER.add_provider(TxtFileProvider) - FAKER.add_provider(ZipFileProvider) - - # Usage example - file = FAKER.txt_file(content="Lorem ipsum") +.. literalinclude:: _static/examples/recipes/imports_and_init_1.py + :language: python -**But this works too** - -.. code-block:: python - :name: test_when_using_with_faker_imports_and_init_but_this_works_too +*See the full example* +:download:`here <_static/examples/recipes/imports_and_init_1.py>` - from faker import Faker - from faker_file.providers.bin_file import BinFileProvider - from faker_file.providers.docx_file import DocxFileProvider - from faker_file.providers.pdf_file import PdfFileProvider - from faker_file.providers.pptx_file import PptxFileProvider - from faker_file.providers.txt_file import TxtFileProvider - from faker_file.providers.zip_file import ZipFileProvider +**But this works too** - FAKER = Faker() +.. literalinclude:: _static/examples/recipes/imports_and_init_2.py + :language: python - # Usage example - file = TxtFileProvider(FAKER).txt_file(content="Lorem ipsum") +*See the full example* +:download:`here <_static/examples/recipes/imports_and_init_2.py>` Throughout documentation we will be mixing these approaches. @@ -52,9 +28,12 @@ Create a TXT file with static content ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Content of the file is ``Lorem ipsum``. -.. code-block:: python +.. literalinclude:: _static/examples/recipes/txt_file_1.py + :language: python + :lines: 7- - file = TxtFileProvider(FAKER).txt_file(content="Lorem ipsum") +*See the full example* +:download:`here <_static/examples/recipes/txt_file_1.py>` Create a DOCX file with dynamically generated content ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -63,24 +42,24 @@ Create a DOCX file with dynamically generated content - Wrap lines after 80 chars. - Prefix the filename with ``zzz``. -.. code-block:: python +.. literalinclude:: _static/examples/recipes/docx_file_1.py + :language: python + :lines: 7- - file = DocxFileProvider(FAKER).docx_file( - prefix="zzz", - max_nb_chars=1_024, - wrap_chars_after=80, - ) +*See the full example* +:download:`here <_static/examples/recipes/docx_file_1.py>` Create a ZIP file consisting of TXT files with static content ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5 TXT files in the ZIP archive (default value is 5). - Content of all files is ``Lorem ipsum``. -.. code-block:: python +.. literalinclude:: _static/examples/recipes/zip_file_1.py + :language: python + :lines: 7- - file = ZipFileProvider(FAKER).zip_file( - options={"create_inner_file_args": {"content": "Lorem ipsum"}} - ) +*See the full example* +:download:`here <_static/examples/recipes/zip_file_1.py>` Create a ZIP file consisting of 3 DOCX files with dynamically generated content ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -91,42 +70,24 @@ Create a ZIP file consisting of 3 DOCX files with dynamically generated content - Prefix the filename of the archive itself with ``zzz``. - Inside the ZIP, put all files in directory ``yyy``. -.. code-block:: python - - from faker_file.providers.helpers.inner import create_inner_docx_file - file = ZipFileProvider(FAKER).zip_file( - prefix="zzz", - options={ - "count": 3, - "create_inner_file_func": create_inner_docx_file, - "create_inner_file_args": { - "prefix": "xxx_", - "max_nb_chars": 1_024, - }, - "directory": "yyy", - } - ) +.. literalinclude:: _static/examples/recipes/zip_file_2.py + :language: python + :lines: 2, 7- + +*See the full example* +:download:`here <_static/examples/recipes/zip_file_2.py>` Create a ZIP file of 9 DOCX files with content generated from template ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 9 DOCX files in the ZIP archive. - Content is generated dynamically from given template. -.. code-block:: python - - from faker_file.providers.helpers.inner import create_inner_docx_file +.. literalinclude:: _static/examples/recipes/zip_file_3.py + :language: python + :lines: 2, 7- - TEMPLATE = "Hey {{name}},\n{{text}},\nBest regards\n{{name}}" - - file = ZipFileProvider(FAKER).zip_file( - options={ - "count": 9, - "create_inner_file_func": create_inner_docx_file, - "create_inner_file_args": { - "content": TEMPLATE, - }, - } - ) +*See the full example* +:download:`here <_static/examples/recipes/zip_file_3.py>` Create a nested ZIP file ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -141,31 +102,12 @@ contain 5 DOCX files. files, prefixed with ``nested_level_2_``, which in their turn contain 5 DOCX files. -.. code-block:: python - - from faker_file.providers.helpers.inner import ( - create_inner_docx_file, - create_inner_zip_file, - ) - - file = ZipFileProvider(FAKER).zip_file( - prefix="nested_level_0_", - options={ - "create_inner_file_func": create_inner_zip_file, - "create_inner_file_args": { - "prefix": "nested_level_1_", - "options": { - "create_inner_file_func": create_inner_zip_file, - "create_inner_file_args": { - "prefix": "nested_level_2_", - "options": { - "create_inner_file_func": create_inner_docx_file, - } - }, - } - }, - } - ) +.. literalinclude:: _static/examples/recipes/zip_file_4.py + :language: python + :lines: 2-5, 10- + +*See the full example* +:download:`here <_static/examples/recipes/zip_file_4.py>` Create a ZIP file with variety of different file types within ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -174,38 +116,12 @@ Create a ZIP file with variety of different file types within - Prefix the filename of the archive itself with ``zzz_archive_``. - Inside the ZIP, put all files in directory ``zzz``. -.. code-block:: python - :name: test_create_a_zip_file_with_different_variety_of_file_types_within - - from faker import Faker - from faker_file.providers.helpers.inner import ( - create_inner_docx_file, - create_inner_epub_file, - create_inner_txt_file, - fuzzy_choice_create_inner_file, - ) - from faker_file.providers.zip_file import ZipFileProvider - from faker_file.storages.filesystem import FileSystemStorage - - FAKER = Faker() - STORAGE = FileSystemStorage() - - kwargs = {"storage": STORAGE, "generator": FAKER} - file = ZipFileProvider(FAKER).zip_file( - prefix="zzz_archive_", - options={ - "count": 50, - "create_inner_file_func": fuzzy_choice_create_inner_file, - "create_inner_file_args": { - "func_choices": [ - (create_inner_docx_file, kwargs), - (create_inner_epub_file, kwargs), - (create_inner_txt_file, kwargs), - ], - }, - "directory": "zzz", - } - ) +.. literalinclude:: _static/examples/recipes/zip_file_5.py + :language: python + :lines: 2-7, 9-10, 14- + +*See the full example* +:download:`here <_static/examples/recipes/zip_file_5.py>` Another way to create a ZIP file with variety of different file types within ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -214,35 +130,12 @@ Another way to create a ZIP file with variety of different file types within - Filename of the archive itself is ``alice-looking-through-the-glass.zip``. - Files inside the archive have fixed name (passed with ``basename`` argument). -.. code-block:: python - :name: test_create_a_zip_file_with_different_variety_of_file_types_within_2 - - from faker import Faker - from faker_file.providers.helpers.inner import ( - create_inner_docx_file, - create_inner_xml_file, - list_create_inner_file, - ) - from faker_file.providers.zip_file import ZipFileProvider - from faker_file.storages.filesystem import FileSystemStorage - - FAKER = Faker() - STORAGE = FileSystemStorage() - - kwargs = {"storage": STORAGE, "generator": FAKER} - file = ZipFileProvider(FAKER).zip_file( - basename="alice-looking-through-the-glass", - options={ - "create_inner_file_func": list_create_inner_file, - "create_inner_file_args": { - "func_list": [ - (create_inner_docx_file, {"basename": "doc"}), - (create_inner_xml_file, {"basename": "doc_metadata"}), - (create_inner_xml_file, {"basename": "doc_isbn"}), - ], - }, - } - ) +.. literalinclude:: _static/examples/recipes/zip_file_6.py + :language: python + :lines: 2-6, 11- + +*See the full example* +:download:`here <_static/examples/recipes/zip_file_6.py>` Note, that ``count`` argument (not shown in the example, but commonly accepted by inner functions) will be simply ignored here. @@ -252,17 +145,12 @@ Create an EML file consisting of TXT files with static content - 5 TXT files in the EML email (default value is 5). - Content of all files is ``Lorem ipsum``. -.. code-block:: python - :name: test_create_an_eml_file_consisting_of_txt_files_with_static_content +.. literalinclude:: _static/examples/recipes/eml_file_1.py + :language: python + :lines: 2-3, 5- - from faker import Faker - from faker_file.providers.eml_file import EmlFileProvider - - FAKER = Faker() - - file = EmlFileProvider(FAKER).eml_file( - options={"create_inner_file_args": {"content": "Lorem ipsum"}} - ) +*See the full example* +:download:`here <_static/examples/recipes/eml_file_1.py>` Create a EML file consisting of 3 DOCX files with dynamically generated content ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -272,26 +160,12 @@ Create a EML file consisting of 3 DOCX files with dynamically generated content - Prefix the filenames in email with ``xxx_``. - Prefix the filename of the email itself with ``zzz``. -.. code-block:: python - :name: test_create_an_eml_file_consisting_of_txt_files_with_dynamic_content - - from faker import Faker - from faker_file.providers.eml_file import EmlFileProvider - from faker_file.providers.helpers.inner import create_inner_docx_file - - FAKER = Faker() +.. literalinclude:: _static/examples/recipes/eml_file_2.py + :language: python + :lines: 3, 7- - file = EmlFileProvider(FAKER).eml_file( - prefix="zzz", - options={ - "count": 3, - "create_inner_file_func": create_inner_docx_file, - "create_inner_file_args": { - "prefix": "xxx_", - "max_nb_chars": 1_024, - }, - } - ) +*See the full example* +:download:`here <_static/examples/recipes/eml_file_2.py>` Create a nested EML file ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -306,36 +180,12 @@ contain 5 DOCX files. files, prefixed with ``nested_level_2_``, which in their turn contain 5 DOCX files. -.. code-block:: python - :name: test_create_a_nested_eml_file - - from faker import Faker - from faker_file.providers.eml_file import EmlFileProvider - from faker_file.providers.helpers.inner import ( - create_inner_docx_file, - create_inner_eml_file, - ) - - FAKER = Faker() - - file = EmlFileProvider(FAKER).eml_file( - prefix="nested_level_0_", - options={ - "create_inner_file_func": create_inner_eml_file, - "create_inner_file_args": { - "prefix": "nested_level_1_", - "options": { - "create_inner_file_func": create_inner_eml_file, - "create_inner_file_args": { - "prefix": "nested_level_2_", - "options": { - "create_inner_file_func": create_inner_docx_file, - } - }, - } - }, - } - ) +.. literalinclude:: _static/examples/recipes/eml_file_3.py + :language: python + :lines: 3-6, 10- + +*See the full example* +:download:`here <_static/examples/recipes/eml_file_3.py>` Create an EML file with variety of different file types within ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -343,89 +193,24 @@ Create an EML file with variety of different file types within - Content is generated dynamically. - Prefix the filename of the EML itself with ``zzz``. -.. code-block:: python - :name: test_create_an_eml_file_with_different_variety_of_file_types_within - - from faker import Faker - from faker_file.providers.helpers.inner import ( - create_inner_docx_file, - create_inner_epub_file, - create_inner_txt_file, - fuzzy_choice_create_inner_file, - ) - from faker_file.providers.eml_file import EmlFileProvider - from faker_file.storages.filesystem import FileSystemStorage - - FAKER = Faker() - STORAGE = FileSystemStorage() - - kwargs = {"storage": STORAGE, "generator": FAKER} - - file = EmlFileProvider(FAKER).eml_file( - prefix="zzz", - options={ - "count": 10, - "create_inner_file_func": fuzzy_choice_create_inner_file, - "create_inner_file_args": { - "func_choices": [ - (create_inner_docx_file, kwargs), - (create_inner_epub_file, kwargs), - (create_inner_txt_file, kwargs), - ], - }, - } - ) - -Create a TXT file with static content -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. code-block:: python - - file = FAKER.txt_file(content="Lorem ipsum dolor sit amet") - -Create a DOCX file with dynamically generated content -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Content is generated dynamically. -- Content is limited to 1024 chars. -- Wrap lines after 80 chars. -- Prefix the filename with ``zzz``. +.. literalinclude:: _static/examples/recipes/eml_file_4.py + :language: python + :lines: 3-8, 17- -.. code-block:: python - - file = FAKER.docx_file( - prefix="zzz", - max_nb_chars=1_024, - wrap_chars_after=80, - ) +*See the full example* +:download:`here <_static/examples/recipes/eml_file_4.py>` Create a PDF file with predefined template containing dynamic fixtures ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Content template is predefined and contains dynamic fixtures. - Wrap lines after 80 chars. -.. code-block:: python - - TEMPLATE = """ - {{date}} {{city}}, {{country}} - - Hello {{name}}, - - {{text}} {{text}} {{text}} - - {{text}} {{text}} {{text}} - - {{text}} {{text}} {{text}} - - Address: {{address}} - - Best regards, +.. literalinclude:: _static/examples/recipes/pdf_file_1.py + :language: python + :lines: 2-3, 5- - {{name}} - {{address}} - {{phone_number}} - """ - - file = FAKER.pdf_file(content=TEMPLATE, wrap_chars_after=80) +*See the full example* +:download:`here <_static/examples/recipes/pdf_file_1.py>` Create a DOCX file with table and image using ``DynamicTemplate`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -435,201 +220,54 @@ It takes a list of content modifiers (tuples): ``(func: Callable, kwargs: dict)``. Each callable should accept the following arguments: -- provider: Faker ``Generator`` instance or ``Faker`` instance. -- document: Document instance. Implementation specific. -- data: Dictionary. Used primarily for observability. -- counter: Integer. Index number of the content modifier. -- **kwargs: Dictionary. Useful to pass implementation-specific arguments. - -The following example shows how to generate a DOCX file with table and image. - -.. code-block:: python - :name: test_create_a_docx_file_with_table_and_image_using_dynamictemplate - - from io import BytesIO - - from faker import Faker - from faker_file.base import DynamicTemplate - from faker_file.providers.docx_file import DocxFileProvider - from faker_file.providers.jpeg_file import JpegFileProvider - - def docx_add_table(provider, document, data, counter, **kwargs): - """Callable responsible for the table generation.""" - table = document.add_table( - kwargs.get("rows", 3), - kwargs.get("cols", 4), - ) - # Modifications of `data` is not required for generation - # of the file, but is useful for when you want to get - # the text content of the file. - data.setdefault("content_modifiers", {}) - data["content_modifiers"].setdefault("add_table", {}) - data["content_modifiers"]["add_table"].setdefault(counter, []) - - for row in table.rows: - for cell in row.cells: - text = provider.generator.paragraph() - cell.text = text - # Useful when you want to get the text content of the file. - data["content_modifiers"]["add_table"][counter].append(text) - data["content"] += ("\r\n" + text) - - - def docx_add_picture(provider, document, data, counter, **kwargs): - """Callable responsible for the picture generation.""" - jpeg_file = JpegFileProvider(provider.generator).jpeg_file(raw=True) - document.add_picture(BytesIO(jpeg_file)) - - # Modifications of `data` is not required for generation - # of the file, but is useful for when you want to get - # the text content of the file. - data.setdefault("content_modifiers", {}) - data["content_modifiers"].setdefault("add_picture", {}) - data["content_modifiers"]["add_picture"].setdefault(counter, []) - data["content_modifiers"]["add_picture"][counter].append( - jpeg_file.data["content"] - ) - data["content"] += ("\r\n" + jpeg_file.data["content"]) - - - file = DocxFileProvider(Faker()).docx_file( - content=DynamicTemplate([(docx_add_table, {}), (docx_add_picture, {})]) - ) +- `provider`: Faker ``Generator`` instance or ``Faker`` instance. +- `document`: Document instance. Implementation specific. +- `data`: Dictionary. Used primarily for observability. +- `counter`: Integer. Index number of the content modifier. +- `**kwargs`: Dictionary. Useful to pass implementation-specific arguments. + +The following example shows how to generate a DOCX file with paragraph, table +and image. + +.. literalinclude:: _static/examples/recipes/docx_file_mixed_1.py + :language: python + :lines: 2-8, 13- + +*See the full example* +:download:`here <_static/examples/recipes/docx_file_mixed_1.py>` Create a ODT file with table and image using ``DynamicTemplate`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Similarly to previous section, the following example shows how to generate an ODT file with table and image. -.. code-block:: python - :name: test_create_a_odt_file_with_table_and_image_using_dynamictemplate - - from faker import Faker - from faker_file.providers.odt_file import OdtFileProvider - from faker_file.base import DynamicTemplate - from faker_file.providers.jpeg_file import JpegFileProvider - from odf.draw import Frame, Image - from odf.style import ( - Style, TextProperties, - TableColumnProperties, - TableRowProperties, - TableCellProperties, - GraphicProperties, - ) - from odf.table import Table, TableRow, TableCell, TableColumn - from odf.text import P - - FAKER = Faker() - - - def odt_add_table(provider, document, data, counter, **kwargs): - """Callable responsible for the table generation.""" - table = Table() - rows = kwargs.get("rows", 3) - cols = kwargs.get("cols", 4) - table_col_style = Style(name="TableColumn", family="table-column") - table_col_style.addElement( - TableColumnProperties(columnwidth="2cm") - ) - document.automaticstyles.addElement(table_col_style) - - table_row_style = Style(name="TableRow", family="table-row") - table_row_style.addElement(TableRowProperties(rowheight="1cm")) - document.automaticstyles.addElement(table_row_style) - - # Modifications of `data` is not required for generation - # of the file, but is useful for when you want to get - # the text content of the file. - data.setdefault("content_modifiers", {}) - data["content_modifiers"].setdefault("add_table", {}) - data["content_modifiers"]["add_table"].setdefault(counter, []) - - table_cell_style = Style(name="TableCell", family="table-cell") - table_cell_style.addElement( - TableCellProperties( - padding="0.1cm", border="0.05cm solid #000000" - ) - ) - document.automaticstyles.addElement(table_cell_style) - - # Create table - table = Table() - for i in range(rows): - table.addElement(TableColumn(stylename=table_col_style)) - - for row in range(cols): - tr = TableRow(stylename=table_row_style) - table.addElement(tr) - for col in range(4): - tc = TableCell(stylename=table_cell_style) - tr.addElement(tc) - text = provider.generator.paragraph() - p = P(text=text) - tc.addElement(p) - # Useful when you want to get the text content of the file. - data["content_modifiers"]["add_table"][counter].append(text) - data["content"] += "\r\n" + text - - document.text.addElement(table) - - - def odt_add_picture(provider, document, data, counter, **kwargs): - """Callable responsible for the picture generation.""" - width = kwargs.get("width", "10cm") - height = kwargs.get("height", "5cm") - paragraph = P() - document.text.addElement(paragraph) - jpeg_file = JpegFileProvider(provider.generator).jpeg_file() - image_data = jpeg_file.data["content"] - image_frame = Frame( - width=width, - height=height, - x="56pt", - y="56pt", - anchortype="paragraph", - ) - href = document.addPicture(jpeg_file.data["filename"]) - image_frame.addElement(Image(href=href)) - paragraph.addElement(image_frame) - - # Modifications of `data` is not required for generation - # of the file, but is useful for when you want to get - # the text content of the file. - data["content"] += "\r\n" + jpeg_file.data["content"] - data.setdefault("content_modifiers", {}) - data["content_modifiers"].setdefault("add_picture", {}) - data["content_modifiers"]["add_picture"].setdefault(counter, []) - data["content_modifiers"]["add_picture"][counter].append( - jpeg_file.data["content"] - ) - - - file = OdtFileProvider(FAKER).odt_file( - content=DynamicTemplate([(odt_add_table, {}), (odt_add_picture, {})]) - ) +.. literalinclude:: _static/examples/recipes/odt_file_mixed_1.py + :language: python + :lines: 3-10, 12- + +*See the full example* +:download:`here <_static/examples/recipes/odt_file_mixed_1.py>` Create a PDF using `reportlab` generator ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. code-block:: python +.. literalinclude:: _static/examples/recipes/pdf_file_reportlab_1.py + :language: python + :lines: 3-5, 9- - from faker_file.providers.pdf_file.generators.reportlab_generator import ( - ReportlabPdfGenerator, - ) - - file = FAKER.pdf_file(pdf_generator_cls=ReportlabPdfGenerator) +*See the full example* +:download:`here <_static/examples/recipes/pdf_file_reportlab_1.py>` Create a PDF using `pdfkit` generator ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Note, that at the moment, ``pdfkit`` is the default generator. However, you could set it explicitly as follows: -.. code-block:: python - - from faker_file.providers.pdf_file.generators.pdfkit_generator import ( - PdfkitPdfGenerator, - ) +.. literalinclude:: _static/examples/recipes/pdf_file_pdfkit_1.py + :language: python + :lines: 3-5, 9- - file = FAKER.pdf_file(pdf_generator_cls=PdfkitPdfGenerator) +*See the full example* +:download:`here <_static/examples/recipes/pdf_file_pdfkit_1.py>` Create a graphic PDF file using `Pillow` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -638,26 +276,23 @@ content. However, sometimes you just need a valid file in PDF format, without caring much about the content. That's where a GraphicPdfFileProvider comes to rescue: -.. code-block:: python - :name: test_create_a_graphic_pdf_file_using_pillow - - from faker import Faker - from faker_file.providers.pdf_file import GraphicPdfFileProvider - - FAKER = Faker() - FAKER.add_provider(GraphicPdfFileProvider) +.. literalinclude:: _static/examples/recipes/pdf_file_pillow_1.py + :language: python + :lines: 2-3, 5- - file = FAKER.graphic_pdf_file() +*See the full example* +:download:`here <_static/examples/recipes/pdf_file_pillow_1.py>` The generated file will contain a random graphic (consisting of lines and shapes of different colours). One of the most useful arguments supported is ``size``. -.. code-block:: python +.. literalinclude:: _static/examples/recipes/pdf_file_pillow_2.py + :language: python + :lines: 7- - file = FAKER.graphic_pdf_file( - size=(800, 800), - ) +*See the full example* +:download:`here <_static/examples/recipes/pdf_file_pillow_2.py>` Graphic providers ~~~~~~~~~~~~~~~~~ @@ -665,110 +300,75 @@ Graphic file providers does not contain text. Don't use it when you need text based content. However, sometimes you just need a valid image file with graphics of a certain size. That's where graphic file providers help. -Supported files formats are: ICO, JPEG, PNG and WEBP. +Supported files formats are: `BMP`, `GIF`, `ICO`, `JPEG`, `PDF`, `PNG`, `SVG` +`TIFF` and `WEBP`. Create an ICO file ^^^^^^^^^^^^^^^^^^ -.. code-block:: python - :name: test_graphic_providers_create_an_ico_file +.. literalinclude:: _static/examples/recipes/graphic_ico_file_1.py + :language: python + :lines: 2-3, 5- - from faker import Faker - from faker_file.providers.ico_file import GraphicIcoFileProvider - - FAKER = Faker() - FAKER.add_provider(GraphicIcoFileProvider) - - file = FAKER.graphic_ico_file(size=(800, 800)) +*See the full example* +:download:`here <_static/examples/recipes/graphic_ico_file_1.py>` Create a JPEG file ^^^^^^^^^^^^^^^^^^ -.. code-block:: python - :name: test_graphic_providers_create_a_jpeg_file - - from faker import Faker - from faker_file.providers.jpeg_file import GraphicJpegFileProvider - - FAKER = Faker() - FAKER.add_provider(GraphicJpegFileProvider) +.. literalinclude:: _static/examples/recipes/graphic_jpeg_file_1.py + :language: python + :lines: 2-3, 5- - file = FAKER.graphic_jpeg_file(size=(800, 800)) +*See the full example* +:download:`here <_static/examples/recipes/graphic_jpeg_file_1.py>` Create a PNG file ^^^^^^^^^^^^^^^^^ -.. code-block:: python - :name: test_graphic_providers_create_a_png_file +.. literalinclude:: _static/examples/recipes/graphic_png_file_1.py + :language: python + :lines: 2-3, 5- - from faker import Faker - from faker_file.providers.png_file import GraphicPngFileProvider - - FAKER = Faker() - FAKER.add_provider(GraphicPngFileProvider) - - file = FAKER.graphic_png_file(size=(800, 800)) +*See the full example* +:download:`here <_static/examples/recipes/graphic_png_file_1.py>` Create a WEBP file ^^^^^^^^^^^^^^^^^^ -.. code-block:: python - :name: test_graphic_providers_create_a_webp_file - - from faker import Faker - from faker_file.providers.webp_file import GraphicWebpFileProvider - - FAKER = Faker() - FAKER.add_provider(GraphicWebpFileProvider) +.. literalinclude:: _static/examples/recipes/graphic_webp_file_1.py + :language: python + :lines: 2-3, 5- - file = FAKER.graphic_webp_file(size=(800, 800)) +*See the full example* +:download:`here <_static/examples/recipes/graphic_webp_file_1.py>` Create a MP3 file ~~~~~~~~~~~~~~~~~ -.. code-block:: python - :name: test_create_a_mp3_file +.. literalinclude:: _static/examples/recipes/mp3_file_1.py + :language: python + :lines: 2-3, 5- - from faker import Faker - from faker_file.providers.mp3_file import Mp3FileProvider - - FAKER = Faker() - FAKER.add_provider(Mp3FileProvider) - - file = FAKER.mp3_file() +*See the full example* +:download:`here <_static/examples/recipes/mp3_file_1.py>` Create a MP3 file by explicitly specifying MP3 generator class ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Google Text-to-Speech ^^^^^^^^^^^^^^^^^^^^^ -.. code-block:: python - :name: test_create_a_mp3_file_explicit_mp3_generator_class +.. literalinclude:: _static/examples/recipes/mp3_file_gtts_1.py + :language: python + :lines: 3-5, 9- - from faker import Faker - from faker_file.providers.mp3_file import Mp3FileProvider - from faker_file.providers.mp3_file.generators.gtts_generator import ( - GttsMp3Generator, - ) +*See the full example* +:download:`here <_static/examples/recipes/mp3_file_gtts_1.py>` - FAKER = Faker() - - file = Mp3FileProvider(FAKER).mp3_file(mp3_generator_cls=GttsMp3Generator) +---- You can tune arguments too: -.. code-block:: python - :name: test_create_a_mp3_file_explicit_mp3_generator_class_fine_tune_args - - from faker import Faker - from faker_file.providers.mp3_file import Mp3FileProvider - from faker_file.providers.mp3_file.generators.gtts_generator import ( - GttsMp3Generator, - ) +.. literalinclude:: _static/examples/recipes/mp3_file_gtts_2.py + :language: python + :lines: 10- - FAKER = Faker() - - file = Mp3FileProvider(FAKER).mp3_file( - mp3_generator_cls=GttsMp3Generator, - mp3_generator_kwargs={ - "lang": "en", - "tld": "co.uk", - } - ) +*See the full example* +:download:`here <_static/examples/recipes/mp3_file_gtts_2.py>` Refer to https://gtts.readthedocs.io/en/latest/module.html#languages-gtts-lang for list of accepted values for ``lang`` argument. @@ -778,38 +378,23 @@ for list of accepted values for ``tld`` argument. Microsoft Edge Text-to-Speech ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -.. code-block:: python - :name: test_create_a_mp3_file_explicit_mp3_generator_class_ms_edge - - from faker import Faker - from faker_file.providers.mp3_file import Mp3FileProvider - from faker_file.providers.mp3_file.generators.edge_tts_generator import ( - EdgeTtsMp3Generator, - ) +.. literalinclude:: _static/examples/recipes/mp3_file_edge_tts_1.py + :language: python + :lines: 3-5, 9- - FAKER = Faker() +*See the full example* +:download:`here <_static/examples/recipes/mp3_file_edge_tts_1.py>` - file = Mp3FileProvider(FAKER).mp3_file(mp3_generator_cls=EdgeTtsMp3Generator) +---- You can tune arguments too: -.. code-block:: python - :name: test_create_a_mp3_file_explicit_mp3_generator_class_ms_edge_finetune - - from faker import Faker - from faker_file.providers.mp3_file import Mp3FileProvider - from faker_file.providers.mp3_file.generators.edge_tts_generator import ( - EdgeTtsMp3Generator, - ) - - FAKER = Faker() +.. literalinclude:: _static/examples/recipes/mp3_file_edge_tts_2.py + :language: python + :lines: 10- - file = Mp3FileProvider(FAKER).mp3_file( - mp3_generator_cls=EdgeTtsMp3Generator, - mp3_generator_kwargs={ - "voice": "en-GB-LibbyNeural", - } - ) +*See the full example* +:download:`here <_static/examples/recipes/mp3_file_edge_tts_2.py>` Run ``edge-tts -l`` from terminal for list of available voices. @@ -826,47 +411,12 @@ services `here `_. Usage with custom MP3 generator class. -.. code-block:: python - - # Imaginary `marytts` Python library - from marytts import MaryTTS - - # Import BaseMp3Generator - from faker_file.providers.base.mp3_generator import ( - BaseMp3Generator, - ) - - # Define custom MP3 generator - class MaryTtsMp3Generator(BaseMp3Generator): - - locale: str = "cmu-rms-hsmm" - voice: str = "en_US" - - def handle_kwargs(self, **kwargs) -> None: - # Since it's impossible to unify all TTS systems it's allowed - # to pass arbitrary arguments to the `BaseMp3Generator` - # constructor. Each implementation class contains its own - # additional tuning arguments. Check the source code of the - # implemented MP3 generators as an example. - if "locale" in kwargs: - self.locale = kwargs["locale"] - if "voice" in kwargs: - self.voice = kwargs["voice"] - - def generate(self) -> bytes: - # Your implementation here. Note, that `self.content` - # in this context is the text to make MP3 from. - # `self.generator` would be the `Faker` or `Generator` - # instance from which you could extract information on - # active locale. - # What comes below is pseudo implementation. - mary_tts = MaryTTS(locale=self.locale, voice=self.voice) - return mary_tts.synth_mp3(self.content) - - # Generate MP3 file from random text - file = FAKER.mp3_file( - mp3_generator_cls=MaryTtsMp3Generator, - ) +.. literalinclude:: _static/examples/recipes/mp3_file_custom_1.py + :language: python + :lines: 2, 4, 9- + +*See the full example* +:download:`here <_static/examples/recipes/mp3_file_custom_1.py>` See exact implementation of `marytts_mp3_generator `_ @@ -878,21 +428,12 @@ Pick a random file from a directory given - Prefix of the destination file would be ``zzz``. - ``source_dir_path`` is the absolute path to the directory to pick files from. -.. code-block:: python - :name: __test_pick_a_random_file_from_directory_given - - from faker import Faker - from faker_file.providers.random_file_from_dir import ( - RandomFileFromDirProvider, - ) +.. literalinclude:: _static/examples/recipes/random_file_from_dir_1.py + :language: python + :lines: 2, 4, 7, 12- - FAKER = Faker() - FAKER.add_provider(RandomFileFromDirProvider) - - file = FAKER.random_file_from_dir( - source_dir_path="/tmp/tmp/", - prefix="zzz", - ) +*See the full example* +:download:`here <_static/examples/recipes/random_file_from_dir_1.py>` File from path given ~~~~~~~~~~~~~~~~~~~~ @@ -900,19 +441,12 @@ File from path given - Prefix of the destination file would be ``zzz``. - ``path`` is the absolute path to the file to copy. -.. code-block:: python - - from faker import Faker - from faker_file.providers.file_from_path import ( - FileFromPathProvider, - ) +.. literalinclude:: _static/examples/recipes/file_from_path_1.py + :language: python + :lines: 3-4, 7, 11- - FAKER = Faker() - - file = FileFromPathProvider(FAKER).file_from_path( - path="/path/to/file.docx", - prefix="zzz", - ) +*See the full example* +:download:`here <_static/examples/recipes/file_from_path_1.py>` Generate a file of a certain size ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -922,147 +456,55 @@ approximate. BIN ^^^ -.. code-block:: python - :name: test_generate_a_file_of_a_certain_size_bin - - from faker import Faker - from faker_file.providers.bin_file import BinFileProvider - - FAKER = Faker() - - file = BinFileProvider(FAKER).bin_file(length=1024**2) # 1 Mb - file = BinFileProvider(FAKER).bin_file(length=3*1024**2) # 3 Mb - file = BinFileProvider(FAKER).bin_file(length=10*1024**2) # 10 Mb +.. literalinclude:: _static/examples/recipes/file_of_size_bin_1.py + :language: python + :lines: 2-3, 5- - file = BinFileProvider(FAKER).bin_file(length=1024) # 1 Kb - file = BinFileProvider(FAKER).bin_file(length=3*1024) # 3 Kb - file = BinFileProvider(FAKER).bin_file(length=10*1024) # 10 Kb +*See the full example* +:download:`here <_static/examples/recipes/file_of_size_bin_1.py>` TXT ^^^ -.. code-block:: python - :name: test_generate_a_file_of_a_certain_size_txt +.. literalinclude:: _static/examples/recipes/file_of_size_txt_1.py + :language: python + :lines: 2-3, 5- - from faker import Faker - from faker_file.providers.txt_file import TxtFileProvider +*See the full example* +:download:`here <_static/examples/recipes/file_of_size_txt_1.py>` - FAKER = Faker() - - file = TxtFileProvider(FAKER).txt_file(max_nb_chars=1024**2) # 1 Mb - file = TxtFileProvider(FAKER).txt_file(max_nb_chars=3*1024**2) # 3 Mb - file = TxtFileProvider(FAKER).txt_file(max_nb_chars=10*1024**2) # 10 Mb - - file = TxtFileProvider(FAKER).txt_file(max_nb_chars=1024) # 1 Kb - file = TxtFileProvider(FAKER).txt_file(max_nb_chars=3*1024) # 3 Kb - file = TxtFileProvider(FAKER).txt_file(max_nb_chars=10*1024) # 10 Kb - -Generate a lot of files using multiprocessing -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Generate 50 DOCX files +Generate a files using multiprocessing +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Generate 10 DOCX files ^^^^^^^^^^^^^^^^^^^^^^ - Use template. -- Generate 50 DOCX files. - -.. code-block:: python - :name: test_generate_a_lot_of_files_using_multiprocessing_50_docx_files +- Generate 10 DOCX files. - from multiprocessing import Pool - from faker import Faker - from faker_file.providers.helpers.inner import create_inner_docx_file - from faker_file.storages.filesystem import FileSystemStorage +.. literalinclude:: _static/examples/recipes/files_multiprocessing_1.py + :language: python + :lines: 1, 4-6, 8- - FAKER = Faker() - STORAGE = FileSystemStorage() - - # Document template - TEMPLATE = "Hey {{name}},\n{{text}},\nBest regards\n{{name}}" - - with Pool(processes=2) as pool: - for _ in range(50): # Number of times we want to run our function - pool.apply_async( - create_inner_docx_file, - # Apply async doesn't support kwargs. We have to pass all - # arguments. - [STORAGE, "mp", FAKER, None, None, TEMPLATE], - ) - pool.close() - pool.join() +*See the full example* +:download:`here <_static/examples/recipes/files_multiprocessing_1.py>` Randomize the file format ^^^^^^^^^^^^^^^^^^^^^^^^^ -.. code-block:: python - :name: test_generate_a_lot_of_files_using_multiprocessing_randomize_format - - from multiprocessing import Pool - - from faker import Faker - from faker_file.providers.helpers.inner import ( - create_inner_docx_file, - create_inner_epub_file, - create_inner_pdf_file, - create_inner_txt_file, - fuzzy_choice_create_inner_file, - ) - from faker_file.storages.filesystem import FileSystemStorage - - FAKER = Faker() - STORAGE = FileSystemStorage() - - # Document template - TEMPLATE = """ - {{date}} {{city}}, {{country}} - - Hello {{name}}, - - {{text}} {{text}} {{text}} - - {{text}} {{text}} {{text}} - - {{text}} {{text}} {{text}} - - Address: {{address}} - - Best regards, +.. literalinclude:: _static/examples/recipes/files_multiprocessing_2.py + :language: python + :lines: 4-10, 36- - {{name}} - {{address}} - {{phone_number}} - """ - - kwargs = {"storage": STORAGE, "generator": FAKER, "content": TEMPLATE} - - with Pool(processes=8) as pool: - for _ in range(100): # Number of times we want to run our function - pool.apply_async( - fuzzy_choice_create_inner_file, - [ - [ - (create_inner_docx_file, kwargs), - (create_inner_epub_file, kwargs), - (create_inner_pdf_file, kwargs), - (create_inner_txt_file, kwargs), - ] - ], - ) - pool.close() - pool.join() +*See the full example* +:download:`here <_static/examples/recipes/files_multiprocessing_2.py>` Generating files from existing documents using NLP augmentation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ See the following example: -.. code-block:: python - - from faker import Faker - from faker_file.providers.augment_file_from_dir import ( - AugmentFileFromDirProvider, - ) - - FAKER = Faker() +.. literalinclude:: _static/examples/recipes/augment_file_from_dir_1.py + :language: python + :lines: 2-4, 9, 15, 22- - file = AugmentFileFromDirProvider(FAKER).augment_file_from_dir( - source_dir_path="/path/to/source/", - ) +*See the full example* +:download:`here <_static/examples/recipes/augment_file_from_dir_1.py>` Generated file will resemble text of the original document, but will not be the same. This is useful when you don't want to @@ -1080,15 +522,19 @@ The following file types are supported: - ``RTF`` - ``TXT`` +---- + By default, all supported files are eligible for random selection. You could however narrow that list by providing ``extensions`` argument: -.. code-block:: python +.. literalinclude:: _static/examples/recipes/augment_file_from_dir_2.py + :language: python + :lines: 23- + +*See the full example* +:download:`here <_static/examples/recipes/augment_file_from_dir_2.py>` - file = AugmentFileFromDirProvider(FAKER).augment_file_from_dir( - source_dir_path="/path/to/source/", - extensions={"docx", "pdf"}, # Pick only DOCX or PDF - ) +---- By default ``bert-base-multilingual-cased`` model is used, which is pretrained on the top 104 languages with the largest Wikipedia using a @@ -1103,21 +549,12 @@ Some well working options for ``model_path`` are: - ``bert-base-german-cased`` - ``GroNLP/bert-base-dutch-cased`` -.. code-block:: python +.. literalinclude:: _static/examples/recipes/augment_file_from_dir_3.py + :language: python + :lines: 5-7, 25- - from faker_file.providers.augment_file_from_dir.augmenters import ( - nlpaug_augmenter - ) - - file = AugmentFileFromDirProvider(FAKER).augment_file_from_dir( - text_augmenter_cls=( - nlpaug_augmenter.ContextualWordEmbeddingsAugmenter - ), - text_augmenter_kwargs={ - "model_path": "bert-base-cased", - "action": "substitute", # or "insert" - } - ) +*See the full example* +:download:`here <_static/examples/recipes/augment_file_from_dir_3.py>` Refer to ``nlpaug`` `docs `__ @@ -1131,89 +568,38 @@ totally correct, ``bytes``-like object ``BytesValue``, which is basically bytes enriched with meta-data). You could then use the ``bytes`` content of the file to build a test payload as shown in the example test below: -.. code-block:: python - - import os - from io import BytesIO - - from django.test import TestCase - from django.urls import reverse - from faker import Faker - from faker_file.providers.docx_file import DocxFileProvider - from rest_framework.status import HTTP_201_CREATED - from upload.models import Upload - - FAKER = Faker() - FAKER.add_provider(DocxFileProvider) - - class UploadTestCase(TestCase): - """Upload test case.""" - - def test_create_docx_upload(self) -> None: - """Test create an Upload.""" - url = reverse("api:upload-list") - - raw = FAKER.docx_file(raw=True) - test_file = BytesIO(raw) - test_file.name = os.path.basename(raw.data["filename"]) - - payload = { - "name": FAKER.word(), - "description": FAKER.paragraph(), - "file": test_file, - } - - response = self.client.post(url, payload, format="json") - - # Test if request is handled properly (HTTP 201) - self.assertEqual(response.status_code, HTTP_201_CREATED) +.. literalinclude:: _static/examples/recipes/raw_1.py + :language: python + :lines: 16- - test_upload = Upload.objects.get(id=response.data["id"]) +*See the full example* +:download:`here <_static/examples/recipes/raw_1.py>` - # Test if the name is properly recorded - self.assertEqual(str(test_upload.name), payload["name"]) - - # Test if file name recorded properly - self.assertEqual(str(test_upload.file.name), test_file.name) - -Create a HTML file predefined template -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Create a HTML file from predefined template +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If you want to generate a file in a format that is not (yet) supported, you can try to use ``GenericFileProvider``. In the following example, an HTML file is generated from a template. -.. code-block:: python - :name: test_generate_a_html_file_from_predefined_template - - from faker import Faker - from faker_file.providers.generic_file import GenericFileProvider +.. literalinclude:: _static/examples/recipes/generic_file_1.py + :language: python + :lines: 2-3, 5- - FAKER = Faker() - - file = GenericFileProvider(FAKER).generic_file( - content="

{{text}}

", - extension="html", - ) +*See the full example* +:download:`here <_static/examples/recipes/generic_file_1.py>` Working with storages ~~~~~~~~~~~~~~~~~~~~~ AWS S3 storage ^^^^^^^^^^^^^^ -.. code-block:: python - - from faker import Faker - from faker_file.providers.txt_file import TxtFileProvider - from faker_file.storages.aws_s3 import AWSS3Storage +.. literalinclude:: _static/examples/recipes/aws_s3_storage_1.py + :language: python + :lines: 3, 7- - FAKER = Faker() - AWS_S3_STORAGE = AWSS3Storage( - bucket_name="your-bucket-name", - root_path="", - rel_path="", - ) - FAKER.add_provider(TxtFileProvider) +*See the full example* +:download:`here <_static/examples/recipes/aws_s3_storage_1.py>` - txt_file = FAKER.txt_file(storage=AWS_S3_STORAGE) +---- Depending on the ORM or framework you're using, you might want to tweak the ``root_path`` and ``rel_path`` values. Especially if you store files in @@ -1223,63 +609,43 @@ For instance, if you use ``Django`` and ``django-storages``, and want to store the files inside ``/user/uploads`` directory the following would be correct: -.. code-block:: python +.. literalinclude:: _static/examples/recipes/aws_s3_storage_2.py + :language: python + :lines: 8-12 - AWS_S3_STORAGE = AWSS3Storage( - bucket_name="your-bucket-name", - root_path="", - rel_path="user/uploads", - ) +*See the full example* +:download:`here <_static/examples/recipes/aws_s3_storage_2.py>` Google Cloud Storage ^^^^^^^^^^^^^^^^^^^^ -.. code-block:: python +.. literalinclude:: _static/examples/recipes/google_cloud_storage_1.py + :language: python + :lines: 3, 7- - from faker import Faker - from faker_file.providers.txt_file import TxtFileProvider - from faker_file.storages.google_cloud_storage import GoogleCloudStorage +*See the full example* +:download:`here <_static/examples/recipes/google_cloud_storage_1.py>` - FAKER = Faker() - GC_STORAGE = GoogleCloudStorage( - bucket_name="your-bucket-name", - root_path="", - rel_path="", - ) - FAKER.add_provider(TxtFileProvider) - - txt_file = FAKER.txt_file(storage=GC_STORAGE) +---- Similarly to ``AWSS3Storage``, if you use ``Django`` and ``django-storages``, and want to store the files inside ``/user/uploads`` directory the following would be correct: -.. code-block:: python +.. literalinclude:: _static/examples/recipes/google_cloud_storage_2.py + :language: python + :lines: 8-12 - GC_STORAGE = GoogleCloudStorage( - bucket_name="your-bucket-name", - root_path="", - rel_path="user/uploads", - ) +*See the full example* +:download:`here <_static/examples/recipes/google_cloud_storage_2.py>` SFTP storage ^^^^^^^^^^^^ -.. code-block:: python - - from faker import Faker - from faker_file.providers.txt_file import TxtFileProvider - from faker_file.storages.sftp import SFTPStorage +.. literalinclude:: _static/examples/recipes/sftp_storage_1.py + :language: python + :lines: 3, 7- - FAKER = Faker() - SFTP_STORAGE = SFTPStorage( - host="your-sftp-host.domain", - port: 22, - username: "your-sftp-username", - password: "your-sftp-password, - root_path: "/dir-name", - ) - FAKER.add_provider(TxtFileProvider) - - txt_file = FAKER.txt_file(storage=SFTP_STORAGE) +*See the full example* +:download:`here <_static/examples/recipes/sftp_storage_1.py>` When using with ``Django`` (and ``factory_boy``) ------------------------------------------------ @@ -1290,292 +656,91 @@ reside outside the ``MEDIA_ROOT`` directory (by default in ``/tmp/`` on Linux) and further operations with those files through Django will cause ``SuspiciousOperation`` exception. +---- + Basic example ~~~~~~~~~~~~~ Imaginary ``Django`` model ^^^^^^^^^^^^^^^^^^^^^^^^^^ -.. code-block:: python - - from django.db import models - - class Upload(models.Model): - """Upload model.""" +.. literalinclude:: _static/examples/recipes/factory_boy_models_1.py + :language: python + :lines: 4-11 - name = models.CharField(max_length=255, unique=True) - description = models.TextField(null=True, blank=True) - - # File - file = models.FileField(null=True) - - class Meta: - verbose_name = "Upload" - verbose_name_plural = "Upload" - - def __str__(self): - return self.name +*See the full example* +:download:`here <_static/examples/recipes/factory_boy_models_1.py>` Correspondent ``factory_boy`` factory ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. code-block:: python - - from django.conf import settings - - from factory import Faker - from factory.django import DjangoModelFactory - - # Import all providers we want to use - from faker_file.providers.bin_file import BinFileProvider - from faker_file.providers.csv_file import CsvFileProvider - from faker_file.providers.docx_file import DocxFileProvider - from faker_file.providers.eml_file import EmlFileProvider - from faker_file.providers.epub_file import EpubFileProvider - from faker_file.providers.ico_file import IcoFileProvider - from faker_file.providers.jpeg_file import JpegFileProvider - from faker_file.providers.mp3_file import Mp3FileProvider - from faker_file.providers.ods_file import OdsFileProvider - from faker_file.providers.odt_file import OdtFileProvider - from faker_file.providers.pdf_file import PdfFileProvider - from faker_file.providers.png_file import PngFileProvider - from faker_file.providers.pptx_file import PptxFileProvider - from faker_file.providers.rtf_file import RtfFileProvider - from faker_file.providers.svg_file import SvgFileProvider - from faker_file.providers.txt_file import TxtFileProvider - from faker_file.providers.webp_file import WebpFileProvider - from faker_file.providers.xlsx_file import XlsxFileProvider - from faker_file.providers.zip_file import ZipFileProvider - - # Import file storage, because we need to customize things in order for it - # to work with Django. - from faker_file.storages.filesystem import FileSystemStorage - - from upload.models import Upload - - # Add all providers we want to use - Faker.add_provider(BinFileProvider) - Faker.add_provider(CsvFileProvider) - Faker.add_provider(DocxFileProvider) - Faker.add_provider(EmlFileProvider) - Faker.add_provider(EpubFileProvider) - Faker.add_provider(IcoFileProvider) - Faker.add_provider(JpegFileProvider) - Faker.add_provider(Mp3FileProvider) - Faker.add_provider(OdsFileProvider) - Faker.add_provider(OdtFileProvider) - Faker.add_provider(PdfFileProvider) - Faker.add_provider(PngFileProvider) - Faker.add_provider(PptxFileProvider) - Faker.add_provider(RtfFileProvider) - Faker.add_provider(SvgFileProvider) - Faker.add_provider(TxtFileProvider) - Faker.add_provider(WebpFileProvider) - Faker.add_provider(XlsxFileProvider) - Faker.add_provider(ZipFileProvider) - - # Define a file storage. When working with Django and FileSystemStorage - # you need to set the value of `root_path` argument to - # `settings.MEDIA_ROOT`. - STORAGE = FileSystemStorage( - root_path=settings.MEDIA_ROOT, - rel_path="tmp" - ) - - class UploadFactory(DjangoModelFactory): - """Upload factory.""" - - name = Faker("text", max_nb_chars=100) - description = Faker("text", max_nb_chars=1000) - - class Meta: - model = Upload - - class Params: - bin_file = Trait(file=Faker("bin_file", storage=STORAGE)) - csv_file = Trait(file=Faker("csv_file", storage=STORAGE)) - docx_file = Trait(file=Faker("docx_file", storage=STORAGE)) - eml_file = Trait(file=Faker("eml_file", storage=STORAGE)) - epub_file = Trait(file=Faker("epub_file", storage=STORAGE)) - ico_file = Trait(file=Faker("ico_file", storage=STORAGE)) - jpeg_file = Trait(file=Faker("jpeg_file", storage=STORAGE)) - mp3_file = Trait(file=Faker("mp3_file", storage=STORAGE)) - ods_file = Trait(file=Faker("ods_file", storage=STORAGE)) - odt_file = Trait(file=Faker("odt_file", storage=STORAGE)) - pdf_file = Trait(file=Faker("pdf_file", storage=STORAGE)) - png_file = Trait(file=Faker("png_file", storage=STORAGE)) - pptx_file = Trait(file=Faker("pptx_file", storage=STORAGE)) - rtf_file = Trait(file=Faker("rtf_file", storage=STORAGE)) - svg_file = Trait(file=Faker("svg_file", storage=STORAGE)) - txt_file = Trait(file=Faker("txt_file", storage=STORAGE)) - webp_file = Trait(file=Faker("webp_file", storage=STORAGE)) - xlsx_file = Trait(file=Faker("xlsx_file", storage=STORAGE)) - zip_file = Trait(file=Faker("zip_file", storage=STORAGE)) +.. literalinclude:: _static/examples/recipes/factory_boy_factory_1.py + :language: python + :lines: 1-87 And then somewhere in your code: -.. code-block:: python +.. literalinclude:: _static/examples/recipes/factory_boy_factory_1.py + :language: python + :lines: 91- - UploadFactory(bin_file=True) # Upload with BIN file - UploadFactory(docx_file=True) # Upload with DOCX file - UploadFactory(jpeg_file=True) # Upload with JPEG file - UploadFactory(zip_file=True) # Upload with ZIP file +*See the full example* +:download:`here <_static/examples/recipes/factory_boy_factory_1.py>` + +---- Randomize provider choice ~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. code-block:: python - - from factory import LazyAttribute - from faker import Faker - from random import choice - - FAKER = Faker() - - PROVIDER_CHOICES = [ - lambda: BinFileProvider(FAKER).bin_file(storage=STORAGE), - lambda: CsvFileProvider(FAKER).csv_file(storage=STORAGE), - lambda: DocxFileProvider(FAKER).docx_file(storage=STORAGE), - lambda: EmlFileProvider(FAKER).eml_file(storage=STORAGE), - lambda: EpubFileProvider(FAKER).epub_file(storage=STORAGE), - lambda: IcoFileProvider(FAKER).ico_file(storage=STORAGE), - lambda: JpegFileProvider(FAKER).jpeg_file(storage=STORAGE), - lambda: Mp3FileProvider(FAKER).mp3_file(storage=STORAGE), - lambda: OdsFileProvider(FAKER).ods_file(storage=STORAGE), - lambda: OdtFileProvider(FAKER).odt_file(storage=STORAGE), - lambda: PdfFileProvider(FAKER).pdf_file(storage=STORAGE), - lambda: PngFileProvider(FAKER).png_file(storage=STORAGE), - lambda: PptxFileProvider(FAKER).pptx_file(storage=STORAGE), - lambda: RtfFileProvider(FAKER).rtf_file(storage=STORAGE), - lambda: SvgFileProvider(FAKER).svg_file(storage=STORAGE), - lambda: TxtFileProvider(FAKER).txt_file(storage=STORAGE), - lambda: XlsxFileProvider(FAKER).xlsx_file(storage=STORAGE), - lambda: ZipFileProvider(FAKER).zip_file(storage=STORAGE), - ] - - def pick_random_provider(*args, **kwargs): - return choice(PROVIDER_CHOICES)() - - class UploadFactory(DjangoModelFactory): - """Upload factory that randomly picks a file provider.""" - - # ... - class Params: - # ... - random_file = Trait(file=LazyAttribute(pick_random_provider)) - # ... +.. literalinclude:: _static/examples/recipes/factory_boy_factory_2.py + :language: python + :lines: 1, 4, 6, 27, 30-49, 55-95 And then somewhere in your code: -.. code-block:: python +.. literalinclude:: _static/examples/recipes/factory_boy_factory_2.py + :language: python + :lines: 98- - UploadFactory(random_file=True) # Upload with randon file +*See the full example* +:download:`here <_static/examples/recipes/factory_boy_factory_2.py>` Use a different locale ~~~~~~~~~~~~~~~~~~~~~~ -.. code-block:: python - - from factory import Faker - from factory.django import DjangoModelFactory - from faker_file.providers.ods_file import OdsFileProvider - - Faker._DEFAULT_LOCALE = "hy_AM" # Set locale to Armenian - - Faker.add_provider(OdsFileProvider) - - class UploadFactory(DjangoModelFactory): - """Base Upload factory.""" - - name = Faker("text", max_nb_chars=100) - description = Faker("text", max_nb_chars=1000) - file = Faker("ods_file") - - class Meta: - """Meta class.""" +.. literalinclude:: _static/examples/recipes/factory_boy_factory_3.py + :language: python + :lines: 23-24 - model = Upload +*See the full example* +:download:`here <_static/examples/recipes/factory_boy_factory_3.py>` Other Django usage examples ~~~~~~~~~~~~~~~~~~~~~~~~~~~ **Faker example with AWS S3 storage** -.. code-block:: python +.. literalinclude:: _static/examples/recipes/aws_s3_storage_3.py + :language: python + :lines: 2, 4- - from django.conf import settings - from faker import Faker - from faker_file.providers.pdf_file import PdfFileProvider - from faker_file.storages.aws_s3 import AWSS3Storage +*See the full example* +:download:`here <_static/examples/recipes/aws_s3_storage_3.py>` - FAKER = Faker() - STORAGE = AWSS3Storage( - bucket_name=settings.AWS_STORAGE_BUCKET_NAME, - root_path="", - rel_path="", - ) - FAKER.add_provider(PdfFileProvider) - - file = FAKER.pdf_file(storage=STORAGE) +---- **factory-boy example with AWS S3 storage** -.. code-block:: python - - import factory - - from django.conf import settings - from factory import Faker - from factory.django import DjangoModelFactory - from faker_file.storages.aws_s3 import AWSS3Storage - - from upload.models import Upload +.. literalinclude:: _static/examples/recipes/aws_s3_storage_4.py + :language: python + :lines: 2, 4-6, 9- - STORAGE = AWSS3Storage( - bucket_name=settings.AWS_STORAGE_BUCKET_NAME, - root_path="", - rel_path="", - ) +*See the full example* +:download:`here <_static/examples/recipes/aws_s3_storage_4.py>` - Faker.add_provider(PdfFileProvider) - - class UploadFactory(DjangoModelFactory): - name = Faker('word') - description = Faker('text') - file = Faker("pdf_file", storage=STORAGE) - - class Meta: - model = Upload - - upload = UploadFactory() +---- **Flexible storage selection** -.. code-block:: python - - from django.conf import settings - from django.core.files.storage import default_storage - from faker_file.storages.aws_s3 import AWSS3Storage - from faker_file.storages.filesystem import FileSystemStorage - from storages.backends.s3boto3 import S3Boto3Storage - - # Faker doesn't know anything about Django. That's why, if we want to - # support remote storages, we need to manually check which file storage - # backend is used. If `Boto3` storage backend (of the `django-storages` - # package) is used we use the correspondent `AWSS3Storage` class of the - # `faker-file`. - # Otherwise, fall back to native file system storage (`FileSystemStorage`) - # of the `faker-file`. - if isinstance(default_storage, S3Boto3Storage): - STORAGE = AWSS3Storage( - bucket_name=settings.AWS_STORAGE_BUCKET_NAME, - credentials={ - "key_id": settings.AWS_ACCESS_KEY_ID, - "key_secret": settings.AWS_SECRET_ACCESS_KEY, - }, - root_path="", - rel_path="tmp", - ) - else: - STORAGE = FileSystemStorage( - root_path=settings.MEDIA_ROOT, - rel_path="tmp", - ) +.. literalinclude:: _static/examples/recipes/flexible_storage_1.py + :language: python + :lines: 2- + +*See the full example* +:download:`here <_static/examples/recipes/flexible_storage_1.py>` diff --git a/docs/talks/pygrunn_2023.rst b/docs/talks/pygrunn_2023.rst index 26a172d2..b98f8e91 100644 --- a/docs/talks/pygrunn_2023.rst +++ b/docs/talks/pygrunn_2023.rst @@ -74,18 +74,18 @@ As everything else in life, it has pros, cons and alternatives. The pros ~~~~~~~~ -- **Data privacy**: Because it's fake - there's no risk of exposing sensitive user data - and no need to comply with data privacy regulations. +- **Data privacy**: Because it's fake - there's no risk of exposing sensitive + user data and no need to comply with data privacy regulations. - **Scalability**: You can generate as much data as you need. -- **Controll**: You have full control over the data, so you can test specific rare edge - cases. +- **Controll**: You have full control over the data, so you can test specific + rare edge cases. The cons ~~~~~~~~ -- **Realism**: Because it's fake it does not always accurately represent real data - or contain the same patterns and anomalies. That could lead to less accurate - testing. +- **Realism**: Because it's fake it does not always accurately represent real + data or contain the same patterns and anomalies. That could lead to less + accurate testing. - **Generation complexity**: Creating realistic data can be complex and time-consuming, depending on the domain and the complexity of the data structures. @@ -325,9 +325,9 @@ files. - Content is generated dynamically. - Prefix the filenames in archive with ``nested_level_1_``. - Prefix the filename of the archive itself with ``nested_level_0_``. -- Each of the `ZIP` files inside the `ZIP` file in their turn contains 5 other `ZIP` - files, prefixed with ``nested_level_2_``, which in their turn contain 2 - DOCX files. +- Each of the `ZIP` files inside the `ZIP` file in their turn contains 5 other + `ZIP` files, prefixed with ``nested_level_2_``, which in their turn contain + 2 `DOCX` files. .. code-block:: python @@ -382,7 +382,7 @@ Create a ZIP file with variety of different file types within ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 50 files in the ZIP archive (limited to DOCX, EPUB and TXT types). - Content is generated dynamically. -- Prefix the filename of the archive itself with zzz_archive_. +- Prefix the filename of the archive itself with `zzz_archive_`. - Inside the ZIP, put all files in directory zzz. .. code-block:: python @@ -456,7 +456,11 @@ Another way to create a ZIP file with variety of different file types within Using raw=True features in tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If you pass ``raw=True`` argument to any provider or inner function, instead of creating a file, you will get bytes back (or to be totally correct, bytes-like object ``BytesValue``, which is basically bytes enriched with meta-data). You could then use the bytes content of the file to build a test payload as shown in the example test below: +If you pass ``raw=True`` argument to any provider or inner function, instead +of creating a file, you will get bytes back (or to be totally correct, +bytes-like object ``BytesValue``, which is basically bytes enriched with +meta-data). You could then use the bytes content of the file to build a test +payload as shown in the example test below: .. code-block:: python @@ -596,7 +600,7 @@ CLI Even if you're not using automated testing, but still want to quickly generate a file with fake content, you could use faker-file: -.. code-block:: sh+- +.. code-block:: sh faker-file generate-completion source ~/faker_file_completion.sh @@ -648,9 +652,9 @@ Recap/conclusion - Most likely, combination of `Faker`_, `factory_boy`_ and `faker-file`_ will do just fine for your MVP and even way beyond that (you have all in one: synthetic data + dynamic fixtures + generation of files). - This approach also saves you from thinking about where to store your test data, - and overall, makes your code more manageable and simplifies the development - process. + This approach also saves you from thinking about where to store your test + data, and overall, makes your code more manageable and simplifies the + development process. - If you need to test files in your project, think upfront about the details, such as amount of test files you will need, where to store them, how to store them, etc. diff --git a/docs/test_docs.py b/docs/test_docs.py new file mode 100644 index 00000000..77eb679d --- /dev/null +++ b/docs/test_docs.py @@ -0,0 +1,57 @@ +import logging +from pathlib import Path +from unittest import mock +from unittest.mock import create_autospec + +import paramiko +import pytest +from django.test import override_settings +from faker_file.registry import FILE_REGISTRY +from moto import mock_s3 + +# Walk through the directory and all subdirectories for .py files +example_dir = Path("docs/_static/examples") +py_files = sorted([str(p) for p in example_dir.rglob("*.py")]) + + +@pytest.fixture +def mock_gcs(): + """Mock Google Cloud Storage.""" + with mock.patch("google.cloud.storage.Client") as mock_client: + yield mock_client + + +@pytest.fixture +def mock_paramiko(): + """Mock paramiko.""" + mock_transport = create_autospec(paramiko.Transport) + mock_transport.return_value.send = mock.Mock(return_value=42) + + mock_sftp_client = create_autospec(paramiko.SFTPClient) + mock_sftp_client.from_transport.return_value = mock_sftp_client + + with mock.patch("paramiko.Transport", mock_transport), mock.patch( + "paramiko.SFTPClient", mock_sftp_client + ): + yield + + +# We have to apply `moto` mocking to all test functions, because in some +# we have boto dependant code. +@mock_s3 +def execute_file(file_path, caplog): + """Dynamic test function.""" + global_vars = {} + # Set the log level to WARNING for this block + with caplog.at_level(logging.WARNING): + with open(file_path, "r") as f: + code = f.read() + exec(code, global_vars) + + +@pytest.mark.django_db +@pytest.mark.parametrize("file_path", py_files) +@override_settings(AWS_STORAGE_BUCKET_NAME="testing") +def test_dynamic_files(file_path, caplog, mock_gcs, mock_paramiko): + execute_file(file_path, caplog) + FILE_REGISTRY.clean_up() diff --git a/examples/customizations/marytts_mp3_generator/__init__.py b/examples/customizations/marytts_mp3_generator/__init__.py index 98dca781..4f8a7410 100644 --- a/examples/customizations/marytts_mp3_generator/__init__.py +++ b/examples/customizations/marytts_mp3_generator/__init__.py @@ -2,9 +2,8 @@ import tempfile import ffmpeg -from speak2mary import MaryTTS - from faker_file.providers.base.mp3_generator import BaseMp3Generator +from speak2mary import MaryTTS __author__ = "Artur Barseghyan " __copyright__ = "2022-2023 Artur Barseghyan" diff --git a/examples/django_example/factories/upload_upload.py b/examples/django_example/factories/upload_upload.py index 79112c74..4214af2a 100644 --- a/examples/django_example/factories/upload_upload.py +++ b/examples/django_example/factories/upload_upload.py @@ -4,9 +4,6 @@ from django.core.files.storage import default_storage from factory import Faker, LazyAttribute, Trait from factory.django import DjangoModelFactory -from storages.backends.s3boto3 import S3Boto3Storage -from upload.models import Upload - from faker_file.providers.bin_file import BinFileProvider from faker_file.providers.csv_file import CsvFileProvider from faker_file.providers.docx_file import DocxFileProvider @@ -30,6 +27,9 @@ from faker_file.providers.zip_file import ZipFileProvider from faker_file.storages.aws_s3 import AWSS3Storage from faker_file.storages.filesystem import FileSystemStorage +from storages.backends.s3boto3 import S3Boto3Storage + +from upload.models import Upload __all__ = ("UploadFactory",) diff --git a/examples/django_example/upload/api/tests.py b/examples/django_example/upload/api/tests.py index 231c2933..4e885bd6 100644 --- a/examples/django_example/upload/api/tests.py +++ b/examples/django_example/upload/api/tests.py @@ -4,11 +4,11 @@ from django.test import TestCase from django.urls import reverse from faker import Faker -from rest_framework.status import HTTP_201_CREATED -from upload.models import Upload - from faker_file.providers.docx_file import DocxFileProvider from faker_file.registry import FILE_REGISTRY +from rest_framework.status import HTTP_201_CREATED + +from upload.models import Upload FAKER = Faker() FAKER.add_provider(DocxFileProvider) diff --git a/examples/requirements/dev.txt b/examples/requirements/dev.txt index ecb3fbf4..f803eec6 100644 --- a/examples/requirements/dev.txt +++ b/examples/requirements/dev.txt @@ -32,10 +32,13 @@ beautifulsoup4==4.11.1 bleach==5.0.1 # via readme-renderer boto3==1.26.33 - # via pathy + # via + # moto + # pathy botocore==1.29.33 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -70,6 +73,7 @@ cryptography==38.0.4 # via # asyncssh # azure-storage-blob + # moto # paramiko # secretstorage cssselect2==0.7.0 @@ -170,7 +174,9 @@ jeepney==0.8.0 # keyring # secretstorage jinja2==3.1.2 - # via xml2epub + # via + # moto + # xml2epub jmespath==1.0.1 # via # boto3 @@ -187,11 +193,15 @@ lxml==4.9.1 # python-pptx # xml2epub markupsafe==2.1.1 - # via jinja2 + # via + # jinja2 + # werkzeug mock==4.0.3 # via pathy more-itertools==9.0.0 # via jaraco-classes +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -296,6 +306,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -305,28 +316,34 @@ python-pptx==0.6.21 pytz==2022.6 # via django pyyaml==6.0 - # via drf-spectacular + # via + # drf-spectacular + # responses rapidfuzz==3.1.1 # via levenshtein readme-renderer==37.3 # via twine reportlab==3.6.12 # via -r examples/requirements/common.in -requests==2.28.1 +requests==2.31.0 # via # azure-core # google-api-core # google-cloud-storage # gtts + # moto # msrest # requests-oauthlib # requests-toolbelt + # responses # twine # xml2epub requests-oauthlib==1.3.1 # via msrest requests-toolbelt==0.10.1 # via twine +responses==0.23.3 + # via moto rfc3986==2.0.0 # via twine rich==12.6.0 @@ -381,6 +398,8 @@ typer==0.3.2 # typer-cli typer-cli==0.0.12 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -391,6 +410,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses # twine virtualenv==20.17.0 # via tox @@ -402,10 +422,14 @@ webencodings==0.5.1 # cssselect2 # html5lib # tinycss2 +werkzeug==3.0.0 + # via moto xlsxwriter==3.0.3 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zipp==3.11.0 diff --git a/examples/requirements/django_2_2.txt b/examples/requirements/django_2_2.txt index 87000f04..e03cccaa 100644 --- a/examples/requirements/django_2_2.txt +++ b/examples/requirements/django_2_2.txt @@ -28,10 +28,13 @@ bcrypt==4.0.1 beautifulsoup4==4.11.1 # via xml2epub boto3==1.26.29 - # via pathy + # via + # moto + # pathy botocore==1.29.29 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -64,6 +67,7 @@ cryptography==38.0.4 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -148,7 +152,9 @@ iniconfig==1.1.1 isodate==0.6.1 # via msrest jinja2==3.1.2 - # via xml2epub + # via + # moto + # xml2epub jmespath==1.0.1 # via # boto3 @@ -163,9 +169,13 @@ lxml==4.9.1 # python-pptx # xml2epub markupsafe==2.1.1 - # via jinja2 + # via + # jinja2 + # werkzeug mock==4.0.3 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -264,6 +274,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -273,22 +284,28 @@ python-pptx==0.6.21 pytz==2022.6 # via django pyyaml==6.0 - # via drf-spectacular + # via + # drf-spectacular + # responses rapidfuzz==3.1.1 # via levenshtein reportlab==3.6.12 # via -r examples/requirements/common.in -requests==2.28.1 +requests==2.31.0 # via # azure-core # google-api-core # google-cloud-storage # gtts + # moto # msrest # requests-oauthlib + # responses # xml2epub requests-oauthlib==1.3.1 # via msrest +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.0 @@ -334,6 +351,8 @@ typer==0.3.2 # typer-cli typer-cli==0.0.12 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -344,6 +363,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses virtualenv==20.17.0 # via tox weasyprint==59.0 @@ -353,10 +373,14 @@ webencodings==0.5.1 # cssselect2 # html5lib # tinycss2 +werkzeug==3.0.0 + # via moto xlsxwriter==3.0.3 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zopfli==0.2.2 diff --git a/examples/requirements/django_2_2_and_flask.txt b/examples/requirements/django_2_2_and_flask.txt index 4d8a2088..f3763aa2 100644 --- a/examples/requirements/django_2_2_and_flask.txt +++ b/examples/requirements/django_2_2_and_flask.txt @@ -32,10 +32,13 @@ bcrypt==4.0.1 beautifulsoup4==4.11.1 # via xml2epub boto3==1.26.36 - # via pathy + # via + # moto + # pathy botocore==1.29.36 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -73,6 +76,7 @@ cryptography==38.0.4 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -181,6 +185,7 @@ jinja2==3.1.2 # via # flask # flask-babelex + # moto # xml2epub jmespath==1.0.1 # via @@ -205,6 +210,8 @@ markupsafe==2.1.1 # wtforms mock==4.0.3 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -304,6 +311,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -315,22 +323,28 @@ pytz==2022.7 # babel # django pyyaml==6.0 - # via drf-spectacular + # via + # drf-spectacular + # responses rapidfuzz==3.1.1 # via levenshtein reportlab==3.6.12 # via -r examples/requirements/common.in -requests==2.28.1 +requests==2.31.0 # via # azure-core # google-api-core # google-cloud-storage # gtts + # moto # msrest # requests-oauthlib + # responses # xml2epub requests-oauthlib==1.3.1 # via msrest +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.0 @@ -382,6 +396,8 @@ typer==0.7.0 # via pathy typer-cli==0.0.1 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -392,6 +408,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses virtualenv==20.17.1 # via tox weasyprint==59.0 @@ -402,13 +419,17 @@ webencodings==0.5.1 # html5lib # tinycss2 werkzeug==2.2.3 - # via flask + # via + # flask + # moto wtforms==3.0.1 # via flask-admin xlsxwriter==3.0.3 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zipp==3.11.0 diff --git a/examples/requirements/django_3_2.txt b/examples/requirements/django_3_2.txt index 2874f04f..a2619620 100644 --- a/examples/requirements/django_3_2.txt +++ b/examples/requirements/django_3_2.txt @@ -30,10 +30,13 @@ bcrypt==4.0.1 beautifulsoup4==4.11.1 # via xml2epub boto3==1.26.29 - # via pathy + # via + # moto + # pathy botocore==1.29.29 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -66,6 +69,7 @@ cryptography==38.0.4 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -153,7 +157,9 @@ iniconfig==1.1.1 isodate==0.6.1 # via msrest jinja2==3.1.2 - # via xml2epub + # via + # moto + # xml2epub jmespath==1.0.1 # via # boto3 @@ -168,9 +174,13 @@ lxml==4.9.1 # python-pptx # xml2epub markupsafe==2.1.1 - # via jinja2 + # via + # jinja2 + # werkzeug mock==4.0.3 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -269,6 +279,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -278,22 +289,28 @@ python-pptx==0.6.21 pytz==2022.6 # via django pyyaml==6.0 - # via drf-spectacular + # via + # drf-spectacular + # responses rapidfuzz==3.1.1 # via levenshtein reportlab==3.6.12 # via -r examples/requirements/common.in -requests==2.28.1 +requests==2.31.0 # via # azure-core # google-api-core # google-cloud-storage # gtts + # moto # msrest # requests-oauthlib + # responses # xml2epub requests-oauthlib==1.3.1 # via msrest +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.0 @@ -339,6 +356,8 @@ typer==0.3.2 # typer-cli typer-cli==0.0.12 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -349,6 +368,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses virtualenv==20.17.0 # via tox weasyprint==59.0 @@ -358,10 +378,14 @@ webencodings==0.5.1 # cssselect2 # html5lib # tinycss2 +werkzeug==3.0.0 + # via moto xlsxwriter==3.0.3 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zopfli==0.2.2 diff --git a/examples/requirements/django_3_2_and_flask.txt b/examples/requirements/django_3_2_and_flask.txt index c1e16139..f8b9dfca 100644 --- a/examples/requirements/django_3_2_and_flask.txt +++ b/examples/requirements/django_3_2_and_flask.txt @@ -34,10 +34,13 @@ bcrypt==4.0.1 beautifulsoup4==4.11.1 # via xml2epub boto3==1.26.36 - # via pathy + # via + # moto + # pathy botocore==1.29.36 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -75,6 +78,7 @@ cryptography==38.0.4 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -186,6 +190,7 @@ jinja2==3.1.2 # via # flask # flask-babelex + # moto # xml2epub jmespath==1.0.1 # via @@ -210,6 +215,8 @@ markupsafe==2.1.1 # wtforms mock==4.0.3 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -309,6 +316,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -320,22 +328,28 @@ pytz==2022.7 # babel # django pyyaml==6.0 - # via drf-spectacular + # via + # drf-spectacular + # responses rapidfuzz==3.1.1 # via levenshtein reportlab==3.6.12 # via -r examples/requirements/common.in -requests==2.28.1 +requests==2.31.0 # via # azure-core # google-api-core # google-cloud-storage # gtts + # moto # msrest # requests-oauthlib + # responses # xml2epub requests-oauthlib==1.3.1 # via msrest +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.0 @@ -387,6 +401,8 @@ typer==0.7.0 # via pathy typer-cli==0.0.1 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -397,6 +413,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses virtualenv==20.17.1 # via tox weasyprint==59.0 @@ -407,13 +424,17 @@ webencodings==0.5.1 # html5lib # tinycss2 werkzeug==2.2.3 - # via flask + # via + # flask + # moto wtforms==3.0.1 # via flask-admin xlsxwriter==3.0.3 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zipp==3.11.0 diff --git a/examples/requirements/django_4_0.txt b/examples/requirements/django_4_0.txt index 32f2139a..792bdffe 100644 --- a/examples/requirements/django_4_0.txt +++ b/examples/requirements/django_4_0.txt @@ -30,10 +30,13 @@ bcrypt==4.0.1 beautifulsoup4==4.11.1 # via xml2epub boto3==1.26.29 - # via pathy + # via + # moto + # pathy botocore==1.29.29 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -66,6 +69,7 @@ cryptography==38.0.4 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -153,7 +157,9 @@ iniconfig==1.1.1 isodate==0.6.1 # via msrest jinja2==3.1.2 - # via xml2epub + # via + # moto + # xml2epub jmespath==1.0.1 # via # boto3 @@ -168,9 +174,13 @@ lxml==4.9.1 # python-pptx # xml2epub markupsafe==2.1.1 - # via jinja2 + # via + # jinja2 + # werkzeug mock==4.0.3 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -269,6 +279,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -278,22 +289,28 @@ python-pptx==0.6.21 pytz==2022.7.1 # via djangorestframework pyyaml==6.0 - # via drf-spectacular + # via + # drf-spectacular + # responses rapidfuzz==3.1.1 # via levenshtein reportlab==3.6.12 # via -r examples/requirements/common.in -requests==2.28.1 +requests==2.31.0 # via # azure-core # google-api-core # google-cloud-storage # gtts + # moto # msrest # requests-oauthlib + # responses # xml2epub requests-oauthlib==1.3.1 # via msrest +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.0 @@ -339,6 +356,8 @@ typer==0.3.2 # typer-cli typer-cli==0.0.12 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -349,6 +368,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses virtualenv==20.17.0 # via tox weasyprint==59.0 @@ -358,10 +378,14 @@ webencodings==0.5.1 # cssselect2 # html5lib # tinycss2 +werkzeug==3.0.0 + # via moto xlsxwriter==3.0.3 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zopfli==0.2.2 diff --git a/examples/requirements/django_4_0_and_flask.txt b/examples/requirements/django_4_0_and_flask.txt index 5ec8aba5..be04ac15 100644 --- a/examples/requirements/django_4_0_and_flask.txt +++ b/examples/requirements/django_4_0_and_flask.txt @@ -34,10 +34,13 @@ bcrypt==4.0.1 beautifulsoup4==4.11.1 # via xml2epub boto3==1.26.36 - # via pathy + # via + # moto + # pathy botocore==1.29.36 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -75,6 +78,7 @@ cryptography==38.0.4 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -186,6 +190,7 @@ jinja2==3.1.2 # via # flask # flask-babelex + # moto # xml2epub jmespath==1.0.1 # via @@ -210,6 +215,8 @@ markupsafe==2.1.1 # wtforms mock==4.0.3 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -309,6 +316,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -320,22 +328,28 @@ pytz==2022.7 # babel # djangorestframework pyyaml==6.0 - # via drf-spectacular + # via + # drf-spectacular + # responses rapidfuzz==3.1.1 # via levenshtein reportlab==3.6.12 # via -r examples/requirements/common.in -requests==2.28.1 +requests==2.31.0 # via # azure-core # google-api-core # google-cloud-storage # gtts + # moto # msrest # requests-oauthlib + # responses # xml2epub requests-oauthlib==1.3.1 # via msrest +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.0 @@ -387,6 +401,8 @@ typer==0.7.0 # via pathy typer-cli==0.0.1 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -397,6 +413,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses virtualenv==20.17.1 # via tox weasyprint==59.0 @@ -407,13 +424,17 @@ webencodings==0.5.1 # html5lib # tinycss2 werkzeug==2.2.3 - # via flask + # via + # flask + # moto wtforms==3.0.1 # via flask-admin xlsxwriter==3.0.3 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zipp==3.11.0 diff --git a/examples/requirements/django_4_1.txt b/examples/requirements/django_4_1.txt index ca5f22ad..51b45581 100644 --- a/examples/requirements/django_4_1.txt +++ b/examples/requirements/django_4_1.txt @@ -30,10 +30,13 @@ bcrypt==4.0.1 beautifulsoup4==4.11.1 # via xml2epub boto3==1.26.29 - # via pathy + # via + # moto + # pathy botocore==1.29.29 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -66,6 +69,7 @@ cryptography==38.0.4 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -153,7 +157,9 @@ iniconfig==1.1.1 isodate==0.6.1 # via msrest jinja2==3.1.2 - # via xml2epub + # via + # moto + # xml2epub jmespath==1.0.1 # via # boto3 @@ -168,9 +174,13 @@ lxml==4.9.1 # python-pptx # xml2epub markupsafe==2.1.1 - # via jinja2 + # via + # jinja2 + # werkzeug mock==4.0.3 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -269,6 +279,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -278,22 +289,28 @@ python-pptx==0.6.21 pytz==2022.7.1 # via djangorestframework pyyaml==6.0 - # via drf-spectacular + # via + # drf-spectacular + # responses rapidfuzz==3.1.1 # via levenshtein reportlab==3.6.12 # via -r examples/requirements/common.in -requests==2.28.1 +requests==2.31.0 # via # azure-core # google-api-core # google-cloud-storage # gtts + # moto # msrest # requests-oauthlib + # responses # xml2epub requests-oauthlib==1.3.1 # via msrest +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.0 @@ -339,6 +356,8 @@ typer==0.3.2 # typer-cli typer-cli==0.0.12 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -349,6 +368,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses virtualenv==20.17.0 # via tox weasyprint==59.0 @@ -358,10 +378,14 @@ webencodings==0.5.1 # cssselect2 # html5lib # tinycss2 +werkzeug==3.0.0 + # via moto xlsxwriter==3.0.3 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zopfli==0.2.2 diff --git a/examples/requirements/django_4_1_and_flask.txt b/examples/requirements/django_4_1_and_flask.txt index dcdaec1a..44f796c7 100644 --- a/examples/requirements/django_4_1_and_flask.txt +++ b/examples/requirements/django_4_1_and_flask.txt @@ -34,10 +34,13 @@ bcrypt==4.0.1 beautifulsoup4==4.11.1 # via xml2epub boto3==1.26.36 - # via pathy + # via + # moto + # pathy botocore==1.29.36 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -75,6 +78,7 @@ cryptography==38.0.4 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -186,6 +190,7 @@ jinja2==3.1.2 # via # flask # flask-babelex + # moto # xml2epub jmespath==1.0.1 # via @@ -210,6 +215,8 @@ markupsafe==2.1.1 # wtforms mock==4.0.3 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -309,6 +316,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -320,22 +328,28 @@ pytz==2022.7 # babel # djangorestframework pyyaml==6.0 - # via drf-spectacular + # via + # drf-spectacular + # responses rapidfuzz==3.1.1 # via levenshtein reportlab==3.6.12 # via -r examples/requirements/common.in -requests==2.28.1 +requests==2.31.0 # via # azure-core # google-api-core # google-cloud-storage # gtts + # moto # msrest # requests-oauthlib + # responses # xml2epub requests-oauthlib==1.3.1 # via msrest +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.0 @@ -387,6 +401,8 @@ typer==0.7.0 # via pathy typer-cli==0.0.1 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -397,6 +413,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses virtualenv==20.17.1 # via tox weasyprint==59.0 @@ -407,13 +424,17 @@ webencodings==0.5.1 # html5lib # tinycss2 werkzeug==2.2.3 - # via flask + # via + # flask + # moto wtforms==3.0.1 # via flask-admin xlsxwriter==3.0.3 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zipp==3.11.0 diff --git a/examples/requirements/django_4_2.txt b/examples/requirements/django_4_2.txt index 9df431e6..a2b788c9 100644 --- a/examples/requirements/django_4_2.txt +++ b/examples/requirements/django_4_2.txt @@ -27,10 +27,13 @@ bcrypt==4.0.1 beautifulsoup4==4.12.2 # via xml2epub boto3==1.26.142 - # via pathy + # via + # moto + # pathy botocore==1.29.142 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -67,6 +70,7 @@ cryptography==40.0.2 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -154,7 +158,9 @@ iniconfig==2.0.0 isodate==0.6.1 # via azure-storage-blob jinja2==3.1.2 - # via xml2epub + # via + # moto + # xml2epub jmespath==1.0.1 # via # boto3 @@ -169,9 +175,13 @@ lxml==4.9.2 # python-pptx # xml2epub markupsafe==2.1.2 - # via jinja2 + # via + # jinja2 + # werkzeug mock==5.0.2 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in multidict==6.0.4 # via # aiohttp @@ -267,6 +277,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -274,7 +285,9 @@ python-levenshtein==0.21.0 python-pptx==0.6.21 # via -r examples/requirements/common.in pyyaml==6.0 - # via drf-spectacular + # via + # drf-spectacular + # responses rapidfuzz==3.1.1 # via levenshtein reportlab==3.6.12 @@ -285,7 +298,11 @@ requests==2.31.0 # google-api-core # google-cloud-storage # gtts + # moto + # responses # xml2epub +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.1 @@ -331,6 +348,8 @@ typer==0.7.0 # typer-cli typer-cli==0.0.13 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.6.2 # via # asgiref @@ -344,6 +363,7 @@ urllib3==1.26.16 # botocore # google-auth # requests + # responses virtualenv==20.23.0 # via tox weasyprint==59.0 @@ -353,10 +373,14 @@ webencodings==0.5.1 # cssselect2 # html5lib # tinycss2 +werkzeug==3.0.0 + # via moto xlsxwriter==3.1.2 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.9.2 # via aiohttp zopfli==0.2.2 diff --git a/examples/requirements/django_4_2_and_flask.txt b/examples/requirements/django_4_2_and_flask.txt index d5175019..aefac44e 100644 --- a/examples/requirements/django_4_2_and_flask.txt +++ b/examples/requirements/django_4_2_and_flask.txt @@ -33,10 +33,13 @@ beautifulsoup4==4.12.2 blinker==1.6.2 # via flask boto3==1.26.142 - # via pathy + # via + # moto + # pathy botocore==1.29.142 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -74,6 +77,7 @@ cryptography==40.0.2 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -183,6 +187,7 @@ jinja2==3.1.2 # via # flask # flask-babelex + # moto # xml2epub jmespath==1.0.1 # via @@ -207,6 +212,8 @@ markupsafe==2.1.2 # wtforms mock==5.0.2 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in multidict==6.0.4 # via # aiohttp @@ -302,6 +309,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -309,7 +317,9 @@ python-levenshtein==0.21.0 python-pptx==0.6.21 # via -r examples/requirements/common.in pyyaml==6.0 - # via drf-spectacular + # via + # drf-spectacular + # responses rapidfuzz==3.1.1 # via levenshtein reportlab==3.6.12 @@ -320,7 +330,11 @@ requests==2.31.0 # google-api-core # google-cloud-storage # gtts + # moto + # responses # xml2epub +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.1 @@ -376,6 +390,8 @@ typer==0.7.0 # typer-cli typer-cli==0.0.13 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.6.2 # via # alembic @@ -391,6 +407,7 @@ urllib3==1.26.16 # botocore # google-auth # requests + # responses virtualenv==20.23.0 # via tox weasyprint==59.0 @@ -401,13 +418,17 @@ webencodings==0.5.1 # html5lib # tinycss2 werkzeug==2.3.4 - # via flask + # via + # flask + # moto wtforms==3.0.1 # via flask-admin xlsxwriter==3.1.2 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.9.2 # via aiohttp zopfli==0.2.2 diff --git a/examples/requirements/docs.txt b/examples/requirements/docs.txt index 04c06fdd..b27ec589 100644 --- a/examples/requirements/docs.txt +++ b/examples/requirements/docs.txt @@ -34,10 +34,13 @@ bcrypt==4.0.1 beautifulsoup4==4.11.1 # via xml2epub boto3==1.26.29 - # via pathy + # via + # moto + # pathy botocore==1.29.29 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -70,6 +73,7 @@ cryptography==38.0.4 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -167,6 +171,7 @@ isodate==0.6.1 # via msrest jinja2==3.1.2 # via + # moto # rst2pdf # sphinx # xml2epub @@ -184,9 +189,13 @@ lxml==4.9.1 # python-pptx # xml2epub markupsafe==2.1.1 - # via jinja2 + # via + # jinja2 + # werkzeug mock==4.0.3 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -291,6 +300,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -304,6 +314,7 @@ pytz==2022.6 pyyaml==6.0 # via # drf-spectacular + # responses # rst2pdf rapidfuzz==3.1.1 # via levenshtein @@ -312,18 +323,22 @@ reportlab==3.3.0 # -r examples/requirements/common.in # -r examples/requirements/docs.in # rst2pdf -requests==2.28.1 +requests==2.31.0 # via # azure-core # google-api-core # google-cloud-storage # gtts + # moto # msrest # requests-oauthlib + # responses # sphinx # xml2epub requests-oauthlib==1.3.1 # via msrest +responses==0.23.3 + # via moto rsa==4.9 # via google-auth rst2pdf==0.99 @@ -396,6 +411,8 @@ typer==0.3.2 # typer-cli typer-cli==0.0.12 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -406,6 +423,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses virtualenv==20.17.0 # via tox weasyprint==59.0 @@ -415,10 +433,14 @@ webencodings==0.5.1 # cssselect2 # html5lib # tinycss2 +werkzeug==3.0.0 + # via moto xlsxwriter==3.0.3 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zipp==3.11.0 diff --git a/examples/requirements/flask.txt b/examples/requirements/flask.txt index 879e9674..c406d3f4 100644 --- a/examples/requirements/flask.txt +++ b/examples/requirements/flask.txt @@ -31,10 +31,13 @@ bcrypt==4.0.1 beautifulsoup4==4.11.1 # via xml2epub boto3==1.26.36 - # via pathy + # via + # moto + # pathy botocore==1.29.36 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -72,6 +75,7 @@ cryptography==38.0.4 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -161,6 +165,7 @@ jinja2==3.1.2 # via # flask # flask-babelex + # moto # xml2epub jmespath==1.0.1 # via @@ -183,6 +188,8 @@ markupsafe==2.1.1 # wtforms mock==4.0.3 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -280,6 +287,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -288,21 +296,27 @@ python-pptx==0.6.21 # via -r examples/requirements/common.in pytz==2022.7 # via babel +pyyaml==6.0.1 + # via responses rapidfuzz==3.1.1 # via levenshtein reportlab==3.6.12 # via -r examples/requirements/common.in -requests==2.28.1 +requests==2.31.0 # via # azure-core # google-api-core # google-cloud-storage # gtts + # moto # msrest # requests-oauthlib + # responses # xml2epub requests-oauthlib==1.3.1 # via msrest +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.0 @@ -350,6 +364,8 @@ typer==0.7.0 # via pathy typer-cli==0.0.1 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -358,6 +374,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses virtualenv==20.17.1 # via tox weasyprint==59.0 @@ -368,13 +385,17 @@ webencodings==0.5.1 # html5lib # tinycss2 werkzeug==2.2.3 - # via flask + # via + # flask + # moto wtforms==3.0.1 # via flask-admin xlsxwriter==3.0.3 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zipp==3.11.0 diff --git a/examples/requirements/ml.txt b/examples/requirements/ml.txt index 24ed222a..be9d23ce 100644 --- a/examples/requirements/ml.txt +++ b/examples/requirements/ml.txt @@ -29,10 +29,13 @@ beautifulsoup4==4.11.1 # gdown # xml2epub boto3==1.26.47 - # via pathy + # via + # moto + # pathy botocore==1.29.47 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -71,6 +74,7 @@ cryptography==39.0.0 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -143,7 +147,9 @@ iniconfig==2.0.0 isodate==0.6.1 # via msrest jinja2==3.1.2 - # via xml2epub + # via + # moto + # xml2epub jmespath==1.0.1 # via # boto3 @@ -156,9 +162,13 @@ lxml==4.9.2 # python-pptx # xml2epub markupsafe==2.1.1 - # via jinja2 + # via + # jinja2 + # werkzeug mock==5.0.1 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -279,6 +289,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto # pandas python-docx==0.8.11 # via -r examples/requirements/common.in @@ -291,6 +302,7 @@ pytz==2022.7 pyyaml==6.0 # via # huggingface-hub + # responses # transformers rapidfuzz==3.1.1 # via levenshtein @@ -298,7 +310,7 @@ regex==2022.10.31 # via transformers reportlab==3.6.12 # via -r examples/requirements/common.in -requests[socks]==2.28.1 +requests[socks]==2.31.0 # via # azure-core # gdown @@ -306,14 +318,18 @@ requests[socks]==2.28.1 # google-cloud-storage # gtts # huggingface-hub + # moto # msrest # nlpaug # requests-oauthlib + # responses # tika # transformers # xml2epub requests-oauthlib==1.3.1 # via msrest +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.0 @@ -369,6 +385,8 @@ typer==0.3.2 # typer-cli typer-cli==0.0.12 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -379,6 +397,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses virtualenv==20.17.1 # via tox weasyprint==59.0 @@ -388,6 +407,8 @@ webencodings==0.5.1 # cssselect2 # html5lib # tinycss2 +werkzeug==3.0.0 + # via moto wheel==0.38.4 # via # nvidia-cublas-cu11 @@ -396,6 +417,8 @@ xlsxwriter==3.0.6 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zopfli==0.2.2 diff --git a/examples/requirements/test.in b/examples/requirements/test.in index 4cb05538..74c9d02b 100644 --- a/examples/requirements/test.in +++ b/examples/requirements/test.in @@ -3,6 +3,7 @@ asyncssh coverage factory_boy fuzzywuzzy[speedup] +moto parametrize py pytest-cov diff --git a/examples/requirements/test.txt b/examples/requirements/test.txt index e8aef6b7..deb99bfa 100644 --- a/examples/requirements/test.txt +++ b/examples/requirements/test.txt @@ -8,14 +8,27 @@ asyncssh==2.13.1 # via -r examples/requirements/test.in attrs==22.1.0 # via pytest +boto3==1.28.62 + # via moto +botocore==1.31.62 + # via + # boto3 + # moto + # s3transfer +certifi==2023.7.22 + # via requests cffi==1.15.1 # via cryptography +charset-normalizer==3.3.0 + # via requests coverage[toml]==6.5.0 # via # -r examples/requirements/test.in # pytest-cov cryptography==41.0.1 - # via asyncssh + # via + # asyncssh + # moto distlib==0.3.6 # via virtualenv exceptiongroup==1.1.0 @@ -32,10 +45,24 @@ filelock==3.8.0 # virtualenv fuzzywuzzy[speedup]==0.18.0 # via -r examples/requirements/test.in +idna==3.4 + # via requests iniconfig==1.1.1 # via pytest +jinja2==3.1.2 + # via moto +jmespath==1.0.1 + # via + # boto3 + # botocore levenshtein==0.21.0 # via python-levenshtein +markupsafe==2.1.3 + # via + # jinja2 + # werkzeug +moto==4.2.5 + # via -r examples/requirements/test.in packaging==21.3 # via # pytest @@ -78,11 +105,24 @@ pytest-rerunfailures==11.0 pytest-rst==0.1.5 # via -r examples/requirements/test.in python-dateutil==2.8.2 - # via faker + # via + # botocore + # faker + # moto python-levenshtein==0.21.0 # via fuzzywuzzy +pyyaml==6.0.1 + # via responses rapidfuzz==3.1.1 # via levenshtein +requests==2.31.0 + # via + # moto + # responses +responses==0.23.3 + # via moto +s3transfer==0.7.0 + # via boto3 six==1.16.0 # via # python-dateutil @@ -96,7 +136,18 @@ tomli==2.0.1 # tox tox==3.27.1 # via -r examples/requirements/test.in +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.6.3 # via asyncssh +urllib3==2.0.6 + # via + # botocore + # requests + # responses virtualenv==20.17.0 # via tox +werkzeug==3.0.0 + # via moto +xmltodict==0.13.0 + # via moto diff --git a/examples/requirements/testing.txt b/examples/requirements/testing.txt index 1579a809..7c8396e8 100644 --- a/examples/requirements/testing.txt +++ b/examples/requirements/testing.txt @@ -30,10 +30,13 @@ bcrypt==4.0.1 beautifulsoup4==4.11.1 # via xml2epub boto3==1.26.29 - # via pathy + # via + # moto + # pathy botocore==1.29.29 # via # boto3 + # moto # s3transfer brotli==1.0.9 # via fonttools @@ -66,6 +69,7 @@ cryptography==38.0.4 # via # asyncssh # azure-storage-blob + # moto # paramiko cssselect2==0.7.0 # via weasyprint @@ -153,7 +157,9 @@ iniconfig==1.1.1 isodate==0.6.1 # via msrest jinja2==3.1.2 - # via xml2epub + # via + # moto + # xml2epub jmespath==1.0.1 # via # boto3 @@ -168,9 +174,13 @@ lxml==4.9.1 # python-pptx # xml2epub markupsafe==2.1.1 - # via jinja2 + # via + # jinja2 + # werkzeug mock==4.0.3 # via pathy +moto==4.2.5 + # via -r examples/requirements/test.in msrest==0.7.1 # via azure-storage-blob multidict==6.0.4 @@ -269,6 +279,7 @@ python-dateutil==2.8.2 # via # botocore # faker + # moto python-docx==0.8.11 # via -r examples/requirements/common.in python-levenshtein==0.21.0 @@ -278,22 +289,28 @@ python-pptx==0.6.21 pytz==2022.6 # via django pyyaml==6.0 - # via drf-spectacular + # via + # drf-spectacular + # responses rapidfuzz==3.1.1 # via levenshtein reportlab==3.6.12 # via -r examples/requirements/common.in -requests==2.28.1 +requests==2.31.0 # via # azure-core # google-api-core # google-cloud-storage # gtts + # moto # msrest # requests-oauthlib + # responses # xml2epub requests-oauthlib==1.3.1 # via msrest +responses==0.23.3 + # via moto rsa==4.9 # via google-auth s3transfer==0.6.0 @@ -339,6 +356,8 @@ typer==0.3.2 # typer-cli typer-cli==0.0.12 # via pathy +types-pyyaml==6.0.12.12 + # via responses typing-extensions==4.4.0 # via # asyncssh @@ -349,6 +368,7 @@ urllib3==1.26.13 # via # botocore # requests + # responses virtualenv==20.17.0 # via tox weasyprint==59.0 @@ -358,10 +378,14 @@ webencodings==0.5.1 # cssselect2 # html5lib # tinycss2 +werkzeug==3.0.0 + # via moto xlsxwriter==3.0.3 # via python-pptx xml2epub==2.6.2 # via -r examples/requirements/common.in +xmltodict==0.13.0 + # via moto yarl==1.8.2 # via aiohttp zopfli==0.2.2 diff --git a/examples/sqlalchemy_example/sqlalchemy_factories/faker_file_admin_upload.py b/examples/sqlalchemy_example/sqlalchemy_factories/faker_file_admin_upload.py index 554defbd..78606c20 100644 --- a/examples/sqlalchemy_example/sqlalchemy_factories/faker_file_admin_upload.py +++ b/examples/sqlalchemy_example/sqlalchemy_factories/faker_file_admin_upload.py @@ -2,9 +2,6 @@ from factory import Faker, LazyAttribute, Sequence, Trait from factory.alchemy import SQLAlchemyModelFactory -from faker_file_admin import db -from faker_file_admin.models import Upload - from faker_file.providers.bin_file import BinFileProvider from faker_file.providers.csv_file import CsvFileProvider from faker_file.providers.docx_file import DocxFileProvider @@ -28,6 +25,9 @@ from faker_file.providers.zip_file import ZipFileProvider from faker_file.storages.filesystem import FileSystemStorage +from faker_file_admin import db +from faker_file_admin.models import Upload + __all__ = ("UploadFactory",) # Faker._DEFAULT_LOCALE = "hy_AM" diff --git a/pyproject.toml b/pyproject.toml index 75f87b72..f7bfd161 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,9 +34,18 @@ force_grid_wrap = 0 use_parentheses = true ensure_newline_before_comments = true line_length = 80 -known_first_party = "faker_file" -known_third_party = ["django", "factory"] -skip = ["wsgi.py",] +#known_first_party = "faker_file" +known_first_party = [ + "upload", + "factories", + "project", + "faker_file_admin", + "instance", + "sqlalchemy_factories", + "marytts_mp3_generator", +] +known_third_party = ["django", "factory", "faker_file"] +skip = ["wsgi.py", "builddocs/"] [tool.ruff] line-length = 80 @@ -67,6 +76,7 @@ exclude = [ "node_modules", "venv", "examples/django_example/project/wsgi.py", + "docs", ] per-file-ignores = {} diff --git a/scripts/black.sh b/scripts/black.sh index 019128fe..d051de43 100755 --- a/scripts/black.sh +++ b/scripts/black.sh @@ -1,2 +1,6 @@ #!/usr/bin/env bash +#black conftest.py +#black setup.py +#black examples/ +#black src/ black . diff --git a/scripts/isort.sh b/scripts/isort.sh index b55e1663..a4b18a78 100755 --- a/scripts/isort.sh +++ b/scripts/isort.sh @@ -1,2 +1,6 @@ #!/usr/bin/env bash +#isort conftest.py --overwrite-in-place +#isort setup.py --overwrite-in-place +#isort examples/ --overwrite-in-place +#isort src/ --overwrite-in-place isort . --overwrite-in-place diff --git a/scripts/ruff.sh b/scripts/ruff.sh index a06ed39e..a1568b14 100755 --- a/scripts/ruff.sh +++ b/scripts/ruff.sh @@ -1,2 +1,5 @@ #!/usr/bin/env bash -ruff . +ruff conftest.py +ruff setup.py +ruff examples/ +ruff src/ diff --git a/scripts/serve_docs.sh b/scripts/serve_docs.sh new file mode 100755 index 00000000..76ebe8e7 --- /dev/null +++ b/scripts/serve_docs.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +cd builddocs/ +python -m http.server 5000 diff --git a/setup.cfg b/setup.cfg index f6b6719c..b7b4590d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,9 +11,12 @@ license-file = LICENSE.rst # doc8 configuration: https://pypi.org/project/doc8/ ignore-path = docs/_build, + builddocs/, examples/requirements/*.in, examples/requirements/*.txt, examples/django_example/project/static/*, + examples/django_example/project/media/tmp/*, src/faker_file.egg-info, + tmp/, max-line-length = 80 sphinx = true diff --git a/setup.py b/setup.py index 2e878b10..cf823c56 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import find_packages, setup -version = "0.17.8" +version = "0.17.9" try: readme = open(os.path.join(os.path.dirname(__file__), "README.rst")).read() @@ -28,6 +28,7 @@ "pytest-ordering", # pytest add-on "pytest-pythonpath", # pytest add-on "pytest-rst", # pytest add-on + "moto", # testing documentation ] _common = [ diff --git a/src/faker_file/__init__.py b/src/faker_file/__init__.py index 6bdc6e11..025eed84 100644 --- a/src/faker_file/__init__.py +++ b/src/faker_file/__init__.py @@ -1,5 +1,5 @@ __title__ = "faker_file" -__version__ = "0.17.8" +__version__ = "0.17.9" __author__ = "Artur Barseghyan " __copyright__ = "2022-2023 Artur Barseghyan" __license__ = "MIT" diff --git a/src/faker_file/tests/_conftest.py b/src/faker_file/tests/_conftest.py index a3ce3c69..5d4d5144 100644 --- a/src/faker_file/tests/_conftest.py +++ b/src/faker_file/tests/_conftest.py @@ -5,7 +5,6 @@ calls the `clean_up` method of the `FILE_REGISTRY` instance. """ import pytest - from faker_file.registry import FILE_REGISTRY __author__ = "Artur Barseghyan " diff --git a/src/faker_file/tests/test_django_integration.py b/src/faker_file/tests/test_django_integration.py index 48d4f450..e18f214c 100644 --- a/src/faker_file/tests/test_django_integration.py +++ b/src/faker_file/tests/test_django_integration.py @@ -1,6 +1,5 @@ from typing import Any, Callable, Dict -import factories from django.conf import settings from django.core.files.storage import default_storage from django.test import TestCase @@ -8,6 +7,8 @@ from parametrize import parametrize from storages.backends.s3boto3 import S3Boto3Storage +import factories + from ..registry import FILE_REGISTRY from ..storages.aws_s3 import AWSS3Storage from ..storages.filesystem import FileSystemStorage diff --git a/src/faker_file/tests/test_sqlalchemy_integration.py b/src/faker_file/tests/test_sqlalchemy_integration.py index 1baea524..cd9bbdb6 100644 --- a/src/faker_file/tests/test_sqlalchemy_integration.py +++ b/src/faker_file/tests/test_sqlalchemy_integration.py @@ -2,14 +2,15 @@ from unittest import TestCase import pytest -import sqlalchemy_factories as factories from faker import Faker -from faker_file_admin import app -from faker_file_admin.models import Upload from parametrize import parametrize from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker +import sqlalchemy_factories as factories +from faker_file_admin import app +from faker_file_admin.models import Upload + from ..registry import FILE_REGISTRY from ..storages.filesystem import FileSystemStorage