Python sys.py3kwarning() Examples
The following are 30
code examples of sys.py3kwarning().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sys
, or try the search function
.
Example #1
Source File: test_regression.py From pySINDy with MIT License | 6 votes |
def test_richcompare_crash(self): # gh-4613 import operator as op # dummy class where __array__ throws exception class Foo(object): __array_priority__ = 1002 def __array__(self, *args, **kwargs): raise Exception() rhs = Foo() lhs = np.array(1) for f in [op.lt, op.le, op.gt, op.ge]: if sys.version_info[0] >= 3: assert_raises(TypeError, f, lhs, rhs) elif not sys.py3kwarning: # With -3 switch in python 2, DeprecationWarning is raised # which we are not interested in f(lhs, rhs) assert_(not op.eq(lhs, rhs)) assert_(op.ne(lhs, rhs))
Example #2
Source File: test_regression.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_richcompare_crash(self): # gh-4613 import operator as op # dummy class where __array__ throws exception class Foo(object): __array_priority__ = 1002 def __array__(self, *args, **kwargs): raise Exception() rhs = Foo() lhs = np.array(1) for f in [op.lt, op.le, op.gt, op.ge]: if sys.version_info[0] >= 3: assert_raises(TypeError, f, lhs, rhs) elif not sys.py3kwarning: # With -3 switch in python 2, DeprecationWarning is raised # which we are not interested in f(lhs, rhs) assert_(not op.eq(lhs, rhs)) assert_(op.ne(lhs, rhs))
Example #3
Source File: test_support.py From BinderFilter with MIT License | 6 votes |
def check_py3k_warnings(*filters, **kwargs): """Context manager to silence py3k warnings. Accept 2-tuples as positional arguments: ("message regexp", WarningCategory) Optional argument: - if 'quiet' is True, it does not fail if a filter catches nothing (default False) Without argument, it defaults to: check_py3k_warnings(("", DeprecationWarning), quiet=False) """ if sys.py3kwarning: if not filters: filters = (("", DeprecationWarning),) else: # It should not raise any py3k warning filters = () return _filterwarnings(filters, kwargs.get('quiet'))
Example #4
Source File: test_regression.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_richcompare_crash(self): # gh-4613 import operator as op # dummy class where __array__ throws exception class Foo(object): __array_priority__ = 1002 def __array__(self, *args, **kwargs): raise Exception() rhs = Foo() lhs = np.array(1) for f in [op.lt, op.le, op.gt, op.ge]: if sys.version_info[0] >= 3: assert_raises(TypeError, f, lhs, rhs) elif not sys.py3kwarning: # With -3 switch in python 2, DeprecationWarning is raised # which we are not interested in f(lhs, rhs) assert_(not op.eq(lhs, rhs)) assert_(op.ne(lhs, rhs))
Example #5
Source File: test_regression.py From vnpy_crypto with MIT License | 6 votes |
def test_richcompare_crash(self): # gh-4613 import operator as op # dummy class where __array__ throws exception class Foo(object): __array_priority__ = 1002 def __array__(self, *args, **kwargs): raise Exception() rhs = Foo() lhs = np.array(1) for f in [op.lt, op.le, op.gt, op.ge]: if sys.version_info[0] >= 3: assert_raises(TypeError, f, lhs, rhs) elif not sys.py3kwarning: # With -3 switch in python 2, DeprecationWarning is raised # which we are not interested in f(lhs, rhs) assert_(not op.eq(lhs, rhs)) assert_(op.ne(lhs, rhs))
Example #6
Source File: test_doctest.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_main(): # Check the doctest cases in doctest itself: test_support.run_doctest(doctest, verbosity=True) from test import test_doctest # Ignore all warnings about the use of class Tester in this module. deprecations = [] if __debug__: deprecations.append(("class Tester is deprecated", DeprecationWarning)) if sys.py3kwarning: deprecations += [("backquote not supported", SyntaxWarning), ("execfile.. not supported", DeprecationWarning)] with test_support.check_warnings(*deprecations): # Check the doctest cases defined here: test_support.run_doctest(test_doctest, verbosity=True)
Example #7
Source File: test_regression.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_richcompare_crash(self): # gh-4613 import operator as op # dummy class where __array__ throws exception class Foo(object): __array_priority__ = 1002 def __array__(self, *args, **kwargs): raise Exception() rhs = Foo() lhs = np.array(1) for f in [op.lt, op.le, op.gt, op.ge]: if sys.version_info[0] >= 3: assert_raises(TypeError, f, lhs, rhs) elif not sys.py3kwarning: # With -3 switch in python 2, DeprecationWarning is raised # which we are not interested in f(lhs, rhs) assert_(not op.eq(lhs, rhs)) assert_(op.ne(lhs, rhs))
Example #8
Source File: test_support.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def check_py3k_warnings(*filters, **kwargs): """Context manager to silence py3k warnings. Accept 2-tuples as positional arguments: ("message regexp", WarningCategory) Optional argument: - if 'quiet' is True, it does not fail if a filter catches nothing (default False) Without argument, it defaults to: check_py3k_warnings(("", DeprecationWarning), quiet=False) """ if sys.py3kwarning: if not filters: filters = (("", DeprecationWarning),) else: # It should not raise any py3k warning filters = () return _filterwarnings(filters, kwargs.get('quiet'))
Example #9
Source File: test_doctest.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_main(): # Check the doctest cases in doctest itself: test_support.run_doctest(doctest, verbosity=True) from test import test_doctest # Ignore all warnings about the use of class Tester in this module. deprecations = [] if __debug__: deprecations.append(("class Tester is deprecated", DeprecationWarning)) if sys.py3kwarning: deprecations += [("backquote not supported", SyntaxWarning), ("execfile.. not supported", DeprecationWarning)] with test_support.check_warnings(*deprecations): # Check the doctest cases defined here: test_support.run_doctest(test_doctest, verbosity=True)
Example #10
Source File: test_support.py From oss-ftp with MIT License | 6 votes |
def check_py3k_warnings(*filters, **kwargs): """Context manager to silence py3k warnings. Accept 2-tuples as positional arguments: ("message regexp", WarningCategory) Optional argument: - if 'quiet' is True, it does not fail if a filter catches nothing (default False) Without argument, it defaults to: check_py3k_warnings(("", DeprecationWarning), quiet=False) """ if sys.py3kwarning: if not filters: filters = (("", DeprecationWarning),) else: # It should not raise any py3k warning filters = () return _filterwarnings(filters, kwargs.get('quiet'))
Example #11
Source File: test_regression.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_richcompare_crash(self): # gh-4613 import operator as op # dummy class where __array__ throws exception class Foo(object): __array_priority__ = 1002 def __array__(self, *args, **kwargs): raise Exception() rhs = Foo() lhs = np.array(1) for f in [op.lt, op.le, op.gt, op.ge]: if sys.version_info[0] >= 3: assert_raises(TypeError, f, lhs, rhs) elif not sys.py3kwarning: # With -3 switch in python 2, DeprecationWarning is raised # which we are not interested in f(lhs, rhs) assert_(not op.eq(lhs, rhs)) assert_(op.ne(lhs, rhs))
Example #12
Source File: test_regression.py From recruit with Apache License 2.0 | 6 votes |
def test_richcompare_crash(self): # gh-4613 import operator as op # dummy class where __array__ throws exception class Foo(object): __array_priority__ = 1002 def __array__(self, *args, **kwargs): raise Exception() rhs = Foo() lhs = np.array(1) for f in [op.lt, op.le, op.gt, op.ge]: if sys.version_info[0] >= 3: assert_raises(TypeError, f, lhs, rhs) elif not sys.py3kwarning: # With -3 switch in python 2, DeprecationWarning is raised # which we are not interested in f(lhs, rhs) assert_(not op.eq(lhs, rhs)) assert_(op.ne(lhs, rhs))
Example #13
Source File: test_deprecations.py From pySINDy with MIT License | 5 votes |
def test_int_dtypes(self): #scramble types and do some mix and match testing deprecated_types = [ 'bool_', 'int_', 'intc', 'uint8', 'int8', 'uint64', 'int32', 'uint16', 'intp', 'int64', 'uint32', 'int16' ] if sys.version_info[0] < 3 and sys.py3kwarning: import operator as op dt2 = 'bool_' for dt1 in deprecated_types: a = np.array([1,2,3], dtype=dt1) b = np.array([1,2,3], dtype=dt2) self.assert_deprecated(op.div, args=(a,b)) dt2 = dt1
Example #14
Source File: test_scalarmath.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_blocked(self): # test alignments offsets for simd instructions # alignments for vz + 2 * (vs - 1) + 1 for dt, sz in [(np.float32, 11), (np.float64, 7), (np.int32, 11)]: for out, inp1, inp2, msg in _gen_alignment_data(dtype=dt, type='binary', max_size=sz): exp1 = np.ones_like(inp1) inp1[...] = np.ones_like(inp1) inp2[...] = np.zeros_like(inp2) assert_almost_equal(np.add(inp1, inp2), exp1, err_msg=msg) assert_almost_equal(np.add(inp1, 2), exp1 + 2, err_msg=msg) assert_almost_equal(np.add(1, inp2), exp1, err_msg=msg) np.add(inp1, inp2, out=out) assert_almost_equal(out, exp1, err_msg=msg) inp2[...] += np.arange(inp2.size, dtype=dt) + 1 assert_almost_equal(np.square(inp2), np.multiply(inp2, inp2), err_msg=msg) # skip true divide for ints if dt != np.int32 or (sys.version_info.major < 3 and not sys.py3kwarning): assert_almost_equal(np.reciprocal(inp2), np.divide(1, inp2), err_msg=msg) inp1[...] = np.ones_like(inp1) np.add(inp1, 2, out=out) assert_almost_equal(out, exp1 + 2, err_msg=msg) inp2[...] = np.ones_like(inp2) np.add(2, inp2, out=out) assert_almost_equal(out, exp1 + 2, err_msg=msg)
Example #15
Source File: pprint.py From datafari with Apache License 2.0 | 5 votes |
def _sorted(iterable): with warnings.catch_warnings(): if _sys.py3kwarning: warnings.filterwarnings("ignore", "comparing unequal types " "not supported", DeprecationWarning) return sorted(iterable)
Example #16
Source File: pprint.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _sorted(iterable): with warnings.catch_warnings(): if _sys.py3kwarning: warnings.filterwarnings("ignore", "comparing unequal types " "not supported", DeprecationWarning) return sorted(iterable)
Example #17
Source File: case.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def assertItemsEqual(self, expected_seq, actual_seq, msg=None): """An unordered sequence specific comparison. It asserts that actual_seq and expected_seq have the same element counts. Equivalent to:: self.assertEqual(Counter(iter(actual_seq)), Counter(iter(expected_seq))) Asserts that each element has the same count in both sequences. Example: - [0, 1, 1] and [1, 0, 1] compare equal. - [0, 0, 1] and [0, 1] compare unequal. """ first_seq, second_seq = list(expected_seq), list(actual_seq) with warnings.catch_warnings(): if sys.py3kwarning: # Silence Py3k warning raised during the sorting for _msg in ["(code|dict|type) inequality comparisons", "builtin_function_or_method order comparisons", "comparing unequal types"]: warnings.filterwarnings("ignore", _msg, DeprecationWarning) try: first = collections.Counter(first_seq) second = collections.Counter(second_seq) except TypeError: # Handle case with unhashable elements differences = _count_diff_all_purpose(first_seq, second_seq) else: if first == second: return differences = _count_diff_hashable(first_seq, second_seq) if differences: standardMsg = 'Element counts were not equal:\n' lines = ['First has %d, Second has %d: %r' % diff for diff in differences] diffMsg = '\n'.join(lines) standardMsg = self._truncateMessage(standardMsg, diffMsg) msg = self._formatMessage(msg, standardMsg) self.fail(msg)
Example #18
Source File: warnings.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def warnpy3k(message, category=None, stacklevel=1): """Issue a deprecation warning for Python 3.x related changes. Warnings are omitted unless Python is started with the -3 option. """ if sys.py3kwarning: if category is None: category = DeprecationWarning warn(message, category, stacklevel+1)
Example #19
Source File: test_scalarmath.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_blocked(self): # test alignments offsets for simd instructions # alignments for vz + 2 * (vs - 1) + 1 for dt, sz in [(np.float32, 11), (np.float64, 7), (np.int32, 11)]: for out, inp1, inp2, msg in _gen_alignment_data(dtype=dt, type='binary', max_size=sz): exp1 = np.ones_like(inp1) inp1[...] = np.ones_like(inp1) inp2[...] = np.zeros_like(inp2) assert_almost_equal(np.add(inp1, inp2), exp1, err_msg=msg) assert_almost_equal(np.add(inp1, 2), exp1 + 2, err_msg=msg) assert_almost_equal(np.add(1, inp2), exp1, err_msg=msg) np.add(inp1, inp2, out=out) assert_almost_equal(out, exp1, err_msg=msg) inp2[...] += np.arange(inp2.size, dtype=dt) + 1 assert_almost_equal(np.square(inp2), np.multiply(inp2, inp2), err_msg=msg) # skip true divide for ints if dt != np.int32 or (sys.version_info.major < 3 and not sys.py3kwarning): assert_almost_equal(np.reciprocal(inp2), np.divide(1, inp2), err_msg=msg) inp1[...] = np.ones_like(inp1) np.add(inp1, 2, out=out) assert_almost_equal(out, exp1 + 2, err_msg=msg) inp2[...] = np.ones_like(inp2) np.add(2, inp2, out=out) assert_almost_equal(out, exp1 + 2, err_msg=msg)
Example #20
Source File: case.py From datafari with Apache License 2.0 | 5 votes |
def assertItemsEqual(self, expected_seq, actual_seq, msg=None): """An unordered sequence specific comparison. It asserts that actual_seq and expected_seq have the same element counts. Equivalent to:: self.assertEqual(Counter(iter(actual_seq)), Counter(iter(expected_seq))) Asserts that each element has the same count in both sequences. Example: - [0, 1, 1] and [1, 0, 1] compare equal. - [0, 0, 1] and [0, 1] compare unequal. """ first_seq, second_seq = list(expected_seq), list(actual_seq) with warnings.catch_warnings(): if sys.py3kwarning: # Silence Py3k warning raised during the sorting for _msg in ["(code|dict|type) inequality comparisons", "builtin_function_or_method order comparisons", "comparing unequal types"]: warnings.filterwarnings("ignore", _msg, DeprecationWarning) try: first = collections.Counter(first_seq) second = collections.Counter(second_seq) except TypeError: # Handle case with unhashable elements differences = _count_diff_all_purpose(first_seq, second_seq) else: if first == second: return differences = _count_diff_hashable(first_seq, second_seq) if differences: standardMsg = 'Element counts were not equal:\n' lines = ['First has %d, Second has %d: %r' % diff for diff in differences] diffMsg = '\n'.join(lines) standardMsg = self._truncateMessage(standardMsg, diffMsg) msg = self._formatMessage(msg, standardMsg) self.fail(msg)
Example #21
Source File: test_defchararray.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_decode(self): if sys.version_info[0] >= 3: A = np.char.array([b'\\u03a3']) assert_(A.decode('unicode-escape')[0] == '\u03a3') else: with suppress_warnings() as sup: if sys.py3kwarning: sup.filter(DeprecationWarning, "'hex_codec'") A = np.char.array(['736563726574206d657373616765']) assert_(A.decode('hex_codec')[0] == 'secret message')
Example #22
Source File: test_deprecations.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_int_dtypes(self): #scramble types and do some mix and match testing deprecated_types = [ 'bool_', 'int_', 'intc', 'uint8', 'int8', 'uint64', 'int32', 'uint16', 'intp', 'int64', 'uint32', 'int16' ] if sys.version_info[0] < 3 and sys.py3kwarning: import operator as op dt2 = 'bool_' for dt1 in deprecated_types: a = np.array([1,2,3], dtype=dt1) b = np.array([1,2,3], dtype=dt2) self.assert_deprecated(op.div, args=(a,b)) dt2 = dt1
Example #23
Source File: test_scalarmath.py From pySINDy with MIT License | 5 votes |
def test_blocked(self): # test alignments offsets for simd instructions # alignments for vz + 2 * (vs - 1) + 1 for dt, sz in [(np.float32, 11), (np.float64, 7), (np.int32, 11)]: for out, inp1, inp2, msg in _gen_alignment_data(dtype=dt, type='binary', max_size=sz): exp1 = np.ones_like(inp1) inp1[...] = np.ones_like(inp1) inp2[...] = np.zeros_like(inp2) assert_almost_equal(np.add(inp1, inp2), exp1, err_msg=msg) assert_almost_equal(np.add(inp1, 2), exp1 + 2, err_msg=msg) assert_almost_equal(np.add(1, inp2), exp1, err_msg=msg) np.add(inp1, inp2, out=out) assert_almost_equal(out, exp1, err_msg=msg) inp2[...] += np.arange(inp2.size, dtype=dt) + 1 assert_almost_equal(np.square(inp2), np.multiply(inp2, inp2), err_msg=msg) # skip true divide for ints if dt != np.int32 or (sys.version_info.major < 3 and not sys.py3kwarning): assert_almost_equal(np.reciprocal(inp2), np.divide(1, inp2), err_msg=msg) inp1[...] = np.ones_like(inp1) np.add(inp1, 2, out=out) assert_almost_equal(out, exp1 + 2, err_msg=msg) inp2[...] = np.ones_like(inp2) np.add(2, inp2, out=out) assert_almost_equal(out, exp1 + 2, err_msg=msg)
Example #24
Source File: test_defchararray.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_decode(self): if sys.version_info[0] >= 3: A = np.char.array([b'\\u03a3']) assert_(A.decode('unicode-escape')[0] == '\u03a3') else: with suppress_warnings() as sup: if sys.py3kwarning: sup.filter(DeprecationWarning, "'hex_codec'") A = np.char.array(['736563726574206d657373616765']) assert_(A.decode('hex_codec')[0] == 'secret message')
Example #25
Source File: test_deprecations.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_int_dtypes(self): #scramble types and do some mix and match testing deprecated_types = [ 'bool_', 'int_', 'intc', 'uint8', 'int8', 'uint64', 'int32', 'uint16', 'intp', 'int64', 'uint32', 'int16' ] if sys.version_info[0] < 3 and sys.py3kwarning: import operator as op dt2 = 'bool_' for dt1 in deprecated_types: a = np.array([1,2,3], dtype=dt1) b = np.array([1,2,3], dtype=dt2) self.assert_deprecated(op.div, args=(a,b)) dt2 = dt1
Example #26
Source File: warnings.py From pmatic with GNU General Public License v2.0 | 5 votes |
def warnpy3k(message, category=None, stacklevel=1): """Issue a deprecation warning for Python 3.x related changes. Warnings are omitted unless Python is started with the -3 option. """ if sys.py3kwarning: if category is None: category = DeprecationWarning warn(message, category, stacklevel+1)
Example #27
Source File: warnings.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def warnpy3k(message, category=None, stacklevel=1): """Issue a deprecation warning for Python 3.x related changes. Warnings are omitted unless Python is started with the -3 option. """ if sys.py3kwarning: if category is None: category = DeprecationWarning warn(message, category, stacklevel+1)
Example #28
Source File: warnings.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def warnpy3k(message, category=None, stacklevel=1): """Issue a deprecation warning for Python 3.x related changes. Warnings are omitted unless Python is started with the -3 option. """ if sys.py3kwarning: if category is None: category = DeprecationWarning warn(message, category, stacklevel+1)
Example #29
Source File: test_scalarmath.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_blocked(self): # test alignments offsets for simd instructions # alignments for vz + 2 * (vs - 1) + 1 for dt, sz in [(np.float32, 11), (np.float64, 7), (np.int32, 11)]: for out, inp1, inp2, msg in _gen_alignment_data(dtype=dt, type='binary', max_size=sz): exp1 = np.ones_like(inp1) inp1[...] = np.ones_like(inp1) inp2[...] = np.zeros_like(inp2) assert_almost_equal(np.add(inp1, inp2), exp1, err_msg=msg) assert_almost_equal(np.add(inp1, 2), exp1 + 2, err_msg=msg) assert_almost_equal(np.add(1, inp2), exp1, err_msg=msg) np.add(inp1, inp2, out=out) assert_almost_equal(out, exp1, err_msg=msg) inp2[...] += np.arange(inp2.size, dtype=dt) + 1 assert_almost_equal(np.square(inp2), np.multiply(inp2, inp2), err_msg=msg) # skip true divide for ints if dt != np.int32 or (sys.version_info.major < 3 and not sys.py3kwarning): assert_almost_equal(np.reciprocal(inp2), np.divide(1, inp2), err_msg=msg) inp1[...] = np.ones_like(inp1) np.add(inp1, 2, out=out) assert_almost_equal(out, exp1 + 2, err_msg=msg) inp2[...] = np.ones_like(inp2) np.add(2, inp2, out=out) assert_almost_equal(out, exp1 + 2, err_msg=msg)
Example #30
Source File: test_defchararray.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_decode(self): if sys.version_info[0] >= 3: A = np.char.array([b'\\u03a3']) assert_(A.decode('unicode-escape')[0] == '\u03a3') else: with suppress_warnings() as sup: if sys.py3kwarning: sup.filter(DeprecationWarning, "'hex_codec'") A = np.char.array(['736563726574206d657373616765']) assert_(A.decode('hex_codec')[0] == 'secret message')