Skip to content

Commit

Permalink
Add built-in provider: RegexProvider at 2024-07-05T17:23:57+0800
Browse files Browse the repository at this point in the history
  • Loading branch information
miyuki-shirogane committed Jul 5, 2024
1 parent d36ab70 commit d271548
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pistol_magazine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
from .data_exporter.json_ex import JSONExporter
from .data_exporter.xml_ex import XMLExporter
from .data_exporter.db_ex import DBExporter

from .built_in_provider.cyclic_parameter import CyclicParameterProvider
from .built_in_provider.fixed_value import FixedValueProvider
from .built_in_provider.random_choice_from_list import RandomChoiceFromListProvider
from .built_in_provider.random_float_in_range import RandomFloatInRangeProvider
from .built_in_provider.incremental_value import IncrementalValueProvider
from .built_in_provider.regex import RegexProvider

__all__ = [
'Datetime',
Expand Down Expand Up @@ -54,4 +56,5 @@
'RandomChoiceFromListProvider',
'RandomFloatInRangeProvider',
'IncrementalValueProvider',
'RegexProvider'
]
23 changes: 23 additions & 0 deletions pistol_magazine/built_in_provider/regex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import rstr
from pistol_magazine import DataMocker


class RegexProvider(DataMocker):
def __init__(self, pattern):
"""
This class generates values that match a given regular expression pattern.
Args:
pattern: The regular expression pattern to generate matching values for.
"""
super().__init__()
self.pattern = pattern

def get_value(self):
"""
Returns a value generated to match the regular expression pattern.
Returns:
A string value that matches the regular expression pattern.
"""
return rstr.xeger(self.pattern)
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Faker==25.1.0
setuptools~=59.0.1
dicttoxml~=1.7.16
PyMySQL~=1.0.2
PyMySQL~=1.0.2
pytest~=6.2.4
rstr~=3.2.2

0 comments on commit d271548

Please sign in to comment.