Example #1
0
    def test_path_typed_list(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, "bar", "moz.build"))

        paths = [
            "!../bar/qux",
            "!/qux/qux",
            "!qux",
            "../bar/qux",
            "/qux/qux",
            "qux",
        ]

        MyList = ContextDerivedTypedList(Path)
        l = MyList(ctxt1)
        l += paths

        for p_str, p_path in zip(paths, l):
            self.assertEqual(p_str, p_path)
            self.assertEqual(p_path, Path(ctxt1, p_str))
            self.assertEqual(p_path.join("foo"),
                             Path(ctxt1, mozpath.join(p_str, "foo")))

        l2 = MyList(ctxt2)
        l2 += paths

        for p_str, p_path in zip(paths, l2):
            self.assertEqual(p_str, p_path)
            self.assertEqual(p_path, Path(ctxt2, p_str))

        # Assigning with Paths from another context doesn't rebase them
        l2 = MyList(ctxt2)
        l2 += l

        for p_str, p_path in zip(paths, l2):
            self.assertEqual(p_str, p_path)
            self.assertEqual(p_path, Path(ctxt1, p_str))

        MyListWithFlags = ContextDerivedTypedListWithItems(
            Path,
            StrictOrderingOnAppendListWithFlagsFactory({
                "foo": bool,
            }),
        )
        l = MyListWithFlags(ctxt1)
        l += paths

        for p in paths:
            l[p].foo = True

        for p_str, p_path in zip(paths, l):
            self.assertEqual(p_str, p_path)
            self.assertEqual(p_path, Path(ctxt1, p_str))
            self.assertEqual(l[p_str].foo, True)
            self.assertEqual(l[p_path].foo, True)
Example #2
0
    def __cmp__(self, other):
        return cmp(self.value, str(other))

    def __hash__(self):
        return hash(self.value)


VARIABLES = {
    'HOGE': (unicode, unicode, None),
    'FUGA': (Fuga, unicode, None),
    'PIYO': (Piyo, unicode, None),
    'HOGERA':
    (ContextDerivedTypedList(Piyo, StrictOrderingOnAppendList), list, None),
    'HOGEHOGE': (ContextDerivedTypedListWithItems(
        Piyo, StrictOrderingOnAppendListWithFlagsFactory({
            'foo': bool,
        })), list, None),
}


class TestContext(unittest.TestCase):
    def test_key_rejection(self):
        # Lowercase keys should be rejected during normal operation.
        ns = Context(allowed_variables=VARIABLES)

        with self.assertRaises(KeyError) as ke:
            ns['foo'] = True

        e = ke.exception.args
        self.assertEqual(e[0], 'global_ns')
        self.assertEqual(e[1], 'set_unknown')
Example #3
0
        return self.value >= six.text_type(other)

    def __hash__(self):
        return hash(self.value)


VARIABLES = {
    "HOGE": (six.text_type, six.text_type, None),
    "FUGA": (Fuga, six.text_type, None),
    "PIYO": (Piyo, six.text_type, None),
    "HOGERA": (ContextDerivedTypedList(Piyo, StrictOrderingOnAppendList), list, None),
    "HOGEHOGE": (
        ContextDerivedTypedListWithItems(
            Piyo,
            StrictOrderingOnAppendListWithFlagsFactory(
                {
                    "foo": bool,
                }
            ),
        ),
        list,
        None,
    ),
}


class TestContext(unittest.TestCase):
    def test_key_rejection(self):
        # Lowercase keys should be rejected during normal operation.
        ns = Context(allowed_variables=VARIABLES)

        with self.assertRaises(KeyError) as ke: