Ejemplo n.º 1
0
        expected = {'x': [1, 2, 3, 4]}  # dest first
        self.assertEqual(merge_to(source, dest), expected)
        self.assertEqual(dest, expected)

    def test_merge_diff_types(self):
        source = {'x': [1, 2]}
        dest = {'x': 'abc'}
        expected = {'x': [1, 2]}  # source wins
        self.assertEqual(merge_to(source, dest), expected)
        self.assertEqual(dest, expected)

    def test_merge(self):
        first = {'a': 1, 'b': 2, 'd': 11}
        second = {'b': 20, 'c': 30}
        third = {'c': 300, 'd': 400}
        expected = {
            'a': 1,
            'b': 20,
            'c': 300,
            'd': 400,
        }
        self.assertEqual(merge(first, second, third), expected)

        # inputs haven't changed..
        self.assertEqual(first, {'a': 1, 'b': 2, 'd': 11})
        self.assertEqual(second, {'b': 20, 'c': 30})
        self.assertEqual(third, {'c': 300, 'd': 400})

if __name__ == '__main__':
    mozunit.main()
Ejemplo n.º 2
0
        self.assertEqual(v.major, 1)
        self.assertEqual(v.minor, 0)
        self.assertEqual(v.patch, 0)

    def test_version_more(self):
        v = Version('1.2.3b')
        self.assertLess(v, '2')
        self.assertEqual(v.major, 1)
        self.assertEqual(v.minor, 2)
        self.assertEqual(v.patch, 3)

    def test_version_bad(self):
        # A version with a letter in the middle doesn't really make sense,
        # so everything after it should be ignored.
        v = Version('1.2b.3')
        self.assertLess(v, '2')
        self.assertEqual(v.major, 1)
        self.assertEqual(v.minor, 2)
        self.assertEqual(v.patch, 0)

    def test_version_badder(self):
        v = Version('1b.2.3')
        self.assertLess(v, '2')
        self.assertEqual(v.major, 1)
        self.assertEqual(v.minor, 0)
        self.assertEqual(v.patch, 0)


if __name__ == '__main__':
    main()
Ejemplo n.º 3
0
        self.assertEqual("long", m.params[2].realtype.type.name)

    def testAttribute(self):
        i = self.p.parse("""[uuid(abc)] interface foo {
attribute long bar;
};""", filename='f')
        self.assertTrue(isinstance(i, xpidl.IDL))
        self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
        iface = i.productions[0]
        a = iface.members[0]
        self.assertTrue(isinstance(a, xpidl.Attribute))
        self.assertEqual("bar", a.name)
        self.assertEqual("long", a.type)

    def testOverloadedVirtual(self):
        i = self.p.parse("""[uuid(abc)] interface foo {
attribute long bar;
void getBar();
};""", filename='f')
        self.assertTrue(isinstance(i, xpidl.IDL))
        class FdMock:
            def write(self, s):
                pass
        try:
            header.print_header(i, FdMock(), filename='f')
        except Exception as e:
            self.assertEqual(e.args[0], "Unexpected overloaded virtual method GetBar in interface foo")

if __name__ == '__main__':
    mozunit.main(runwith='unittest')
Ejemplo n.º 4
0
def test_routes(server):
    assert server.routes is not None


def test_is_alive(server):
    assert server.is_alive == False
    server.start()
    assert server.is_alive == True


def test_handler(server):
    counter = 0

    @json_handler
    def handler(request, response):
        return {"count": counter}

    route = ("GET", "/httpd/test_handler", handler)
    server.router.register(*route)
    server.start()

    url = server.get_url("/httpd/test_handler")
    body = urllib2.urlopen(url).read()
    res = json.loads(body)
    assert res["count"] == counter


if __name__ == "__main__":
    mozunit.main('--log-tbpl=-')
