Пример #1
0
    def sandbox(self, relpath='moz.build', data_path=None):
        config = None

        if data_path is not None:
            config = MockConfig(os.path.join(test_data_path, data_path))
        else:
            config = MockConfig()

        return MozbuildSandbox(config, config.child_path(relpath))
Пример #2
0
    def sandbox(self, data_path=None, metadata={}):
        config = None

        if data_path is not None:
            config = MockConfig(mozpath.join(test_data_path, data_path))
        else:
            config = MockConfig()

        return TestedSandbox(Context(VARIABLES, config), metadata)
Пример #3
0
    def sandbox(self, relpath='moz.build', data_path=None):
        config = None

        if data_path is not None:
            config = MockConfig(os.path.join(test_data_path, data_path))
        else:
            config = MockConfig()

        return MozbuildSandbox(config, config.child_path(relpath))
Пример #4
0
    def test_invalid_utf8_substs(self):
        """Ensure invalid UTF-8 in substs is converted with an error."""

        config = MockConfig()
        # This is really mbcs. It's a bunch of invalid UTF-8.
        config.substs['BAD_UTF8'] = b'\x83\x81\x83\x82\x3A'

        sandbox = MozbuildSandbox(config, '/foo/moz.build')

        self.assertEqual(sandbox['CONFIG']['BAD_UTF8'],
            u'\ufffd\ufffd\ufffd\ufffd:')
Пример #5
0
    def reader(self, name):
        config = MockConfig(os.path.join(data_path, name), extra_substs=dict(
            ENABLE_TESTS='1',
            BIN_SUFFIX='.prog',
        ))

        return BuildReader(config)
Пример #6
0
def resolver(request, tmpdir, monkeypatch, topsrcdir, all_tests, defaults):
    topobjdir = tmpdir.mkdir("objdir").strpath
    loader_cls = request.param

    if loader_cls == BuildBackendLoader:
        with open(os.path.join(topobjdir, "all-tests.pkl"), "wb") as fh:
            pickle.dump(all_tests, fh)
        with open(os.path.join(topobjdir, "test-defaults.pkl"), "wb") as fh:
            pickle.dump(defaults, fh)

        # The mock data already exists, so prevent BuildBackendLoader from regenerating
        # the build information from the whole gecko tree...
        class BuildBackendLoaderNeverOutOfDate(BuildBackendLoader):
            def backend_out_of_date(self, backend_file):
                return False

        loader_cls = BuildBackendLoaderNeverOutOfDate

    # Patch WPT's manifestupdate.run to return tests based on the contents of
    # 'data/srcdir/wpt_manifest_data.json'.
    monkeypatch.setattr(manifestupdate, "run", fake_wpt_manifestupdate)

    resolver = TestResolver(topsrcdir,
                            None,
                            None,
                            topobjdir=topobjdir,
                            loader_cls=loader_cls)
    resolver._puppeteer_loaded = True

    if loader_cls == TestManifestLoader:
        config = MockConfig(topsrcdir)
        resolver.load_tests.reader = BuildReader(config)
    return resolver
Пример #7
0
    def test_exec_source_reassign_exported(self):
        template_sandbox = self.sandbox(data_path='templates')

        # Templates need to be defined in actual files because of
        # inspect.getsourcelines.
        template_sandbox.exec_file('templates.mozbuild')

        config = MockConfig()

        exports = {'DIST_SUBDIR': 'browser'}

        sandbox = TestedSandbox(Context(VARIABLES, config),
                                metadata={
                                    'exports': exports,
                                    'templates': template_sandbox.templates,
                                })

        self.assertEqual(sandbox['DIST_SUBDIR'], 'browser')

        # Templates should not interfere
        sandbox.exec_source('Template([])', 'foo.mozbuild')

        sandbox.exec_source('DIST_SUBDIR = "foo"')
        with self.assertRaises(SandboxExecutionError) as se:
            sandbox.exec_source('DIST_SUBDIR = "bar"')

        self.assertEqual(sandbox['DIST_SUBDIR'], 'foo')
        e = se.exception
        self.assertIsInstance(e.exc_value, KeyError)

        e = se.exception.exc_value
        self.assertEqual(e.args[0], 'global_ns')
        self.assertEqual(e.args[1], 'reassign')
        self.assertEqual(e.args[2], 'DIST_SUBDIR')
Пример #8
0
def resolver(request, tmpdir, topsrcdir, all_tests, defaults):
    topobjdir = tmpdir.mkdir("objdir").strpath
    loader_cls = request.param

    if loader_cls == BuildBackendLoader:
        with open(os.path.join(topobjdir, 'all-tests.pkl'), 'wb') as fh:
            pickle.dump(all_tests, fh)
        with open(os.path.join(topobjdir, 'test-defaults.pkl'), 'wb') as fh:
            pickle.dump(defaults, fh)

        # The mock data already exists, so prevent BuildBackendLoader from regenerating
        # the build information from the whole gecko tree...
        class BuildBackendLoaderNeverOutOfDate(BuildBackendLoader):
            def backend_out_of_date(self, backend_file):
                return False

        loader_cls = BuildBackendLoaderNeverOutOfDate

    resolver = TestResolver(topsrcdir,
                            None,
                            None,
                            topobjdir=topobjdir,
                            loader_cls=loader_cls)
    resolver._puppeteer_loaded = True
    resolver._wpt_loaded = True

    if loader_cls == TestManifestLoader:
        config = MockConfig(topsrcdir)
        resolver.load_tests.reader = BuildReader(config)
    return resolver
