예제 #1
0
        class HypotPoint(namedtuple('Point', 'x y')):
            @property
            def hypot(self):
                return (self.x**2 + self.y**2)**0.5

            def __str__(self):
                return 'Point: x=%6.3f y=%6.3f hypot=%6.3f' % (self.x, self.y,
                                                               self.hypot)
예제 #2
0
        class OptimizedPoint(namedtuple('Point', 'x y')):
            _make = classmethod(tuple.__new__)

            def _replace(self, _map=map, **kwds):
                return self._make(_map(kwds.get, ('x', 'y'), self))
예제 #3
0
import unittest
import sys
import pickle
import doctest

try:
    import autotest.common as common
except ImportError:
    import common
from autotest.client.shared import backports
from autotest.client.shared.backports.collections import namedtuple


# Used in namedtuple unittests, put at module scope to cope with pickle:
# "classes that are defined at the top level of a module"
Point = namedtuple('Point', 'x, y')


class TestBackports(unittest.TestCase):

    def test_any(self):
        self.assertTrue(backports.any([False, 0, 1, "", True, set()]))
        self.assertFalse(backports.any([]))
        self.assertFalse(backports.any(set()))
        self.assertFalse(backports.any(["", 0, False]))

    def test_all(self):
        self.assertFalse(backports.all([False, 0, 1, "", True]))
        self.assertTrue(backports.all([]))
        self.assertFalse(backports.all(["", 0, False, set()]))
        self.assertTrue(backports.all(["True", 1, True]))
예제 #4
0
import unittest
import sys
import pickle
import doctest

try:
    import autotest.common as common
except ImportError:
    import common
from autotest.client.shared import backports
from autotest.client.shared.backports.collections import namedtuple

# Used in namedtuple unittests, put at module scope to cope with pickle:
# "classes that are defined at the top level of a module"
Point = namedtuple('Point', 'x, y')


class TestBackports(unittest.TestCase):
    def test_any(self):
        self.assertTrue(backports.any([False, 0, 1, "", True, set()]))
        self.assertFalse(backports.any([]))
        self.assertFalse(backports.any(set()))
        self.assertFalse(backports.any(["", 0, False]))

    def test_all(self):
        self.assertFalse(backports.all([False, 0, 1, "", True]))
        self.assertTrue(backports.all([]))
        self.assertFalse(backports.all(["", 0, False, set()]))
        self.assertTrue(backports.all(["True", 1, True]))
예제 #5
0
import pickle
import sys
import unittest

try:
    import autotest.common as common  # pylint: disable=W0611
except ImportError:
    import common  # pylint: disable=W0611
from autotest.client.shared import backports
from autotest.client.shared.backports.collections import namedtuple


# Used in namedtuple unittests, put at module scope to cope with pickle:
# "classes that are defined at the top level of a module"
Point = namedtuple("Point", "x, y")


class TestBackports(unittest.TestCase):
    def test_any(self):
        self.assertTrue(backports.any([False, 0, 1, "", True, set()]))
        self.assertFalse(backports.any([]))
        self.assertFalse(backports.any(set()))
        self.assertFalse(backports.any(["", 0, False]))

    def test_all(self):
        self.assertFalse(backports.all([False, 0, 1, "", True]))
        self.assertTrue(backports.all([]))
        self.assertFalse(backports.all(["", 0, False, set()]))
        self.assertTrue(backports.all(["True", 1, True]))