def test_instMethod(self):
     Wrapped = utilitytypes.proxyClass(self.MyClass, 'Wrapped',
                                       dataAttrName='_data', makeDefaultInit=True)
     wrappedResult = Wrapped('bar').instMeth()
     myClassResult = self.MyClass('bar').instMeth()
     self.assertEqual(wrappedResult[0].__class__, myClassResult[0].__class__)
     self.assertEqual(wrappedResult[1], myClassResult[1])
Beispiel #2
0
 def test_wrapData(self):
     Wrapped = utilitytypes.proxyClass(self.MyClass,
                                       'Wrapped',
                                       dataAttrName='_data',
                                       makeDefaultInit=True)
     self.assertEqual(Wrapped.data, self.MyClass.data)
     self.assertEqual(Wrapped('foo').data, self.MyClass('foo').data)
 def test_instMethod(self):
     Wrapped = utilitytypes.proxyClass(self.MyClass, 'Wrapped',
                                       dataAttrName='_data', makeDefaultInit=True)
     wrappedResult = Wrapped('bar').instMeth()
     myClassResult = self.MyClass('bar').instMeth()
     self.assertEqual(wrappedResult[0].__class__, myClassResult[0].__class__)
     self.assertEqual(wrappedResult[1], myClassResult[1])
Beispiel #4
0
    def test_immutable(self):

        Wrapped = utilitytypes.proxyClass(''.__class__,
                                          'Wrapped',
                                          dataAttrName='_data',
                                          makeDefaultInit=True)
        self.assertEqual(
            Wrapped('Fun times were had by all')[3:7],
            'Fun times were had by all'[3:7])
 def test_unboundMethodDescriptor(self):
     """
     Some built-in types have fun things called method descriptors...
     ...they're like methods, but not!
     """
     Wrapped = utilitytypes.proxyClass(''.__class__, 'Wrapped',
                                       dataAttrName='_data', makeDefaultInit=True)
     theString = 'Fun times were had by all!'
     wrapInst = Wrapped(theString)
     self.assertEqual(Wrapped.__len__(wrapInst), len(theString))
 def test_unboundMethodDescriptor(self):
     """
     Some built-in types have fun things called method descriptors...
     ...they're like methods, but not!
     """
     Wrapped = utilitytypes.proxyClass(''.__class__, 'Wrapped',
                                       dataAttrName='_data', makeDefaultInit=True)
     theString = 'Fun times were had by all!'
     wrapInst = Wrapped(theString)
     self.assertEqual(Wrapped.__len__(wrapInst), len(theString))
 def test_unboundMethod(self):
     """
     We should be able to do MyProxyClass.wrappedMethod(myProxyClassInst)
     """
     Wrapped = utilitytypes.proxyClass(self.MyClass, 'Wrapped',
                                       dataAttrName='_data', makeDefaultInit=True)
     wrapInst = Wrapped('bar')
     wrappedResult = Wrapped.instMeth(wrapInst)
     myClassResult = self.MyClass('bar').instMeth()
     self.assertEqual(wrappedResult[0].__class__, myClassResult[0].__class__)
     self.assertEqual(wrappedResult[1], myClassResult[1])
 def test_unboundMethod(self):
     """
     We should be able to do MyProxyClass.wrappedMethod(myProxyClassInst)
     """
     Wrapped = utilitytypes.proxyClass(self.MyClass, 'Wrapped',
                                       dataAttrName='_data', makeDefaultInit=True)
     wrapInst = Wrapped('bar')
     wrappedResult = Wrapped.instMeth(wrapInst)
     myClassResult = self.MyClass('bar').instMeth()
     self.assertEqual(wrappedResult[0].__class__, myClassResult[0].__class__)
     self.assertEqual(wrappedResult[1], myClassResult[1])
