Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

python-testdata

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

python-testdata - pypi Package Compare versions

Comparing version
1.0.0
to
1.0.1
+49
-3
PKG-INFO
Metadata-Version: 1.1
Name: python-testdata
Version: 1.0.0
Version: 1.0.1
Summary: A small package that helps generate content to fill databases for tests.

@@ -18,5 +18,15 @@ Home-page: http://github.com/arieb/python-testdata

The DictFactory is especially useful if you want to generate data that you will later input to your NoSQL, Document based
database
In addition, using the DictFactory and the DependentField factories allows us to create factorys that depend on the results
of other factories. (see Examples for more information).
testdata isn't bound to a specifc database, but does include database specfic modules inside, like - extra.mongodb.py)
but it will always be clean of database related dependencies.
## Installation
pip install python-testdata
## Examples

@@ -38,3 +48,3 @@ We integrate the awsome fake-factory package to generate data using FakeDataFactory.

for user in Users(10): # let say we only want 10 users
for user in Users().generate(10): # let say we only want 10 users
print user

@@ -46,4 +56,40 @@ # {'firstname': 'Toni', 'lastname': 'Schaden', 'gender': 'female', 'age': 18, 'address': '0641 Homenick Hills\nSouth Branson, RI 70388', 'id': 10}

When creating our own subclasses for DictFactory, we can make some fields dependent on other fields.
for example:
```
class ExampleFactory(DictFactory):
a = CountingFactory(10)
b = ClonedField("a") # b will have the same value as field 'a'
for e in ExampleFactory().generate(100):
print e
# {'a': 10, 'b': 10}
# {'a': 11, 'b': 11}
# ...
```
Lets say we want to generate something like events data, we want events to have
a start time, and an end time that will be 20 minutes in the future.
In addition, we want the event's start_time will be 12 minutes apart.
```python
import testdata
EVENT_TYPES = ["USER_DISCONNECT", "USER_CONNECTED", "USER_LOGIN", "USER_LOGOUT"]
class EventsFactory(testdata.DictFactory):
start_time = testdata.DateIntervalFactory(datetime.datetime.now(), datetime.timedelta(minutes=12))
end_time = testdata.RelativeToDatetimeField("start_time", datetime.timedelta(minutes=20))
event_code = testdata.RandomSelection(EVENT_TYPES)
for event in EventFactory().generate(100):
print event
# {'start_time': datetime.datetime(2013, 12, 23, 13, 37, 1, 591878), 'end_time': datetime.datetime(2013, 12, 23, 13, 57, 1, 591878), 'event_code': 'USER_CONNECTED'}
# {'start_time': datetime.datetime(2013, 12, 23, 13, 49, 1, 591878), 'end_time': datetime.datetime(2013, 12, 23, 14, 9, 1, 591878), 'event_code': 'USER_LOGIN'}
# {'start_time': datetime.datetime(2013, 12, 23, 14, 1, 1, 591878), 'end_time': datetime.datetime(2013, 12, 23, 14, 21, 1, 591878), 'event_code': 'USER_DISCONNECT'}
```
## Factories
See Docstrings for more examples and doctests.
See the Factorie's Docstrings for more examples and doctests.

@@ -50,0 +96,0 @@ #### Bases

Metadata-Version: 1.1
Name: python-testdata
Version: 1.0.0
Version: 1.0.1
Summary: A small package that helps generate content to fill databases for tests.

@@ -18,5 +18,15 @@ Home-page: http://github.com/arieb/python-testdata

The DictFactory is especially useful if you want to generate data that you will later input to your NoSQL, Document based
database
In addition, using the DictFactory and the DependentField factories allows us to create factorys that depend on the results
of other factories. (see Examples for more information).
testdata isn't bound to a specifc database, but does include database specfic modules inside, like - extra.mongodb.py)
but it will always be clean of database related dependencies.
## Installation
pip install python-testdata
## Examples

@@ -38,3 +48,3 @@ We integrate the awsome fake-factory package to generate data using FakeDataFactory.

