示例#1
0
    def test_using1(self):
        lines = ['@group mygroup using group1',
                 'meter',
                 'second',
                 ]

        d = {}
        root = self._build_root(d)

        g = Group('group1', d)
        grp = Group.from_lines(lines, lambda x: None, d)
        self.assertEqual(grp.name, 'mygroup')
        self.assertEqual(grp._unit_names, set(['meter', 'second']))
        self.assertEqual(grp._used_groups, set(['group1']))
        self.assertEqual(grp.members, frozenset(['meter', 'second']))
示例#2
0
    def test_using1(self):
        lines = [
            '@group mygroup using group1',
            'meter',
            'second',
        ]

        d = {}
        root = self._build_root(d)

        g = Group('group1', d)
        grp = Group.from_lines(lines, lambda x: None, d)
        self.assertEqual(grp.name, 'mygroup')
        self.assertEqual(grp._unit_names, set(['meter', 'second']))
        self.assertEqual(grp._used_groups, set(['group1']))
        self.assertEqual(grp.members, frozenset(['meter', 'second']))
示例#3
0
    def test_with_defintions(self):
        lines = [
            '@group imperial', 'inch', 'yard', 'kings_leg = 2 * meter',
            'kings_head = 52 * inch'
            'pint'
        ]
        defs = []

        def define(ud):
            defs.append(ud.name)

        d = {}
        root = self._build_root(d)

        grp = Group.from_lines(lines, define, d)

        self.assertEqual(['kings_leg', 'kings_head'], defs)
示例#4
0
    def test_simple(self):
        lines = ['@group mygroup',
                 'meter',
                 'second',
                 ]

        d = {}
        root = self._build_root(d)

        grp = Group.from_lines(lines, lambda x: None, d)

        self.assertEqual(set(d.keys()), set(['root', 'mygroup']))

        self.assertEqual(grp.name, 'mygroup')
        self.assertEqual(grp._unit_names, set(['meter', 'second']))
        self.assertEqual(grp._used_groups, set())
        self.assertEqual(grp._used_by, set([root.name]))
        self.assertEqual(grp.members, frozenset(['meter', 'second']))
示例#5
0
    def test_with_defintions(self):
        lines = ['@group imperial',
                 'inch',
                 'yard',
                 'kings_leg = 2 * meter',
                 'kings_head = 52 * inch'
                 'pint'
                 ]
        defs = []
        def define(ud):
            defs.append(ud.name)

        d = {}
        root = self._build_root(d)

        grp = Group.from_lines(lines, define, d)

        self.assertEqual(['kings_leg', 'kings_head'], defs)
示例#6
0
    def test_simple(self):
        lines = [
            '@group mygroup',
            'meter',
            'second',
        ]

        d = {}
        root = self._build_root(d)

        grp = Group.from_lines(lines, lambda x: None, d)

        self.assertEqual(set(d.keys()), set(['root', 'mygroup']))

        self.assertEqual(grp.name, 'mygroup')
        self.assertEqual(grp._unit_names, set(['meter', 'second']))
        self.assertEqual(grp._used_groups, set())
        self.assertEqual(grp._used_by, set([root.name]))
        self.assertEqual(grp.members, frozenset(['meter', 'second']))
示例#7
0
    def test_invalidate_members(self):
        lines = ['@group mygroup using group1',
                 'meter',
                 'second',
                 ]

        d = {}
        root = self._build_root(d)

        g1 = Group('group1', d)
        grp = Group.from_lines(lines, lambda x: None, d)
        self.assertIs(root._computed_members, None)
        self.assertIs(grp._computed_members, None)
        self.assertEqual(grp.members, frozenset(['meter', 'second']))
        self.assertIs(root._computed_members, None)
        self.assertIsNot(grp._computed_members, None)
        self.assertEqual(root.members, frozenset(['meter', 'second']))
        self.assertIsNot(root._computed_members, None)
        self.assertIsNot(grp._computed_members, None)
        grp.invalidate_members()
        self.assertIs(root._computed_members, None)
        self.assertIs(grp._computed_members, None)
示例#8
0
    def test_invalidate_members(self):
        lines = [
            '@group mygroup using group1',
            'meter',
            'second',
        ]

        d = {}
        root = self._build_root(d)

        g1 = Group('group1', d)
        grp = Group.from_lines(lines, lambda x: None, d)
        self.assertIs(root._computed_members, None)
        self.assertIs(grp._computed_members, None)
        self.assertEqual(grp.members, frozenset(['meter', 'second']))
        self.assertIs(root._computed_members, None)
        self.assertIsNot(grp._computed_members, None)
        self.assertEqual(root.members, frozenset(['meter', 'second']))
        self.assertIsNot(root._computed_members, None)
        self.assertIsNot(grp._computed_members, None)
        grp.invalidate_members()
        self.assertIs(root._computed_members, None)
        self.assertIs(grp._computed_members, None)