Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test():
'''Test cute-(un)pickling on various objects.'''
if not import_tools.exists('multiprocessing'):
raise nose.SkipTest('`multiprocessing` is not installed.')
import multiprocessing
totally_pickleable_things = [
[1, 2, (3, 4)],
{1: 2, 3: set((1, 2, 3))},
None, True, False,
(1, 2, 'meow'),
'qweqweqasd',
PickleableObject()
]
thing = Object()
thing.a, thing.b, thing.c, thing.d, thing.e, thing.f, thing.g, thing.h = \
totally_pickleable_things
from __future__ import print_function
import sys
import pickle # noqa
import timeit
import rpyc
import unittest
from nose import SkipTest
import cfg_tests
try:
import pandas as pd
import numpy as np
except Exception:
raise SkipTest("Requires pandas, numpy, and tables")
DF_ROWS = 2000
DF_COLS = 2500
class MyService(rpyc.Service):
on_connect_called = False
on_disconnect_called = False
def on_connect(self, conn):
self.on_connect_called = True
def on_disconnect(self, conn):
self.on_disconnect_called = True
def test_file_permission_copy():
if sys.platform == "win32":
raise SkipTest("No actual chmod on windows")
test_source = "test_file_permission_copy1"
test_dest = "test_file_permission_copy2"
create_file(test_source, 0o755)
create_file(test_dest, 0o646)
file_system.file_permissions_copy(test_source, test_dest)
eq_(
stat.S_IMODE(os.lstat(test_source).st_mode),
stat.S_IMODE(os.lstat(test_dest).st_mode),
)
os.unlink(test_source)
os.unlink(test_dest)
def prepare_folder(
self,
prepare_files=True,
broken_symlink=False,
invalid_permissions=False,
use_file_versions_info=False
):
assert not (broken_symlink and invalid_permissions)
if platform.system() == 'Windows':
raise SkipTest(
'on Windows there are some environment issues with test directory creation'
)
if prepare_files:
for relative_path in self.NAMES:
self.prepare_file(relative_path)
if broken_symlink:
os.symlink(
os.path.join(self.root_dir, 'non_existant_file'),
os.path.join(self.root_dir, 'bad_symlink')
)
elif invalid_permissions:
os.chmod(os.path.join(self.root_dir, self.NAMES[0]), 0)
return LocalFolder(self.root_dir)
def _skip_if_no_pandas():
try:
import pandas # noqa
except ImportError:
import nose
raise nose.SkipTest("no pandas module")
def testCMVN2D_mu2(seed):
if backend_name() != "lite": raise SkipTest("CMVN in lite only")
ripl = get_ripl(seed=seed)
ripl.assume("m0","(array 5.0 5.0)")
ripl.assume("k0","7.0")
ripl.assume("v0","11.0")
ripl.assume("S0","(matrix (array (array 13.0 0.0) (array 0.0 13.0)))")
ripl.assume("f","(make_niw_normal m0 k0 v0 S0)")
ripl.predict("(f)",label="pid")
predictions = collectSamples(ripl,"pid")
mu2 = [p[1] for p in predictions]
return reportKnownMean(5, mu2)
def test_set_locale(self):
raise SkipTest('Not implemented yet')
def test_monkeypatch_classmethod_subclass():
'''
Test `monkeypatch_method` on a subclass of `classmethod`.
This is useful in Django, that uses its own `classmethod` subclass.
'''
if sys.version[:2] <= (2, 6):
raise nose.SkipTest('Not supported on Python 2.6.')
class FunkyClassMethod(classmethod):
is_funky = True
class A(object):
@FunkyClassMethod
def my_funky_class_method(cls):
raise 'Flow should never reach here.'
@monkeypatching_tools.monkeypatch_method(A)
@FunkyClassMethod
def my_funky_class_method(cls):
return cls
assert isinstance(cute_inspect.getattr_static(A, 'my_funky_class_method'),
FunkyClassMethod)
def test_upload_dead_symlink(self):
if platform.system() == 'Windows':
raise SkipTest('no os.symlink() on Windows')
with TempDir() as d:
path = os.path.join(d, 'file1')
os.symlink('non-existing', path)
with self.assertRaises(InvalidUploadSource):
self.bucket.upload_local_file(path, 'file1')
def test_ior(prng, klass, generator):
if klass == OrderedFrozenSet:
raise SkipTest('destructive operations')
elements, s_a, s_b, s_c, s_ab, s_ba, s_bc, s_cb, s_ac, s_ca, \
s_abc, s_acb, s_bac, s_bca, s_cab, s_cba = \
pick_subsets(prng, klass, generator)
for si in (s_a, s_b, s_c, s_ab, s_ba, s_bc, s_cb, s_ac, s_ca):
for sj in (s_a, s_b, s_c, s_ab, s_ba, s_bc, s_cb, s_ac, s_ca):
si_ = klass(si)
si_ |= sj
assert si_ == si | sj
for sk in (s_a, s_b, s_c, s_ab, s_ba, s_bc, s_cb, s_ac, s_ca):
si_ = klass(si)
si_.update(sj, sk)
assert si_ == si | sj | sk