示例#1
0
    def updater(self, fields=True, groups=False, all=True, **kvargs):
        """
        provide the ability for subclassing objects to extend the
        definitions of the fields.  this is implemented as a
        context manager with the form called from the subclass
        constructor:

          with self.extend() as more:
            more.fields = <dict>
            more.groups = <dict>   # optional
        """
        # ---------------------------------------------------------------------
        # create a new object class so we can attach stuff to it arbitrarily.
        # then pass that object to the caller, yo!
        # ---------------------------------------------------------------------

        more = type("RunstatViewMore", (object, ), {})()
        if fields is True:
            more.fields = ViewFields()

        # ---------------------------------------------------------------------
        # callback through context manager
        # ---------------------------------------------------------------------

        yield more
        updater = self._updater_class if all is True else self._updater_instance
        updater(more)
示例#2
0
class TestFactoryViewFields(unittest.TestCase):
    def setUp(self):
        self.vf = ViewFields()

    def test_viewfields_string(self):
        self.vf.str('test', key='123')
        self.assertEqual(self.vf.end['test']['key'], '123')

    def test_viewfields_astype(self):
        self.vf.astype('test', astype=1)
        self.assertEqual(self.vf.end['test']['astype'], 1)

    def test_viewfields_int(self):
        self.vf.int('test')
        self.assertEqual(self.vf.end['test']['astype'], int)

    def test_viewfields_flag(self):
        self.vf.flag('test')
        self.assertEqual(self.vf.end['test']['astype'], bool)

    def test_viewfields_table(self):
        self.vf.table('test', [])
        self.assertEqual(self.vf.end['test']['table'], [])
示例#3
0
class TestFactoryViewFields(unittest.TestCase):
    def setUp(self):
        self.vf = ViewFields()

    def test_viewfields_string(self):
        self.vf.str("test", key="123")
        self.assertEqual(self.vf.end["test"]["key"], "123")

    def test_viewfields_astype(self):
        self.vf.astype("test", astype=1)
        self.assertEqual(self.vf.end["test"]["astype"], 1)

    def test_viewfields_int(self):
        self.vf.int("test")
        self.assertEqual(self.vf.end["test"]["astype"], int)

    def test_viewfields_flag(self):
        self.vf.flag("test")
        self.assertEqual(self.vf.end["test"]["astype"], bool)

    def test_viewfields_table(self):
        self.vf.table("test", [])
        self.assertEqual(self.vf.end["test"]["table"], [])
示例#4
0
class TestFactoryViewFields(unittest.TestCase):

    def setUp(self):
        self.vf = ViewFields()

    def test_viewfields_string(self):
        self.vf.str('test', key='123')
        self.assertEqual(self.vf.end['test']['key'], '123')

    def test_viewfields_astype(self):
        self.vf.astype('test', astype=1)
        self.assertEqual(self.vf.end['test']['astype'], 1)

    def test_viewfields_int(self):
        self.vf.int('test')
        self.assertEqual(self.vf.end['test']['astype'], int)

    def test_viewfields_flag(self):
        self.vf.flag('test')
        self.assertEqual(self.vf.end['test']['astype'], bool)

    def test_viewfields_table(self):
        self.vf.table('test', [])
        self.assertEqual(self.vf.end['test']['table'], [])
示例#5
0
 def setUp(self):
     self.vf = ViewFields()
示例#6
0
 def setUp(self):
     self.vf = ViewFields()