Skip to content

Commit

Permalink
Minor fixes in xml_file provider
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed May 11, 2023
1 parent d1e638b commit e2a2a1b
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"filename": "README.rst",
"hashed_secret": "077d5a0e0f8bb517307a6e92a73b0a9aa959233c",
"is_verified": true,
"line_number": 423
"line_number": 425
}
],
"examples/django_example/project/settings/base.py": [
Expand Down Expand Up @@ -149,5 +149,5 @@
}
]
},
"generated_at": "2023-05-06T22:40:52Z"
"generated_at": "2023-05-11T19:32:37Z"
}
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.14.5
------
2023-05-11

- Minor fixes in ``xml_file`` provider.

0.14.4
------
2023-05-11
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ Additional providers
- ``AugmentFileFromDirProvider``: Make an augmented copy of randomly picked
file from given directory. The following types are supported : ``DOCX``,
``EML``, ``EPUB``, ``ODT``, ``PDF``, ``RTF`` and ``TXT``.
- ``GenericFileProvider``: Create files in any format from a predefined
template.
- ``RandomFileFromDirProvider``: Pick a random file from given directory.

Supported file storages
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import find_packages, setup

version = "0.14.4"
version = "0.14.5"

try:
readme = open(os.path.join(os.path.dirname(__file__), "README.rst")).read()
Expand Down
2 changes: 1 addition & 1 deletion src/faker_file/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = "faker_file"
__version__ = "0.14.4"
__version__ = "0.14.5"
__author__ = "Artur Barseghyan <[email protected]>"
__copyright__ = "2022-2023 Artur Barseghyan"
__license__ = "MIT"
9 changes: 7 additions & 2 deletions src/faker_file/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
__all__ = (
"DEFAULT_AUDIO_MAX_NB_CHARS",
"DEFAULT_FILE_ENCODING",
"DEFAULT_FONT_NAME",
"DEFAULT_FONT_PATH",
"DEFAULT_IMAGE_MAX_NB_CHARS",
"DEFAULT_TEXT_CONTENT_TEMPLATE",
"DEFAULT_TEXT_MAX_NB_CHARS",
"DEFAULT_FONT_NAME",
"DEFAULT_FONT_PATH",
"DEFAULT_XML_DATA_COLUMNS",
)

DEFAULT_AUDIO_MAX_NB_CHARS = 500
Expand All @@ -18,3 +19,7 @@
DEFAULT_TEXT_MAX_NB_CHARS = 10_000
DEFAULT_FONT_NAME = "Vera"
DEFAULT_FONT_PATH = "Vera.ttf"
DEFAULT_XML_DATA_COLUMNS = {
"name": "{{name}}",
"address": "{{address}}",
}
15 changes: 3 additions & 12 deletions src/faker_file/providers/helpers/inner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,10 +1412,7 @@ def create_inner_xml_file(
generator: Optional[Union[Faker, Generator, Provider]] = None,
root_element: str = "root",
row_element: str = "row",
data_columns: Sequence[Tuple[str, str]] = (
("name", "{{name}}"),
("address", "{{address}}"),
),
data_columns: Optional[Dict[str, str]] = None,
num_rows: int = 10,
content: Optional[str] = None,
encoding: Optional[str] = None,
Expand All @@ -1433,10 +1430,7 @@ def create_inner_xml_file(
generator: Optional[Union[Faker, Generator, Provider]] = None,
root_element: str = "root",
row_element: str = "row",
data_columns: Sequence[Tuple[str, str]] = (
("name", "{{name}}"),
("address", "{{address}}"),
),
data_columns: Optional[Dict[str, str]] = None,
num_rows: int = 10,
content: Optional[str] = None,
encoding: Optional[str] = None,
Expand All @@ -1452,10 +1446,7 @@ def create_inner_xml_file(
generator: Optional[Union[Faker, Generator, Provider]] = None,
root_element: str = "root",
row_element: str = "row",
data_columns: Sequence[Tuple[str, str]] = (
("name", "{{name}}"),
("address", "{{address}}"),
),
data_columns: Optional[Dict[str, str]] = None,
num_rows: int = 10,
content: Optional[str] = None,
encoding: Optional[str] = None,
Expand Down
8 changes: 2 additions & 6 deletions src/faker_file/providers/xml_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from faker.providers import BaseProvider

from ..base import BytesValue, FileMixin, StringValue
from ..constants import DEFAULT_XML_DATA_COLUMNS
from ..storages.base import BaseStorage
from ..storages.filesystem import FileSystemStorage

Expand All @@ -13,7 +14,6 @@
__license__ = "MIT"
__all__ = ("XmlFileProvider",)


FAKER = Faker()


Expand Down Expand Up @@ -151,12 +151,8 @@ def xml_file(
self.generator = Faker()

if content is None:
default_data_columns = {
"name": "{{name}}",
"address": "{{address}}",
}
data_columns = (
data_columns if data_columns else default_data_columns
data_columns if data_columns else DEFAULT_XML_DATA_COLUMNS
)
root = ET.Element(root_element)
for _ in range(num_rows):
Expand Down
1 change: 1 addition & 0 deletions src/faker_file/tests/test_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ class ProvidersTestCase(unittest.TestCase):
(create_inner_txt_file, "Lorem ipsum", {}),
# (create_inner_webp_file, "Lorem ipsum", {}),
(create_inner_xlsx_file, None, {}),
(create_inner_xml_file, None, {}),
(create_inner_zip_file, None, {}),
(
fuzzy_choice_create_inner_file,
Expand Down

0 comments on commit e2a2a1b

Please sign in to comment.