for user in Users(10): # let say we only want 10 users
for user in Users().generate(10): # let say we only want 10 users
print user

@@ -46,4 +56,40 @@ # {'firstname': 'Toni', 'lastname': 'Schaden', 'gender': 'female', 'age': 18, 'address': '0641 Homenick Hills\nSouth Branson, RI 70388', 'id': 10}

When creating our own subclasses for DictFactory, we can make some fields dependent on other fields.
for example:
```
class ExampleFactory(DictFactory):
a = CountingFactory(10)
b = ClonedField("a") # b will have the same value as field 'a'
for e in ExampleFactory().generate(100):
print e
# {'a': 10, 'b': 10}
# {'a': 11, 'b': 11}
# ...
```
Lets say we want to generate something like events data, we want events to have
a start time, and an end time that will be 20 minutes in the future.
In addition, we want the event's start_time will be 12 minutes apart.
```python
import testdata
EVENT_TYPES = ["USER_DISCONNECT", "USER_CONNECTED", "USER_LOGIN", "USER_LOGOUT"]
class EventsFactory(testdata.DictFactory):
start_time = testdata.DateIntervalFactory(datetime.datetime.now(), datetime.timedelta(minutes=12))
end_time = testdata.RelativeToDatetimeField("start_time", datetime.timedelta(minutes=20))
event_code = testdata.RandomSelection(EVENT_TYPES)
for event in EventFactory().generate(100):
print event
# {'start_time': datetime.datetime(2013, 12, 23, 13, 37, 1, 591878), 'end_time': datetime.datetime(2013, 12, 23, 13, 57, 1, 591878), 'event_code': 'USER_CONNECTED'}
# {'start_time': datetime.datetime(2013, 12, 23, 13, 49, 1, 591878), 'end_time': datetime.datetime(2013, 12, 23, 14, 9, 1, 591878), 'event_code': 'USER_LOGIN'}
# {'start_time': datetime.datetime(2013, 12, 23, 14, 1, 1, 591878), 'end_time': datetime.datetime(2013, 12, 23, 14, 21, 1, 591878), 'event_code': 'USER_DISCONNECT'}
```
## Factories
See Docstrings for more examples and doctests.
See the Factorie's Docstrings for more examples and doctests.

@@ -50,0 +96,0 @@ #### Bases

@@ -10,5 +10,15 @@ python-testdata

The DictFactory is especially useful if you want to generate data that you will later input to your NoSQL, Document based
database
In addition, using the DictFactory and the DependentField factories allows us to create factorys that depend on the results
of other factories. (see Examples for more information).
testdata isn't bound to a specifc database, but does include database specfic modules inside, like - extra.mongodb.py)
but it will always be clean of database related dependencies.
## Installation
pip install python-testdata
## Examples

@@ -30,3 +40,3 @@ We integrate the awsome fake-factory package to generate data using FakeDataFactory.

for user in Users(10): # let say we only want 10 users
for user in Users().generate(10): # let say we only want 10 users
print user

@@ -38,4 +48,40 @@ # {'firstname': 'Toni', 'lastname': 'Schaden', 'gender': 'female', 'age': 18, 'address': '0641 Homenick Hills\nSouth Branson, RI 70388', 'id': 10}