Beispiel #9
0
def pytest_test(argv, **kwargs):
    import pytest
    argv[0] = 'pytest'
    argv[1:1] = ['-vv', '--doctest-modules']  # verbose
    origStdOut = sys.stdout
    wrappedStdout = None
    if inGui():
        # maya's own stdout redirection messes with pytest's... disable it
        argv.insert(1, '--capture=no')

        # also, pytest will try to query if sys.stdout is a tty, but Maya's
        # output redirector has no "isatty" method...
        stdoutType = type(sys.stdout)
        if isMayaOutput(stdoutType) and not hasattr(stdoutType, 'isatty'):
            # maya.Output is a compiled / builtin object, so we can't assign
            # to it's "isatty" or it's __class__ - so use a proxy class..
            from pymel.util.utilitytypes import proxyClass
            _ProxyMayaOutput = proxyClass(stdoutType,
                                          '_ProxyMayaOutput',
                                          dataAttrName='_mayaOutput')

            class ProxyMayaOutput(_ProxyMayaOutput):
                def __init__(self, toWrap):
                    self._mayaOutput = toWrap

                def isatty(self):
                    return False

            wrappedStdout = ProxyMayaOutput(sys.stdout)

    exclude_modules = get_exclude_modules()
    argv.extend('--ignore={}'.format(x) for x in exclude_modules)

    # the test excludes are handled by conftest.py, since I couldn't find
    # a way to exclude them from the "command line"
    print " ".join(pipes.quote(x) for x in argv)

    if wrappedStdout is not None:
        sys.stdout = wrappedStdout
    try:
        pytest.main(args=argv[1:])
    finally:
        if wrappedStdout is not None:
            sys.stdout = origStdOut
 def test_immutable(self):
     
     Wrapped = utilitytypes.proxyClass(''.__class__, 'Wrapped',
                                       dataAttrName='_data', makeDefaultInit=True)
     self.assertEqual(Wrapped('Fun times were had by all')[3:7],
                      'Fun times were had by all'[3:7])
 def test_docString(self):
     Wrapped = utilitytypes.proxyClass(self.MyClass, 'Wrapped',
                                       dataAttrName='_data', makeDefaultInit=True)
     self.assertEqual(Wrapped.__doc__, self.MyClass.__doc__)
 def test_staticMethod(self):
     Wrapped = utilitytypes.proxyClass(self.MyClass, 'Wrapped',
                                       dataAttrName='_data', makeDefaultInit=True)
     self.assertEqual(Wrapped.statMeth(), self.MyClass.statMeth())
 def test_wrapData(self):
     Wrapped = utilitytypes.proxyClass(self.MyClass, 'Wrapped',
                                       dataAttrName='_data', makeDefaultInit=True)
     self.assertEqual(Wrapped.data, self.MyClass.data)
     self.assertEqual(Wrapped('foo').data, self.MyClass('foo').data)
Beispiel #14
0
def pytest_test(argv, doctest=True, warnings=True):
    import pytest
    import warnings as warnings_mod

    new_args = [
        'pytest',
        '-vv',  # verbose
        '-rfE',  # print summary with (f)ailed and (E)rror
    ]
    if doctest:
        new_args.append('--doctest-modules')
    argv[0:1] = new_args

    if not warnings:
        argv.append('--disable-warnings')
    elif warnings == 'errors':
        # TODO: possibly get rid of our own flag entirely, and require
        # pytest >= 3.1?

        # what we do depends on pytest version - pytest >= 3.1 has it's own
        # controls for handling warnings, and trying to handle them ourselves
        # will get overridden by pytest
        pytest_ver = pytest.__version__.split('.')
        pytest_ver = tuple(int(x) if x.isdigit() else x for x in pytest_ver)
        if pytest_ver >= (3, 1):
            argv.extend(['-W', 'error::PendingDeprecationWarning'])
            argv.extend(['-W', 'error::DeprecationWarning'])
            argv.extend(['-W', 'error::FutureWarning'])
        else:
            warnings_mod.simplefilter("error", PendingDeprecationWarning)
            warnings_mod.simplefilter("error", DeprecationWarning)
            warnings_mod.simplefilter("error", FutureWarning)

    origStdOut = sys.stdout
    wrappedStdout = None
    if inGui():
        # maya's own stdout redirection messes with pytest's... disable it
        argv.insert(1, '--capture=no')

        # also, pytest will try to query if sys.stdout is a tty, but Maya's
        # output redirector has no "isatty" method...
        stdoutType = type(sys.stdout)
        if isMayaOutput(stdoutType) and not hasattr(stdoutType, 'isatty'):
            # maya.Output is a compiled / builtin object, so we can't assign
            # to it's "isatty" or it's __class__ - so use a proxy class..
            from pymel.util.utilitytypes import proxyClass
            _ProxyMayaOutput = proxyClass(stdoutType,
                                          '_ProxyMayaOutput',
                                          dataAttrName='_mayaOutput')

            class ProxyMayaOutput(_ProxyMayaOutput):
                def __init__(self, toWrap):
                    self._mayaOutput = toWrap

                def isatty(self):
                    return False

            wrappedStdout = ProxyMayaOutput(sys.stdout)

    exclude_modules = get_exclude_modules()
    argv.extend('--ignore={}'.format(x) for x in exclude_modules)

    # the test excludes are handled by conftest.py, since I couldn't find
    # a way to exclude them from the "command line"
    print(" ".join(pipes.quote(x) for x in argv))

    if wrappedStdout is not None:
        sys.stdout = wrappedStdout
    try:
        return pytest.main(args=argv[1:])
    finally:
        if wrappedStdout is not None:
            sys.stdout = origStdOut
Beispiel #15
0
 def test_docString(self):
     Wrapped = utilitytypes.proxyClass(self.MyClass,
                                       'Wrapped',
                                       dataAttrName='_data',
                                       makeDefaultInit=True)
     self.assertEqual(Wrapped.__doc__, self.MyClass.__doc__)
Beispiel #16
0
 def test_staticMethod(self):
     Wrapped = utilitytypes.proxyClass(self.MyClass,
                                       'Wrapped',
                                       dataAttrName='_data',
                                       makeDefaultInit=True)
     self.assertEqual(Wrapped.statMeth(), self.MyClass.statMeth())