arieb / python-testdata Goto Github PK
View Code? Open in Web Editor NEWA simple package that generates data for tests.
License: MIT License
A simple package that generates data for tests.
License: MIT License
CentOS 6.5
Python 2.6.6
Installed with pip install python-testdata
Example DictFactory code errors with the following:
/usr/bin/python /home/corey/PycharmProjects/test.py
Traceback (most recent call last):
File "/home/corey/PycharmProjects/test.py", line 14, in
for user in Users().generate(10): # let say we only want 10 users
File "/usr/lib/python2.6/site-packages/testdata/dictionary.py", line 27, in init
self._child_factories = deepcopy(self._child_factory_tree)
File "/usr/lib64/python2.6/copy.py", line 189, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib64/python2.6/copy.py", line 338, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib64/python2.6/copy.py", line 162, in deepcopy
y = copier(x, memo)
File "/usr/lib64/python2.6/copy.py", line 255, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib64/python2.6/copy.py", line 189, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib64/python2.6/copy.py", line 334, in _reconstruct
value = deepcopy(value, memo)
File "/usr/lib64/python2.6/copy.py", line 162, in deepcopy
y = copier(x, memo)
File "/usr/lib64/python2.6/copy.py", line 255, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib64/python2.6/copy.py", line 189, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib64/python2.6/copy.py", line 338, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib64/python2.6/copy.py", line 162, in deepcopy
y = copier(x, memo)
File "/usr/lib64/python2.6/copy.py", line 255, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib64/python2.6/copy.py", line 189, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib64/python2.6/copy.py", line 323, in _reconstruct
y = callable(*args)
File "/usr/lib64/python2.6/copy_reg.py", line 93, in newobj
return cls.new(cls, *args)
TypeError: instancemethod expected at least 2 arguments, got 0
Process finished with exit code 1
class Accounts(testdata.DictFactory):
id = testdata.CountingFactory(10)
first = testdata.FakeDataFactory('firstName')
last = testdata.FakeDataFactory('lastName')
address = testdata.FakeDataFactory('address')
age = testdata.RandomInteger(10, 30)
Accounts().generate(10)
raises this exception:
tdata/dictionary.py", line 27, in __init__
self._child_factories = deepcopy(self._child_factory_tree)
AttributeError: 'Accounts' object has no attribute '_child_factory_tree'
If you're running out of ideas: http://www.mockaroo.com/ has some more factory types ;)
Using Python 3.5.2 and 3.6.1 shows this error:
Traceback (most recent call last):
File "./testdata-gen.py", line 13, in
for user in Users().generate(4): # Generate 4 users
File "/anaconda/lib/python3.5/site-packages/testdata/dictionary.py", line 27, in init
self._child_factories = deepcopy(self._child_factory_tree)
AttributeError: 'Users' object has no attribute '_child_factory_tree'
$ python --version
Python 3.5.2 :: Anaconda 4.2.0 (x86_64)
Hello, is this project still active? Should I use another library? Do you need support?
Hi,
Can't get this to install on windows. I get the following:
File "C:\Python27\Lib\distutils\util.py", line 126, in convert_path
raise ValueError, "path '%s' cannot end with '/'" % pathname
ValueError: path './' cannot end with '/'
Hey,
I created some new number classes and wanted to share them. I might keep on working on some more.
With these classes it's possible to add / multiply multiple dependent fields and to create a RandomFloat where the maximum is dependent on another field.
class RelativeNumberAddFields(DependentField):
"""
Returns a number relative to another number field.
Example:
>>> import testdata
>>> class Foo(testdata.DictFactory):
... a = testdata.CountingFactory(1)
b = testdata.CountingFactory(5)
c = testdata.CountingFactory(10)
... d = testdata.RelativeNumberAdd('a', 'b', 'c')
>>> [i for i in Foo().generate(3)]
[{'a': 1, 'b': 5, 'c': 10, 'd': 16},
{'a': 2, 'b': 6, 'c': 11, 'd': 19},
{'a': 3, 'b': 7, 'c': 12, 'd': 22}]
"""
def __init__(self, *args):
super(RelativeNumberAddFields, self).__init__(args)
self._args = args
def __call__(self):
super(RelativeNumberAddFields, self).__call__()
result = 0
for value in self._args:
result += self.depending_fields[value]
return result
class RelativeNumberMultiplyFields(DependentField):
"""
Returns a number relative to another number field.
Example:
>>> import testdata
>>> class Foo(testdata.DictFactory):
... a = testdata.CountingFactory(1)
b = testdata.CountingFactory(5)
c = testdata.CountingFactory(10)
... d = testdata.RelativeNumberAdd('a', 'b', 'c')
>>> [i for i in Foo().generate(3)]
[{'a': 1, 'b': 5, 'c': 10, 'd': 50},
{'a': 2, 'b': 6, 'c': 11, 'd': 132},
{'a': 3, 'b': 7, 'c': 12, 'd': 252}]
"""
def __init__(self, *args):
super(RelativeNumberMultiplyFields, self).__init__(args)
self._args = args
def __call__(self):
super(RelativeNumberMultiplyFields, self).__call__()
result = 1
for value in self._args:
result = result * self.depending_fields[value]
return result
class ConditionalMaxRandomFloat(DependentField):
"""
Returns a Float between `minimum` and `maximum`
"""
def __init__(self, minimum, maximum):
super(ConditionalMaxRandomFloat, self).__init__([maximum])
self._maximum = maximum
self._minimum = minimum
def __call__(self):
super(ConditionalMaxRandomFloat, self).__call__()
return (random.random() * (self.depending_fields[self._maximum] - self._minimum)) + self._minimum
To make debugging easier, I like to generate OrderedDict
objects, so my eyes can easily scan to where various fields "should be" and do rapid visual inspection. The randomizing effect of dict
objects makes this harder.
So I suggest an OrderedDictFactory
subclass to DictFactory
.
Also, I did not see a quick way to interrogate a DictFactory
object as to what fields it would be generating. That too would be handy.
The 1.0.5 code has a different fake-factory requirement in setup.py for the PyPi versus GitHub version.
In the PyPi version it has:
'fake-factory == 0.2'
In the GitHub version it has:
'fake-factory == 0.3.2'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.