Ejemplo n.º 5
0
        (["subdir1/subdir3"], ["subdir1/subdir3"]),
        (
            [
                "foo",
                "foobar",
            ],
            ["foo", "foobar"],
        ),
    ],
)
def test_collapse(paths, expected):
    os.chdir(root)

    inputs = []
    for path in paths:
        base, name = os.path.split(path)
        if "*" in name:
            for n in os.listdir(base):
                if not fnmatch(n, name):
                    continue
                inputs.append(os.path.join(base, n))
        else:
            inputs.append(path)

    print("inputs: {}".format(inputs))
    assert_paths(pathutils.collapse(inputs), expected)


if __name__ == "__main__":
    mozunit.main()
Ejemplo n.º 6
0
        with self.assertRaises(UnsortedError):
            ns['HOGERA'] += ['f', 'e', 'd']

    def test_context_derived_typed_list_with_items(self):
        ns = Context(allowed_variables=VARIABLES)

        # Setting to a type that's rejected by coercion should not work.
        with self.assertRaises(ValueError):
            ns['HOGEHOGE'] = [False]

        values = ['a', 'b', 'c']
        ns['HOGEHOGE'] += values

        self.assertIsInstance(ns['HOGEHOGE'], VARIABLES['HOGEHOGE'][0])
        for v in values:
            ns['HOGEHOGE'][v].foo = True

        for v, item in zip(values, ns['HOGEHOGE']):
            self.assertIsInstance(item, Piyo)
            self.assertEqual(v, item)
            self.assertEqual(ns['HOGEHOGE'][v].foo, True)
            self.assertEqual(ns['HOGEHOGE'][item].foo, True)

        with self.assertRaises(UnsortedError):
            ns['HOGEHOGE'] += ['f', 'e', 'd']


if __name__ == '__main__':
    main()
Ejemplo n.º 7
0
    bin_name = "mitmproxy-rel-bin-{platform}.manifest"
    pageset_name = "mitmproxy-recordings-raptor-paypal.manifest"

    config = {
        "playback_tool": "mitmproxy",
        "playback_binary_manifest": bin_name,
        "playback_pageset_manifest": pageset_name,
        "platform": mozinfo.os,
        "playback_recordings": os.path.join(here, "paypal.mp"),
        "run_local": True,
        "obj_path": here,  # XXX tmp?
        "binary": "firefox",
        "app": "firefox",
        "host": "example.com",
    }

    prefix = "mozproxy.backends.mitm.MitmproxyDesktop."
    with mock.patch(prefix + "setup", new_callable=setup):
        with mock.patch(prefix + "stop_mitmproxy_playback") as p:
            try:
                pb = get_playback(config)
                pb.start()
            except SetupFailed:
                assert p.call_count == 1
            except Exception:
                raise


if __name__ == "__main__":
    mozunit.main(runwith="pytest")
Ejemplo n.º 8
0
def test_routes(server):
    assert server.routes is not None


def test_is_alive(server):
    assert server.is_alive == False
    server.start()
    assert server.is_alive == True


def test_handler(server):
    counter = 0

    @json_handler
    def handler(request, response):
        return {"count": counter}

    route = ("GET", "/httpd/test_handler", handler)
    server.router.register(*route)
    server.start()

    url = server.get_url("/httpd/test_handler")
    body = urllib2.urlopen(url).read()
    res = json.loads(body)
    assert res["count"] == counter


if __name__ == "__main__":
    mozunit.main('-p', 'no:terminalreporter', '--log-tbpl=-')
Ejemplo n.º 9
0
                u"defaultValue": {
                    u"default": False
                },
            },
            u"minimal-feature": {
                u"id": u"minimal-feature",
                u"title": u"Minimal Feature",
                u"description": u"The smallest feature that is valid",
                u"restartRequired": True,
                u"preference": u"features.minimal-feature.enabled",
                u"type": u"boolean",
                u"bugNumbers": [1479127],
                u"isPublic": {
                    u"default": False
                },
                u"defaultValue": {
                    u"default": False
                },
            },
        }

    def test_it_returns_1_for_errors(self):
        output = StringIO()
        filename = make_test_file_path('invalid_toml')
        assert main(output, filename) == 1
        assert output.getvalue() == ''