When creating our own subclasses for DictFactory, we can make some fields dependent on other fields.
for example:
```
class ExampleFactory(DictFactory):
a = CountingFactory(10)
b = ClonedField("a") # b will have the same value as field 'a'
for e in ExampleFactory().generate(100):
print e
# {'a': 10, 'b': 10}
# {'a': 11, 'b': 11}
# ...
```
Lets say we want to generate something like events data, we want events to have
a start time, and an end time that will be 20 minutes in the future.
In addition, we want the event's start_time will be 12 minutes apart.
```python
import testdata
EVENT_TYPES = ["USER_DISCONNECT", "USER_CONNECTED", "USER_LOGIN", "USER_LOGOUT"]
class EventsFactory(testdata.DictFactory):
start_time = testdata.DateIntervalFactory(datetime.datetime.now(), datetime.timedelta(minutes=12))
end_time = testdata.RelativeToDatetimeField("start_time", datetime.timedelta(minutes=20))
event_code = testdata.RandomSelection(EVENT_TYPES)
for event in EventFactory().generate(100):
print event
# {'start_time': datetime.datetime(2013, 12, 23, 13, 37, 1, 591878), 'end_time': datetime.datetime(2013, 12, 23, 13, 57, 1, 591878), 'event_code': 'USER_CONNECTED'}
# {'start_time': datetime.datetime(2013, 12, 23, 13, 49, 1, 591878), 'end_time': datetime.datetime(2013, 12, 23, 14, 9, 1, 591878), 'event_code': 'USER_LOGIN'}
# {'start_time': datetime.datetime(2013, 12, 23, 14, 1, 1, 591878), 'end_time': datetime.datetime(2013, 12, 23, 14, 21, 1, 591878), 'event_code': 'USER_DISCONNECT'}
```
## Factories
See Docstrings for more examples and doctests.
See the Factorie's Docstrings for more examples and doctests.

@@ -42,0 +88,0 @@ #### Bases

+2
-3

@@ -26,5 +26,4 @@ try:

db = client[database]
self._collection = db[collection]
self._field_name = field_name
possible_values = self._collection.find(filter_query).distinct(field_name)
collection = db[collection]
possible_values = collection.find(filter_query).distinct(field_name)
super(FieldFromCollection, self).__init__(possible_values)
from copy import deepcopy
import random
import operator

@@ -69,1 +70,29 @@

factory.set_element_amount(new_element_amount)
class RandomLengthListFactory(Factory):
"""
A factory that returns on each iteration a list of of between `min` and `max` items, returned
from calls to the given factory.
Example,
>> import testdata
>> f = RandomLengthListFactory(testdata.CountingFactory(1), 3, 8).generate(5)
>> list(f)
[[1, 2, 3], [4, 5, 6, 7], [8, 9, 10], [11, 12,13, 14, 15]]
"""
def __init__(self, factory=None, min_items=0, max_items=1):
super(RandomLengthListFactory, self).__init__()
self._factory = factory
self._min_items = min_items
self._max_items = max_items
def __iter__(self):
self._factory = iter(self._factory)
return super(RandomLengthListFactory, self).__iter__()
def set_element_amount(self, element_amount):
super(RandomLengthListFactory, self).set_element_amount(element_amount)
self._factory.set_element_amount(element_amount * self._max_items)
def __call__(self):
return [self._factory.next() for i in xrange(random.randint(self._min_items, self._max_items))]

@@ -6,2 +6,5 @@ import random

class RandomNumber(Factory):
"""
A base factory for generating a number between `minimum` and `maximum`.
"""
def __init__(self, minimum=0, maximum=0):

@@ -13,2 +16,5 @@ super(RandomNumber, self).__init__()

class RandomInteger(RandomNumber):
"""
Returns an Integer between `minimum` and `maximum`
"""
def __call__(self):

@@ -18,2 +24,5 @@ return random.randint(self._minimum, self._maximum)

class RandomFloat(RandomNumber):
"""
Returns a Float between `minimum` and `maximum`
"""
def __call__(self):

@@ -23,2 +32,13 @@ return (random.random() * (self._maximum - self._minimum)) + self._minimum

class RelativeNumber(DependentField):
"""
Returns a number relative to another number field.
Example:
>>> import testdata
>>> class Foo(testdata.DictFactory):
... a = testdata.CountingFactory(1)
... b = RelativeNumber('a', 1)
>>> [i for i in Foo().generate(3)]
[{'a': 1, 'b': 2}, {'a': 2, 'b': 3}, {'a': 3, 'b': 4}]
"""
def __init__(self, other_number_field, delta):

@@ -25,0 +45,0 @@ super(RelativeNumber, self).__init__([other_number_field])

@@ -1,1 +0,1 @@

1.0.0
1.0.1