Пример #9
0
    def reader(self, name, enable_tests=False):
        config = MockConfig(mozpath.join(data_path, name),
                            extra_substs=dict(
                                ENABLE_TESTS='1' if enable_tests else '',
                                BIN_SUFFIX='.prog',
                                OS_TARGET='WINNT',
                            ))

        return BuildReader(config)
Пример #10
0
    def test_invalid_utf8_substs(self):
        """Ensure invalid UTF-8 in substs is converted with an error."""

        # This is really mbcs. It's a bunch of invalid UTF-8.
        config = MockConfig(extra_substs={'BAD_UTF8': b'\x83\x81\x83\x82\x3A'})

        sandbox = MozbuildSandbox(Context(VARIABLES, config))

        self.assertEqual(sandbox['CONFIG']['BAD_UTF8'],
                         u'\ufffd\ufffd\ufffd\ufffd:')
Пример #11
0
    def reader(self, name, enable_tests=False, extra_substs=None):
        substs = dict(
            ENABLE_TESTS='1' if enable_tests else '',
            BIN_SUFFIX='.prog',
            OS_TARGET='WINNT',
            COMPILE_ENVIRONMENT='1',
        )
        if extra_substs:
            substs.update(extra_substs)
        config = MockConfig(mozpath.join(data_path, name), extra_substs=substs)

        return BuildReader(config)
Пример #12
0
def resolver(request, tmpdir, topsrcdir, all_tests, defaults):
    topobjdir = tmpdir.mkdir("objdir").strpath
    loader_cls = request.param

    if loader_cls == BuildBackendLoader:
        with open(os.path.join(topobjdir, 'all-tests.pkl'), 'wb') as fh:
            pickle.dump(all_tests, fh)
        with open(os.path.join(topobjdir, 'test-defaults.pkl'), 'wb') as fh:
            pickle.dump(defaults, fh)

    resolver = TestResolver(topsrcdir, None, None, topobjdir=topobjdir, loader_cls=loader_cls)
    resolver._puppeteer_loaded = True
    resolver._wpt_loaded = True

    if loader_cls == TestManifestLoader:
        config = MockConfig(topsrcdir)
        resolver.load_tests.reader = BuildReader(config)
    return resolver
Пример #13
0
    def test_exec_source_reassign_exported(self):
        config = MockConfig()

        exports = {'DIST_SUBDIR': 'browser'}

        sandbox = MozbuildSandbox(Context(VARIABLES, config),
                                  metadata={'exports': exports})

        self.assertEqual(sandbox['DIST_SUBDIR'], 'browser')

        sandbox.exec_source('DIST_SUBDIR = "foo"')
        with self.assertRaises(SandboxExecutionError) as se:
            sandbox.exec_source('DIST_SUBDIR = "bar"')

        self.assertEqual(sandbox['DIST_SUBDIR'], 'foo')
        e = se.exception
        self.assertIsInstance(e.exc_value, KeyError)

        e = se.exception.exc_value
        self.assertEqual(e.args[0], 'global_ns')
        self.assertEqual(e.args[1], 'reassign')
        self.assertEqual(e.args[2], 'DIST_SUBDIR')
Пример #14
0
    def test_exec_source_reassign_exported(self):
        template_sandbox = self.sandbox(data_path="templates")

        # Templates need to be defined in actual files because of
        # inspect.getsourcelines.
        template_sandbox.exec_file("templates.mozbuild")

        config = MockConfig()

        exports = {"DIST_SUBDIR": "browser"}

        sandbox = TestedSandbox(
            Context(VARIABLES, config),
            metadata={
                "exports": exports,
                "templates": template_sandbox.templates,
            },
        )

        self.assertEqual(sandbox["DIST_SUBDIR"], "browser")

        # Templates should not interfere
        sandbox.exec_source("Template([])", "foo.mozbuild")

        sandbox.exec_source('DIST_SUBDIR = "foo"')
        with self.assertRaises(SandboxExecutionError) as se:
            sandbox.exec_source('DIST_SUBDIR = "bar"')

        self.assertEqual(sandbox["DIST_SUBDIR"], "foo")
        e = se.exception
        self.assertIsInstance(e.exc_value, KeyError)

        e = se.exception.exc_value
        self.assertEqual(e.args[0], "global_ns")
        self.assertEqual(e.args[1], "reassign")
        self.assertEqual(e.args[2], "DIST_SUBDIR")
Пример #15
0
    def config(self, name, **kwargs):
        path = mozpath.join(data_path, name)

        return MockConfig(path, **kwargs)
Пример #16
0
    def reader(self, name):
        config = MockConfig(os.path.join(data_path, name))
        config.substs["ENABLE_TESTS"] = "1"
        config.substs["BIN_SUFFIX"] = ".prog"

        return BuildReader(config)
Пример #17
0
    def reader(self, name):
        config = MockConfig(os.path.join(data_path, name))
        config.substs['ENABLE_TESTS'] = '1'
        config.substs['BIN_SUFFIX'] = '.prog'

        return BuildReader(config)
Пример #18
0
    def reader(self, name):
        config = MockConfig(os.path.join(data_path, name))
        config.substs['ENABLE_TESTS'] = '1'
        config.substs['BIN_SUFFIX'] = '.prog'

        return BuildReader(config)
Пример #19
0
    def config(self, name):
        path = os.path.join(data_path, name)

        return MockConfig(path)