if __name__ == '__main__':
    mozunit.main(*sys.argv[1:])
Ejemplo n.º 10
0
            self.assertEqual(e.message, (
                "scriptable interface 'nsIScriptableWithNotXPCOM' "
                "must be marked [builtinclass] because it contains a [notxpcom] "
                "method 'method2'"))

        # notxpcom attribute requires builtinclass on the interface
        i = self.p.parse("""
        interface nsISomeInterface;
        [scriptable, uuid(aaa)] interface nsISupports {};
        [scriptable, uuid(abc)] interface nsIScriptableWithNotXPCOM : nsISupports {
          [notxpcom] attribute nsISomeInterface attrib;
        };
        """,
                         filename='f')
        self.assertTrue(isinstance(i, xpidl.IDL))
        try:
            i.resolve([], self.p, {})
            self.assertTrue(
                False,
                "Resolve should fail for non-builtinclasses with notxpcom attributes"
            )
        except xpidl.IDLError as e:
            self.assertEqual(e.message, (
                "scriptable interface 'nsIScriptableWithNotXPCOM' must be marked "
                "[builtinclass] because it contains a [notxpcom] attribute 'attrib'"
            ))


if __name__ == '__main__':
    mozunit.main(runwith='unittest')
Ejemplo n.º 11
0
        # notxpcom attribute requires builtinclass on the interface
        i = self.p.parse(
            """
        interface nsISomeInterface;
        [scriptable, uuid(aaa)] interface nsISupports {};
        [scriptable, uuid(abc)] interface nsIScriptableWithNotXPCOM : nsISupports {
          [notxpcom] attribute nsISomeInterface attrib;
        };
        """,
            filename="f",
        )
        self.assertTrue(isinstance(i, xpidl.IDL))
        try:
            i.resolve([], self.p, {})
            self.assertTrue(
                False,
                "Resolve should fail for non-builtinclasses with notxpcom attributes",
            )
        except xpidl.IDLError as e:
            self.assertEqual(
                e.message,
                ("scriptable interface 'nsIScriptableWithNotXPCOM' must be marked "
                 "[builtinclass] because it contains a [notxpcom] attribute 'attrib'"
                 ),
            )


if __name__ == "__main__":
    mozunit.main(runwith="unittest")
Ejemplo n.º 12
0

@pytest.mark.parametrize("has_crashed", [True, False])
def test_crash_is_recorded_as_error(empty_marionette_test, logger,
                                    has_crashed):
    """ Number of errors is incremented by stopTest iff has_crashed is true """
    # collect results from the empty test
    result = MarionetteTestResult(
        marionette=empty_marionette_test._marionette_weakref(),
        logger=logger,
        verbosity=None,
        stream=None,
        descriptions=None,
    )
    result.startTest(empty_marionette_test)
    assert len(result.errors) == 0
    assert len(result.failures) == 0
    assert result.testsRun == 1
    assert result.shouldStop is False
    result.stopTest(empty_marionette_test)
    assert result.shouldStop == has_crashed
    if has_crashed:
        assert len(result.errors) == 1
    else:
        assert len(result.errors) == 0


if __name__ == "__main__":
    mozunit.main("-p", "no:terminalreporter", "--log-tbpl=-", "--capture",
                 "no")
Ejemplo n.º 13
0
def test_routes(server):
    assert server.routes is not None


def test_is_alive(server):
    assert server.is_alive == False
    server.start()
    assert server.is_alive == True


def test_handler(server):
    counter = 0

    @json_handler
    def handler(request, response):
        return {"count": counter}

    route = ("GET", "/httpd/test_handler", handler)
    server.router.register(*route)
    server.start()

    url = server.get_url("/httpd/test_handler")
    body = urllib2.urlopen(url).read()
    res = json.loads(body)
    assert res["count"] == counter


if __name__ == "__main__":
    mozunit.main('--log-tbpl=-')