Coder Social home page Coder Social logo

python-testdata's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-testdata's Issues

Example Code Generates Exception

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

Example code fails in python 3.6

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'

dictionary.py attribute error

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)

still active?

Hello, is this project still active? Should I use another library? Do you need support?

Pip Install not working on windows

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 '/'

Some new number classes

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

Suggestion: OrderedDictFactory

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.

fake-factory version out of sync

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'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.