Python operator.floordiv() Examples
The following are 30
code examples of operator.floordiv().
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
operator
, or try the search function
.
Example #1
Source File: base.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def _add_arithmetic_ops(cls): cls.__add__ = cls._create_arithmetic_method(operator.add) cls.__radd__ = cls._create_arithmetic_method(ops.radd) cls.__sub__ = cls._create_arithmetic_method(operator.sub) cls.__rsub__ = cls._create_arithmetic_method(ops.rsub) cls.__mul__ = cls._create_arithmetic_method(operator.mul) cls.__rmul__ = cls._create_arithmetic_method(ops.rmul) cls.__pow__ = cls._create_arithmetic_method(operator.pow) cls.__rpow__ = cls._create_arithmetic_method(ops.rpow) cls.__mod__ = cls._create_arithmetic_method(operator.mod) cls.__rmod__ = cls._create_arithmetic_method(ops.rmod) cls.__floordiv__ = cls._create_arithmetic_method(operator.floordiv) cls.__rfloordiv__ = cls._create_arithmetic_method(ops.rfloordiv) cls.__truediv__ = cls._create_arithmetic_method(operator.truediv) cls.__rtruediv__ = cls._create_arithmetic_method(ops.rtruediv) if not PY3: cls.__div__ = cls._create_arithmetic_method(operator.div) cls.__rdiv__ = cls._create_arithmetic_method(ops.rdiv) cls.__divmod__ = cls._create_arithmetic_method(divmod) cls.__rdivmod__ = cls._create_arithmetic_method(ops.rdivmod)
Example #2
Source File: test_panel.py From recruit with Apache License 2.0 | 6 votes |
def test_arith_flex_panel(self): ops = ['add', 'sub', 'mul', 'div', 'truediv', 'pow', 'floordiv', 'mod'] if not compat.PY3: aliases = {} else: aliases = {'div': 'truediv'} self.panel = self.panel.to_panel() for n in [np.random.randint(-50, -1), np.random.randint(1, 50), 0]: for op in ops: alias = aliases.get(op, op) f = getattr(operator, alias) exp = f(self.panel, n) result = getattr(self.panel, op)(n) assert_panel_equal(result, exp, check_panel_type=True) # rops r_f = lambda x, y: f(y, x) exp = r_f(self.panel, n) result = getattr(self.panel, 'r' + op)(n) assert_panel_equal(result, exp)
Example #3
Source File: test_series.py From recruit with Apache License 2.0 | 6 votes |
def test_binary_operators(self): # skipping for now ##### import pytest pytest.skip("skipping sparse binary operators test") def _check_inplace_op(iop, op): tmp = self.bseries.copy() expected = op(tmp, self.bseries) iop(tmp, self.bseries) tm.assert_sp_series_equal(tmp, expected) inplace_ops = ['add', 'sub', 'mul', 'truediv', 'floordiv', 'pow'] for op in inplace_ops: _check_inplace_op(getattr(operator, "i%s" % op), getattr(operator, op))
Example #4
Source File: test_panel.py From recruit with Apache License 2.0 | 6 votes |
def test_arith(self): self._test_op(self.panel, operator.add) self._test_op(self.panel, operator.sub) self._test_op(self.panel, operator.mul) self._test_op(self.panel, operator.truediv) self._test_op(self.panel, operator.floordiv) self._test_op(self.panel, operator.pow) self._test_op(self.panel, lambda x, y: y + x) self._test_op(self.panel, lambda x, y: y - x) self._test_op(self.panel, lambda x, y: y * x) self._test_op(self.panel, lambda x, y: y / x) self._test_op(self.panel, lambda x, y: y ** x) self._test_op(self.panel, lambda x, y: x + y) # panel + 1 self._test_op(self.panel, lambda x, y: x - y) # panel - 1 self._test_op(self.panel, lambda x, y: x * y) # panel * 1 self._test_op(self.panel, lambda x, y: x / y) # panel / 1 self._test_op(self.panel, lambda x, y: x ** y) # panel ** 1 pytest.raises(Exception, self.panel.__add__, self.panel['ItemA'])
Example #5
Source File: base.py From recruit with Apache License 2.0 | 6 votes |
def _add_arithmetic_ops(cls): cls.__add__ = cls._create_arithmetic_method(operator.add) cls.__radd__ = cls._create_arithmetic_method(ops.radd) cls.__sub__ = cls._create_arithmetic_method(operator.sub) cls.__rsub__ = cls._create_arithmetic_method(ops.rsub) cls.__mul__ = cls._create_arithmetic_method(operator.mul) cls.__rmul__ = cls._create_arithmetic_method(ops.rmul) cls.__pow__ = cls._create_arithmetic_method(operator.pow) cls.__rpow__ = cls._create_arithmetic_method(ops.rpow) cls.__mod__ = cls._create_arithmetic_method(operator.mod) cls.__rmod__ = cls._create_arithmetic_method(ops.rmod) cls.__floordiv__ = cls._create_arithmetic_method(operator.floordiv) cls.__rfloordiv__ = cls._create_arithmetic_method(ops.rfloordiv) cls.__truediv__ = cls._create_arithmetic_method(operator.truediv) cls.__rtruediv__ = cls._create_arithmetic_method(ops.rtruediv) if not PY3: cls.__div__ = cls._create_arithmetic_method(operator.div) cls.__rdiv__ = cls._create_arithmetic_method(ops.rdiv) cls.__divmod__ = cls._create_arithmetic_method(divmod) cls.__rdivmod__ = cls._create_arithmetic_method(ops.rdivmod)
Example #6
Source File: base.py From recruit with Apache License 2.0 | 6 votes |
def _add_numeric_methods_binary(cls): """ Add in numeric methods. """ cls.__add__ = _make_arithmetic_op(operator.add, cls) cls.__radd__ = _make_arithmetic_op(ops.radd, cls) cls.__sub__ = _make_arithmetic_op(operator.sub, cls) cls.__rsub__ = _make_arithmetic_op(ops.rsub, cls) cls.__rpow__ = _make_arithmetic_op(ops.rpow, cls) cls.__pow__ = _make_arithmetic_op(operator.pow, cls) cls.__truediv__ = _make_arithmetic_op(operator.truediv, cls) cls.__rtruediv__ = _make_arithmetic_op(ops.rtruediv, cls) if not compat.PY3: cls.__div__ = _make_arithmetic_op(operator.div, cls) cls.__rdiv__ = _make_arithmetic_op(ops.rdiv, cls) # TODO: rmod? rdivmod? cls.__mod__ = _make_arithmetic_op(operator.mod, cls) cls.__floordiv__ = _make_arithmetic_op(operator.floordiv, cls) cls.__rfloordiv__ = _make_arithmetic_op(ops.rfloordiv, cls) cls.__divmod__ = _make_arithmetic_op(divmod, cls) cls.__mul__ = _make_arithmetic_op(operator.mul, cls) cls.__rmul__ = _make_arithmetic_op(ops.rmul, cls)
Example #7
Source File: ops.py From recruit with Apache License 2.0 | 6 votes |
def _gen_fill_zeros(name): """ Find the appropriate fill value to use when filling in undefined values in the results of the given operation caused by operating on (generally dividing by) zero. Parameters ---------- name : str Returns ------- fill_value : {None, np.nan, np.inf} """ name = name.strip('__') if 'div' in name: # truediv, floordiv, div, and reversed variants fill_value = np.inf elif 'mod' in name: # mod, rmod fill_value = np.nan else: fill_value = None return fill_value
Example #8
Source File: test_scalarmath.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_modulus_basic(self): dt = np.typecodes['AllInteger'] + np.typecodes['Float'] for dt1, dt2 in itertools.product(dt, dt): for sg1, sg2 in itertools.product((+1, -1), (+1, -1)): if sg1 == -1 and dt1 in np.typecodes['UnsignedInteger']: continue if sg2 == -1 and dt2 in np.typecodes['UnsignedInteger']: continue fmt = 'dt1: %s, dt2: %s, sg1: %s, sg2: %s' msg = fmt % (dt1, dt2, sg1, sg2) a = np.array(sg1*71, dtype=dt1)[()] b = np.array(sg2*19, dtype=dt2)[()] div = self.floordiv(a, b) rem = self.mod(a, b) assert_equal(div*b + rem, a, err_msg=msg) if sg2 == -1: assert_(b < rem <= 0, msg) else: assert_(b > rem >= 0, msg)
Example #9
Source File: test_scalarmath.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_float_modulus_roundoff(self): # gh-6127 dt = np.typecodes['Float'] for dt1, dt2 in itertools.product(dt, dt): for sg1, sg2 in itertools.product((+1, -1), (+1, -1)): fmt = 'dt1: %s, dt2: %s, sg1: %s, sg2: %s' msg = fmt % (dt1, dt2, sg1, sg2) a = np.array(sg1*78*6e-8, dtype=dt1)[()] b = np.array(sg2*6e-8, dtype=dt2)[()] div = self.floordiv(a, b) rem = self.mod(a, b) # Equal assertion should hold when fmod is used assert_equal(div*b + rem, a, err_msg=msg) if sg2 == -1: assert_(b < rem <= 0, msg) else: assert_(b > rem >= 0, msg)
Example #10
Source File: test_panel.py From vnpy_crypto with MIT License | 6 votes |
def test_arith(self): with catch_warnings(record=True): self._test_op(self.panel, operator.add) self._test_op(self.panel, operator.sub) self._test_op(self.panel, operator.mul) self._test_op(self.panel, operator.truediv) self._test_op(self.panel, operator.floordiv) self._test_op(self.panel, operator.pow) self._test_op(self.panel, lambda x, y: y + x) self._test_op(self.panel, lambda x, y: y - x) self._test_op(self.panel, lambda x, y: y * x) self._test_op(self.panel, lambda x, y: y / x) self._test_op(self.panel, lambda x, y: y ** x) self._test_op(self.panel, lambda x, y: x + y) # panel + 1 self._test_op(self.panel, lambda x, y: x - y) # panel - 1 self._test_op(self.panel, lambda x, y: x * y) # panel * 1 self._test_op(self.panel, lambda x, y: x / y) # panel / 1 self._test_op(self.panel, lambda x, y: x ** y) # panel ** 1 pytest.raises(Exception, self.panel.__add__, self.panel['ItemA'])
Example #11
Source File: base.py From vnpy_crypto with MIT License | 6 votes |
def _add_numeric_methods_binary(cls): """ add in numeric methods """ cls.__add__ = _make_arithmetic_op(operator.add, cls) cls.__radd__ = _make_arithmetic_op(ops.radd, cls) cls.__sub__ = _make_arithmetic_op(operator.sub, cls) cls.__rsub__ = _make_arithmetic_op(ops.rsub, cls) cls.__mul__ = _make_arithmetic_op(operator.mul, cls) cls.__rmul__ = _make_arithmetic_op(ops.rmul, cls) cls.__rpow__ = _make_arithmetic_op(ops.rpow, cls) cls.__pow__ = _make_arithmetic_op(operator.pow, cls) cls.__mod__ = _make_arithmetic_op(operator.mod, cls) cls.__floordiv__ = _make_arithmetic_op(operator.floordiv, cls) cls.__rfloordiv__ = _make_arithmetic_op(ops.rfloordiv, cls) cls.__truediv__ = _make_arithmetic_op(operator.truediv, cls) cls.__rtruediv__ = _make_arithmetic_op(ops.rtruediv, cls) if not compat.PY3: cls.__div__ = _make_arithmetic_op(operator.div, cls) cls.__rdiv__ = _make_arithmetic_op(ops.rdiv, cls) cls.__divmod__ = _make_arithmetic_op(divmod, cls)
Example #12
Source File: test_panel.py From vnpy_crypto with MIT License | 6 votes |
def test_arith_flex_panel(self): with catch_warnings(record=True): ops = ['add', 'sub', 'mul', 'div', 'truediv', 'pow', 'floordiv', 'mod'] if not compat.PY3: aliases = {} else: aliases = {'div': 'truediv'} self.panel = self.panel.to_panel() for n in [np.random.randint(-50, -1), np.random.randint(1, 50), 0]: for op in ops: alias = aliases.get(op, op) f = getattr(operator, alias) exp = f(self.panel, n) result = getattr(self.panel, op)(n) assert_panel_equal(result, exp, check_panel_type=True) # rops r_f = lambda x, y: f(y, x) exp = r_f(self.panel, n) result = getattr(self.panel, 'r' + op)(n) assert_panel_equal(result, exp)
Example #13
Source File: test_series.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_binary_operators(self): # skipping for now ##### import pytest pytest.skip("skipping sparse binary operators test") def _check_inplace_op(iop, op): tmp = self.bseries.copy() expected = op(tmp, self.bseries) iop(tmp, self.bseries) tm.assert_sp_series_equal(tmp, expected) inplace_ops = ['add', 'sub', 'mul', 'truediv', 'floordiv', 'pow'] for op in inplace_ops: _check_inplace_op(getattr(operator, "i%s" % op), getattr(operator, op))
Example #14
Source File: test_panel.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_arith_flex_panel(self): ops = ['add', 'sub', 'mul', 'div', 'truediv', 'pow', 'floordiv', 'mod'] if not compat.PY3: aliases = {} else: aliases = {'div': 'truediv'} self.panel = self.panel.to_panel() for n in [np.random.randint(-50, -1), np.random.randint(1, 50), 0]: for op in ops: alias = aliases.get(op, op) f = getattr(operator, alias) exp = f(self.panel, n) result = getattr(self.panel, op)(n) assert_panel_equal(result, exp, check_panel_type=True) # rops r_f = lambda x, y: f(y, x) exp = r_f(self.panel, n) result = getattr(self.panel, 'r' + op)(n) assert_panel_equal(result, exp)
Example #15
Source File: test_panel.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_arith(self): self._test_op(self.panel, operator.add) self._test_op(self.panel, operator.sub) self._test_op(self.panel, operator.mul) self._test_op(self.panel, operator.truediv) self._test_op(self.panel, operator.floordiv) self._test_op(self.panel, operator.pow) self._test_op(self.panel, lambda x, y: y + x) self._test_op(self.panel, lambda x, y: y - x) self._test_op(self.panel, lambda x, y: y * x) self._test_op(self.panel, lambda x, y: y / x) self._test_op(self.panel, lambda x, y: y ** x) self._test_op(self.panel, lambda x, y: x + y) # panel + 1 self._test_op(self.panel, lambda x, y: x - y) # panel - 1 self._test_op(self.panel, lambda x, y: x * y) # panel * 1 self._test_op(self.panel, lambda x, y: x / y) # panel / 1 self._test_op(self.panel, lambda x, y: x ** y) # panel ** 1 pytest.raises(Exception, self.panel.__add__, self.panel['ItemA'])
Example #16
Source File: test_numeric.py From ibis with Apache License 2.0 | 6 votes |
def test_binary_arithmetic_operations(backend, alltypes, df, op): smallint_col = alltypes.smallint_col + 1 # make it nonzero smallint_series = df.smallint_col + 1 expr = op(alltypes.double_col, smallint_col) result = expr.execute() expected = op(df.double_col, smallint_series) if op is operator.floordiv: # defined in ops.FloorDivide.output_type # -> returns int64 whereas pandas float64 result = result.astype('float64') expected = backend.default_series_rename(expected) backend.assert_series_equal( result, expected, check_exact=False, check_less_precise=True )
Example #17
Source File: test_sparse.py From Computable with MIT License | 6 votes |
def test_binary_operators(self): # skipping for now ##### raise nose.SkipTest("skipping sparse binary operators test") def _check_inplace_op(iop, op): tmp = self.bseries.copy() expected = op(tmp, self.bseries) iop(tmp, self.bseries) assert_sp_series_equal(tmp, expected) inplace_ops = ['add', 'sub', 'mul', 'truediv', 'floordiv', 'pow'] for op in inplace_ops: _check_inplace_op( getattr(operator, "i%s" % op), getattr(operator, op))
Example #18
Source File: test_quaternion.py From quaternion with MIT License | 6 votes |
def test_quaternion_divide_ufunc(Qs): ufunc_binary_utility(np.array([quaternion.one]), Qs[Qs_finitenonzero], operator.truediv) ufunc_binary_utility(Qs[Qs_finite], np.array([quaternion.one]), operator.truediv) ufunc_binary_utility(np.array([1.0]), Qs[Qs_finitenonzero], operator.truediv) ufunc_binary_utility(Qs[Qs_finite], np.array([1.0]), operator.truediv) ufunc_binary_utility(np.array([1]), Qs[Qs_finitenonzero], operator.truediv) ufunc_binary_utility(Qs[Qs_finite], np.array([1]), operator.truediv) ufunc_binary_utility(np.array([0.0]), Qs[Qs_finitenonzero], operator.truediv) ufunc_binary_utility(np.array([0]), Qs[Qs_finitenonzero], operator.truediv) ufunc_binary_utility(np.array([-3, -2.3, -1.2, -1.0, 0.0, 0, 1.0, 1, 1.2, 2.3, 3]), Qs[Qs_finitenonzero], operator.truediv) ufunc_binary_utility(Qs[Qs_finitenonzero], np.array([-3, -2.3, -1.2, -1.0, 1.0, 1, 1.2, 2.3, 3]), operator.truediv) ufunc_binary_utility(Qs[Qs_finite], Qs[Qs_finitenonzero], operator.truediv) ufunc_binary_utility(Qs[Qs_finite], Qs[Qs_finitenonzero], operator.floordiv) ufunc_binary_utility(Qs[Qs_finitenonzero], Qs[Qs_finitenonzero], operator.truediv) ufunc_binary_utility(Qs[Qs_finitenonzero], Qs[Qs_finitenonzero], operator.floordiv)
Example #19
Source File: ops.py From vnpy_crypto with MIT License | 6 votes |
def _gen_fill_zeros(name): """ Find the appropriate fill value to use when filling in undefined values in the results of the given operation caused by operating on (generally dividing by) zero. Parameters ---------- name : str Returns ------- fill_value : {None, np.nan, np.inf} """ name = name.strip('__') if 'div' in name: # truediv, floordiv, div, and reversed variants fill_value = np.inf elif 'mod' in name: # mod, rmod fill_value = np.nan else: fill_value = None return fill_value
Example #20
Source File: test_series.py From vnpy_crypto with MIT License | 6 votes |
def test_binary_operators(self): # skipping for now ##### import pytest pytest.skip("skipping sparse binary operators test") def _check_inplace_op(iop, op): tmp = self.bseries.copy() expected = op(tmp, self.bseries) iop(tmp, self.bseries) tm.assert_sp_series_equal(tmp, expected) inplace_ops = ['add', 'sub', 'mul', 'truediv', 'floordiv', 'pow'] for op in inplace_ops: _check_inplace_op(getattr(operator, "i%s" % op), getattr(operator, op))
Example #21
Source File: euclid.py From honeybee with GNU General Public License v3.0 | 5 votes |
def __rfloordiv__(self, other): assert type(other) in (int, long, float) return Vector3(operator.floordiv(other, self.x), operator.floordiv(other, self.y), operator.floordiv(other, self.z))
Example #22
Source File: test_classes.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_floordiv(Poly): c1 = list(random((4,)) + .5) c2 = list(random((3,)) + .5) c3 = list(random((2,)) + .5) p1 = Poly(c1) p2 = Poly(c2) p3 = Poly(c3) p4 = p1 * p2 + p3 c4 = list(p4.coef) assert_poly_almost_equal(p4 // p2, p1) assert_poly_almost_equal(p4 // c2, p1) assert_poly_almost_equal(c4 // p2, p1) assert_poly_almost_equal(p4 // tuple(c2), p1) assert_poly_almost_equal(tuple(c4) // p2, p1) assert_poly_almost_equal(p4 // np.array(c2), p1) assert_poly_almost_equal(np.array(c4) // p2, p1) assert_poly_almost_equal(2 // p2, Poly([0])) assert_poly_almost_equal(p2 // 2, 0.5*p2) assert_raises( TypeError, op.floordiv, p1, Poly([0], domain=Poly.domain + 1)) assert_raises( TypeError, op.floordiv, p1, Poly([0], window=Poly.window + 1)) if Poly is Polynomial: assert_raises(TypeError, op.floordiv, p1, Chebyshev([0])) else: assert_raises(TypeError, op.floordiv, p1, Polynomial([0]))
Example #23
Source File: euclid.py From honeybee with GNU General Public License v3.0 | 5 votes |
def __floordiv__(self, other): assert type(other) in (int, long, float) return Vector3(operator.floordiv(self.x, other), operator.floordiv(self.y, other), operator.floordiv(self.z, other))
Example #24
Source File: test_operator.py From oss-ftp with MIT License | 5 votes |
def test_floordiv(self): self.assertRaises(TypeError, operator.floordiv, 5) self.assertRaises(TypeError, operator.floordiv, None, None) self.assertTrue(operator.floordiv(5, 2) == 2)
Example #25
Source File: test_operator.py From oss-ftp with MIT License | 5 votes |
def test_div(self): self.assertRaises(TypeError, operator.div, 5) self.assertRaises(TypeError, operator.div, None, None) self.assertTrue(operator.floordiv(5, 2) == 2)
Example #26
Source File: test_classes.py From recruit with Apache License 2.0 | 5 votes |
def test_floordiv(Poly): c1 = list(random((4,)) + .5) c2 = list(random((3,)) + .5) c3 = list(random((2,)) + .5) p1 = Poly(c1) p2 = Poly(c2) p3 = Poly(c3) p4 = p1 * p2 + p3 c4 = list(p4.coef) assert_poly_almost_equal(p4 // p2, p1) assert_poly_almost_equal(p4 // c2, p1) assert_poly_almost_equal(c4 // p2, p1) assert_poly_almost_equal(p4 // tuple(c2), p1) assert_poly_almost_equal(tuple(c4) // p2, p1) assert_poly_almost_equal(p4 // np.array(c2), p1) assert_poly_almost_equal(np.array(c4) // p2, p1) assert_poly_almost_equal(2 // p2, Poly([0])) assert_poly_almost_equal(p2 // 2, 0.5*p2) assert_raises( TypeError, op.floordiv, p1, Poly([0], domain=Poly.domain + 1)) assert_raises( TypeError, op.floordiv, p1, Poly([0], window=Poly.window + 1)) if Poly is Polynomial: assert_raises(TypeError, op.floordiv, p1, Chebyshev([0])) else: assert_raises(TypeError, op.floordiv, p1, Polynomial([0]))
Example #27
Source File: missing.py From vnpy_crypto with MIT License | 5 votes |
def dispatch_missing(op, left, right, result): """ Fill nulls caused by division by zero, casting to a diffferent dtype if necessary. Parameters ---------- op : function (operator.add, operator.div, ...) left : object (Index for non-reversed ops) right : object (Index fof reversed ops) result : ndarray Returns ------- result : ndarray """ opstr = '__{opname}__'.format(opname=op.__name__).replace('____', '__') if op in [operator.truediv, operator.floordiv, getattr(operator, 'div', None)]: result = mask_zero_div_zero(left, right, result) elif op is operator.mod: result = fill_zeros(result, left, right, opstr, np.nan) elif op is divmod: res0 = mask_zero_div_zero(left, right, result[0]) res1 = fill_zeros(result[1], left, right, opstr, np.nan) result = (res0, res1) return result
Example #28
Source File: ops.py From vnpy_crypto with MIT License | 5 votes |
def _cast_sparse_series_op(left, right, opname): """ For SparseSeries operation, coerce to float64 if the result is expected to have NaN or inf values Parameters ---------- left : SparseArray right : SparseArray opname : str Returns ------- left : SparseArray right : SparseArray """ opname = opname.strip('_') if is_integer_dtype(left) and is_integer_dtype(right): # series coerces to float64 if result should have NaN/inf if opname in ('floordiv', 'mod') and (right.values == 0).any(): left = left.astype(np.float64) right = right.astype(np.float64) elif opname in ('rfloordiv', 'rmod') and (left.values == 0).any(): left = left.astype(np.float64) right = right.astype(np.float64) return left, right
Example #29
Source File: dataset.py From angr with BSD 2-Clause "Simplified" License | 5 votes |
def __div__(self, other): return self._bin_op(other, operator.floordiv)
Example #30
Source File: test_operator.py From BinderFilter with MIT License | 5 votes |
def test_div(self): self.assertRaises(TypeError, operator.div, 5) self.assertRaises(TypeError, operator.div, None, None) self.assertTrue(operator.floordiv(5, 2) == 2)