Exemple #1
0
    def setup_karma_artifact_runtime(self):

        def export_target_only(package_names, export_target):
            spec = Spec(
                export_target=export_target,
                test_package_names=package_names,
                # typically, the toolchain test advice will be advised
                # to the spec which will then set these up.
                calmjs_test_registry_names=['calmjs.dev.module.tests'],
            )
            return KarmaToolchain(), spec,

        def generic_tester(package_names, export_target):
            toolchain, spec = export_target_only(package_names, export_target)
            spec['artifact_paths'] = [export_target]
            return toolchain, spec

        tester_mod = ModuleType('calmjs_dev_tester')
        tester_mod.generic = generic_tester
        tester_mod.export = export_target_only

        self.addCleanup(sys.modules.pop, 'calmjs_dev_tester')
        self.addCleanup(
            root_registry.records.pop, 'calmjs.dev.module.tests', None)
        sys.modules['calmjs_dev_tester'] = tester_mod

        working_dir = mkdtemp(self)

        make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                '[calmjs.artifacts.tests]',
                'artifact.js = calmjs_dev_tester:generic',
                'export_target.js = calmjs_dev_tester:export',
            ])),
        ), 'calmjs.dev', '1.0', working_dir=working_dir)

        make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                '[calmjs.artifacts.tests]',
                'missing.js = calmjs_dev_tester:generic',
            ])),
        ), 'missing', '1.0', working_dir=working_dir)

        make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                # this won't actually generate an artifact, but that is
                # not what is being tested.
                '[calmjs.artifacts]',
                'testless.js = calmjs_dev_tester:generic',
            ])),
        ), 'testless', '1.0', working_dir=working_dir)

        make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                # the tester is missing.
                '[calmjs.artifacts.tests]',
                'artifact.js = not_installed:tester',
            ])),
        ), 'depsmissing', '1.0', working_dir=working_dir)

        make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
            ])),
        ), 'nothing', '1.0', working_dir=working_dir)

        # simply inject the "artifact" for this package into the
        # registry
        mock_ws = WorkingSet([working_dir])
        registry = ArtifactTestRegistry(
            'calmjs.artifacts.tests', _working_set=mock_ws)

        # produce the "artifact" by simply the local main.js
        main_js = resource_filename('calmjs.dev', 'main.js')
        artifact_target = registry.get_artifact_filename(
            'calmjs.dev', 'artifact.js')
        export_target = registry.get_artifact_filename(
            'calmjs.dev', 'export_target.js')
        os.mkdir(dirname(artifact_target))
        with open(main_js) as reader:
            with open(artifact_target, 'w') as writer:
                writer.write(reader.read())
            reader.seek(0)
            with open(export_target, 'w') as writer:
                writer.write(reader.read())

        # assign this dummy registry to the root records with cleanup
        self.addCleanup(root_registry.records.pop, 'calmjs.artifacts.tests')
        root_registry.records['calmjs.artifacts.tests'] = registry

        # include the artifact registry, too.
        self.addCleanup(root_registry.records.pop, 'calmjs.artifacts')
        artifact_registry = ArtifactRegistry(
            'calmjs.artifacts', _working_set=mock_ws)
        root_registry.records['calmjs.artifacts'] = artifact_registry

        # use the verify artifact runtime directly
        return KarmaArtifactRuntime()