Esempio n. 1
0
    def test_denormalized_package_names(self):
        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (('entry_points.txt', '\n'.join([
            '[calmjs.artifacts]',
            'full.js = calmjs_testbuild:full',
        ])), ),
                              'de_normal_name',
                              '1.0',
                              working_dir=working_dir)

        mock_ws = WorkingSet([working_dir])
        # stub the default working set in calmjs.dist for the resolver
        # to work.
        utils.stub_item_attr_value(self, dist, 'default_working_set', mock_ws)
        # still specify the working set.
        registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
        self.assertEqual(
            1, len(list(registry.iter_records_for('de_normal_name'))))
        # also test internal consistency
        self.assertIn('de_normal_name', registry.compat_builders['full'])
        self.assertIn('de_normal_name', registry.packages)
        default = registry.get_artifact_filename('de_normal_name', 'full.js')
        normal = registry.get_artifact_filename(safe_name('de_normal_name'),
                                                'full.js')
        self.assertEqual(default, normal)
Esempio n. 2
0
    def test_standard(self):
        d_egg_root = join(mkdtemp(self), 'dummyns')

        make_dummy_dist(self, ((
            'namespace_packages.txt',
            'dummyns\n',
        ), (
            'entry_points.txt',
            '[dummyns]\n'
            'dummyns = dummyns:attr\n',
        ),), 'dummyns', '1.0', working_dir=d_egg_root)
        working_set = pkg_resources.WorkingSet([
            d_egg_root,
            self.ds_egg_root,
        ])
        # ensure the working_set is providing the distributions being
        # mocked here so that resource_filename will resolve correctly
        stub_item_attr_value(self, pkg_resources, 'working_set', working_set)

        moddir = join(d_egg_root, 'dummyns')
        os.makedirs(moddir)

        # make this also a proper thing
        with open(join(moddir, '__init__.py'), 'w') as fd:
            fd.write('')

        dummyns_ep = next(working_set.iter_entry_points('dummyns'))
        p = indexer.resource_filename_mod_entry_point('dummyns', dummyns_ep)

        # finally, this should work.
        self.assertEqual(normcase(p), normcase(moddir))
Esempio n. 3
0
    def test_deprecation_test_package_flag(self):
        make_dummy_dist(self, ((
            'entry_points.txt',
            '[calmjs.runtime]\n'
            'fakekarma = calmjs.testing.mocks:krt\n'
        ),), 'example.package', '1.0')
        working_set = WorkingSet([self._calmjs_testing_tmpdir])

        self.addCleanup(delattr, mocks, 'krt')
        mocks.krt = KarmaRuntime(KarmaDriver(), working_set=working_set)
        runtime = Runtime(working_set=working_set)
        argparser = runtime.argparser

        import warnings
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            ns = argparser.parse_args([
                'fakekarma',
                '--test-package=pkg1', '--test-registries=dummy1',
            ])

        self.assertIn(
            "please use '--test-with-package' instead", str(w[0].message))
        self.assertEqual(ns.calmjs_test_registry_names, ['dummy1'])
        self.assertEqual(ns.test_package_names, ['pkg1'])
Esempio n. 4
0
 def test_missing_distribution(self):
     d_egg_root = join(mkdtemp(self), 'dummyns')
     make_dummy_dist(self, (
         (
             'namespace_packages.txt',
             'not_ns\n',
         ),
         (
             'entry_points.txt',
             '[dummyns]\n'
             'dummyns = dummyns:attr\n',
         ),
     ),
                     'dummyns',
                     '2.0',
                     working_dir=d_egg_root)
     working_set = pkg_resources.WorkingSet([
         d_egg_root,
         self.ds_egg_root,
     ])
     dummyns_ep = next(working_set.iter_entry_points('dummyns'))
     with pretty_logging(stream=StringIO()) as fd:
         p = indexer.resource_filename_mod_entry_point(
             'dummyns', dummyns_ep)
     # not stubbed working_set, so this is derived using fallback
     # value from the sys.modules['dummyns'] location
     self.assertEqual(normcase(p), normcase(self.dummyns_path))
     self.assertIn("distribution 'dummyns 2.0' not found", fd.getvalue())
Esempio n. 5
0
    def test_iter_builders_verify_export_target(self):
        mod = ModuleType('calmjs_testing_dummy')
        mod.complete = generic_builder
        self.addCleanup(sys.modules.pop, 'calmjs_testing_dummy')
        sys.modules['calmjs_testing_dummy'] = mod

        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (('entry_points.txt', '\n'.join([
            '[calmjs.artifacts]',
            'artifact.js = calmjs_testing_dummy:complete',
            'invalid.js = calmjs_testing_dummy:complete',
        ])), ),
                              'app',
                              '1.0',
                              working_dir=working_dir)
        mock_ws = WorkingSet([working_dir])

        class FakeArtifactRegistry(ArtifactRegistry):
            def verify_export_target(self, export_target):
                return 'invalid.js' not in export_target

        registry = FakeArtifactRegistry('calmjs.artifacts',
                                        _working_set=mock_ws)

        # the invalid.js should be filtered out
        with pretty_logging(stream=mocks.StringIO()) as stream:
            self.assertEqual(1, len(list(registry.iter_builders_for('app'))))
        self.assertIn("invalid.js' has been rejected", stream.getvalue())
Esempio n. 6
0
    def test_karma_runtime_integration_ignore_error(self):
        stub_stdouts(self)
        target = join(mkdtemp(self), 'target')
        build_dir = mkdtemp(self)
        stub_item_attr_value(
            self, mocks, 'dummy',
            ToolchainRuntime(NullToolchain()),
        )
        make_dummy_dist(self, ((
            'entry_points.txt',
            '[calmjs.runtime]\n'
            'null = calmjs.testing.mocks:dummy\n'
        ),), 'example.package', '1.0')
        working_set = WorkingSet([self._calmjs_testing_tmpdir])
        rt = KarmaRuntime(self.driver, working_set=working_set)
        result = rt([
            '-I', 'null', '--export-target', target, '--build-dir', build_dir,
        ])
        self.assertIn('karma_config_path', result)
        self.assertTrue(exists(result['karma_config_path']))
        self.assertFalse(result.get('karma_abort_on_test_failure'))
        self.assertIn(
            "karma exited with return code 1; continuing as specified",
            sys.stderr.getvalue()
        )

        # ensure coverage isn't run at all.
        coverage_report_dir = join(build_dir, 'coverage')
        self.assertFalse(exists(coverage_report_dir))
Esempio n. 7
0
    def test_iter_builders_side_effect(self):
        # inject dummy module and add cleanup
        mod = ModuleType('calmjs_testing_dummy')
        mod.complete = generic_builder
        self.addCleanup(sys.modules.pop, 'calmjs_testing_dummy')
        sys.modules['calmjs_testing_dummy'] = mod

        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (('entry_points.txt', '\n'.join([
            '[calmjs.artifacts]',
            'artifact.js = calmjs_testing_dummy:complete',
        ])), ),
                              'app',
                              '1.0',
                              working_dir=working_dir)
        mock_ws = WorkingSet([working_dir])
        registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
        registry.update_artifact_metadata('app', {})

        root = join(working_dir, 'app-1.0.egg-info', 'calmjs_artifacts')
        self.assertFalse(exists(root))
        ep, toolchain, spec = next(registry.iter_builders_for('app'))
        self.assertFalse(exists(root))
        # directory only created after the toolchain is executed
        toolchain(spec)
        self.assertTrue(exists(root))
Esempio n. 8
0
    def setUp(self):
        # save working directory
        remember_cwd(self)

        # All the pre-made setup.
        stub_mod_call(self, cli)
        app = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'jquery': '~1.11.0'},
            })),
        ), 'foo', '1.9.0')
        underscore = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'underscore': '~1.8.0'},
            })),
        ), 'underscore', '1.8.0')
        named = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'jquery': '~3.0.0'},
                'name': 'named-js',
            })),
        ), 'named', '2.0.0')
        working_set = WorkingSet()
        working_set.add(app, self._calmjs_testing_tmpdir)
        working_set.add(underscore, self._calmjs_testing_tmpdir)
        working_set.add(named, self._calmjs_testing_tmpdir)
        stub_item_attr_value(self, dist, 'default_working_set', working_set)
        stub_check_interactive(self, True)
Esempio n. 9
0
    def setUp(self):
        # save working directory
        remember_cwd(self)

        # All the pre-made setup.
        stub_mod_call(self, cli)
        app = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'jquery': '~1.11.0'},
            })),
        ), 'foo', '1.9.0')
        underscore = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'underscore': '~1.8.0'},
            })),
        ), 'underscore', '1.8.0')
        named = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'jquery': '~3.0.0'},
                'name': 'named-js',
            })),
        ), 'named', '2.0.0')
        working_set = WorkingSet()
        working_set.add(app, self._calmjs_testing_tmpdir)
        working_set.add(underscore, self._calmjs_testing_tmpdir)
        working_set.add(named, self._calmjs_testing_tmpdir)
        stub_item_attr_value(self, dist, 'default_working_set', working_set)
        stub_mod_check_interactive(self, [cli], True)
        # also save this
        self.inst_interactive = npm.npm.cli_driver.interactive
Esempio n. 10
0
    def setup_runtime(self):
        make_dummy_dist(self, (('bower.json',
                                json.dumps({
                                    'name': 'site',
                                    'dependencies': {
                                        'jquery': '~3.1.0',
                                    },
                                })), ), 'example.package1', '1.0')

        make_dummy_dist(self, (('bower.json',
                                json.dumps({
                                    'name': 'site',
                                    'dependencies': {
                                        'underscore': '~1.8.3',
                                    },
                                })), ), 'example.package2', '2.0')

        working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])

        # Stub out the underlying data needed for the cli for the tests
        # to test against our custom data for reproducibility.
        stub_item_attr_value(self, dist, 'default_working_set', working_set)
        stub_mod_check_interactive(self, [cli], True)

        # Of course, apply a mock working set for the runtime instance
        # so it can use the bower runtime.
        working_set = mocks.WorkingSet({
            'calmjs.runtime': [
                'bower = calmjs.bower:bower.runtime',
            ],
        })
        return runtime.Runtime(working_set=working_set)
Esempio n. 11
0
    def test_update_artifact_metadata(self):
        # inject dummy module and add cleanup
        mod = ModuleType('calmjs_testing_dummy')
        mod.complete = generic_builder
        self.addCleanup(sys.modules.pop, 'calmjs_testing_dummy')
        sys.modules['calmjs_testing_dummy'] = mod

        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (
            ('requires.txt', '\n'.join([
                'calmjs',
            ])),
            ('entry_points.txt', '\n'.join([
                '[calmjs.artifacts]',
                'artifact.js = calmjs_testing_dummy:complete',
            ])),
        ), 'app', '1.0', working_dir=working_dir)
        # mock a version of calmjs within that environment too
        utils.make_dummy_dist(self, (
            ('entry_points.txt', ''),
        ), 'calmjs', '1.0', working_dir=working_dir)

        mock_ws = WorkingSet([working_dir])
        registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
        registry.update_artifact_metadata('app', {})
        self.assertTrue(exists(registry.metadata.get('app')))

        with pretty_logging(stream=mocks.StringIO()) as s:
            registry.update_artifact_metadata('calmjs', {})
        self.assertIn(
            "package 'calmjs' has not declare any artifacts", s.getvalue())
Esempio n. 12
0
    def test_update_artifact_metadata(self):
        # inject dummy module and add cleanup
        mod = ModuleType('calmjs_testing_dummy')
        mod.complete = generic_builder
        self.addCleanup(sys.modules.pop, 'calmjs_testing_dummy')
        sys.modules['calmjs_testing_dummy'] = mod

        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (
            ('requires.txt', '\n'.join([
                'calmjs',
            ])),
            ('entry_points.txt', '\n'.join([
                '[calmjs.artifacts]',
                'artifact.js = calmjs_testing_dummy:complete',
            ])),
        ),
                              'app',
                              '1.0',
                              working_dir=working_dir)
        # mock a version of calmjs within that environment too
        utils.make_dummy_dist(self, (('entry_points.txt', ''), ),
                              'calmjs',
                              '1.0',
                              working_dir=working_dir)

        mock_ws = WorkingSet([working_dir])
        registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
        registry.update_artifact_metadata('app', {})
        self.assertTrue(exists(registry.metadata.get('app')))

        with pretty_logging(stream=mocks.StringIO()) as s:
            registry.update_artifact_metadata('calmjs', {})
        self.assertIn("package 'calmjs' has not declare any artifacts",
                      s.getvalue())
Esempio n. 13
0
    def test_relocated_distribution(self):
        root = mkdtemp(self)
        dummyns_path = join(root, 'dummyns')

        make_dummy_dist(self, ((
            'namespace_packages.txt',
            'dummyns\n',
        ), (
            'entry_points.txt',
            '[dummyns]\n'
            'dummyns = dummyns:attr\n',
        ),), 'dummyns', '1.0', working_dir=root)
        working_set = pkg_resources.WorkingSet([
            root,
            self.ds_egg_root,
        ])
        # activate this as the working set
        stub_item_attr_value(self, pkg_resources, 'working_set', working_set)
        dummyns_ep = next(working_set.iter_entry_points('dummyns'))
        with pretty_logging(stream=StringIO()) as fd:
            p = indexer.resource_filename_mod_entry_point(
                'dummyns', dummyns_ep)
        # since the actual location is not created)
        self.assertIsNone(p)
        self.assertIn("does not exist", fd.getvalue())

        # retry with the module directory created at the expected location
        os.mkdir(dummyns_path)
        with pretty_logging(stream=StringIO()) as fd:
            p = indexer.resource_filename_mod_entry_point(
                'dummyns', dummyns_ep)
        self.assertEqual(normcase(p), normcase(dummyns_path))
        self.assertEqual('', fd.getvalue())
Esempio n. 14
0
    def test_iter_builders_side_effect_build_issue(self):
        mod = ModuleType('calmjs_testing_dummy')
        mod.complete = generic_builder
        self.addCleanup(sys.modules.pop, 'calmjs_testing_dummy')
        sys.modules['calmjs_testing_dummy'] = mod

        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                '[calmjs.artifacts]',
                'artifact.js = calmjs_testing_dummy:complete',
            ])),
        ), 'app', '1.0', working_dir=working_dir)
        mock_ws = WorkingSet([working_dir])
        registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
        registry.update_artifact_metadata('app', {})

        root = join(working_dir, 'app-1.0.egg-info', 'calmjs_artifacts')
        # clog the build directory so build cannot happen
        with open(join(root), 'w'):
            pass

        ep, toolchain, spec = next(registry.iter_builders_for('app'))
        check = []
        spec.advise('after_prepare', check.append, True)
        with pretty_logging(stream=mocks.StringIO()) as stream:
            with self.assertRaises(ToolchainAbort):
                toolchain(spec)
        self.assertIn(
            "an advice in group 'before_prepare' triggered an abort",
            stream.getvalue())
        # should have stopped at before_prepare
        self.assertFalse(check)
Esempio n. 15
0
    def test_iter_builders_side_effect(self):
        # inject dummy module and add cleanup
        mod = ModuleType('calmjs_testing_dummy')
        mod.complete = generic_builder
        self.addCleanup(sys.modules.pop, 'calmjs_testing_dummy')
        sys.modules['calmjs_testing_dummy'] = mod

        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                '[calmjs.artifacts]',
                'artifact.js = calmjs_testing_dummy:complete',
            ])),
        ), 'app', '1.0', working_dir=working_dir)
        mock_ws = WorkingSet([working_dir])
        registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
        registry.update_artifact_metadata('app', {})

        root = join(working_dir, 'app-1.0.egg-info', 'calmjs_artifacts')
        self.assertFalse(exists(root))
        ep, toolchain, spec = next(registry.iter_builders_for('app'))
        self.assertFalse(exists(root))
        # directory only created after the toolchain is executed
        toolchain(spec)
        self.assertTrue(exists(root))
Esempio n. 16
0
    def test_iter_builders_verify_export_target(self):
        mod = ModuleType('calmjs_testing_dummy')
        mod.complete = generic_builder
        self.addCleanup(sys.modules.pop, 'calmjs_testing_dummy')
        sys.modules['calmjs_testing_dummy'] = mod

        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                '[calmjs.artifacts]',
                'artifact.js = calmjs_testing_dummy:complete',
                'invalid.js = calmjs_testing_dummy:complete',
            ])),
        ), 'app', '1.0', working_dir=working_dir)
        mock_ws = WorkingSet([working_dir])

        class FakeArtifactRegistry(ArtifactRegistry):
            def verify_export_target(self, export_target):
                return 'invalid.js' not in export_target

        registry = FakeArtifactRegistry(
            'calmjs.artifacts', _working_set=mock_ws)

        # the invalid.js should be filtered out
        with pretty_logging(stream=mocks.StringIO()) as stream:
            self.assertEqual(1, len(list(registry.iter_builders_for('app'))))
        self.assertIn("invalid.js' has been rejected", stream.getvalue())
Esempio n. 17
0
    def test_iter_builders_side_effect_build_issue(self):
        mod = ModuleType('calmjs_testing_dummy')
        mod.complete = generic_builder
        self.addCleanup(sys.modules.pop, 'calmjs_testing_dummy')
        sys.modules['calmjs_testing_dummy'] = mod

        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (('entry_points.txt', '\n'.join([
            '[calmjs.artifacts]',
            'artifact.js = calmjs_testing_dummy:complete',
        ])), ),
                              'app',
                              '1.0',
                              working_dir=working_dir)
        mock_ws = WorkingSet([working_dir])
        registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
        registry.update_artifact_metadata('app', {})

        root = join(working_dir, 'app-1.0.egg-info', 'calmjs_artifacts')
        # clog the build directory so build cannot happen
        with open(join(root), 'w'):
            pass

        ep, toolchain, spec = next(registry.iter_builders_for('app'))
        check = []
        spec.advise('after_prepare', check.append, True)
        with pretty_logging(stream=mocks.StringIO()) as stream:
            with self.assertRaises(ToolchainAbort):
                toolchain(spec)
        self.assertIn("an advice in group 'before_prepare' triggered an abort",
                      stream.getvalue())
        # should have stopped at before_prepare
        self.assertFalse(check)
Esempio n. 18
0
    def test_registry_reserved(self):
        make_dummy_dist(self,
                        (('entry_points.txt', '[calmjs.reserved]\n'
                          'calmjs.r1 = calmjs\n'
                          'calmjs.r3 = an.external\n'
                          '\n'
                          '[calmjs.registry]\n'
                          'calmjs.r1 = calmjs.module:ModuleRegistry\n'
                          'calmjs.r2 = calmjs.module:ModuleRegistry\n'
                          'calmjs.r3 = calmjs.module:ModuleRegistry\n'), ),
                        'calmjs', '1.0')

        make_dummy_dist(self, (
            (
                'requires.txt',
                'calmjs',
            ),
            ('entry_points.txt', '[calmjs.reserved]\n'
             'calmjs.r1 = an.external\n'
             'calmjs.r2 = calmjs\n'
             'calmjs.r3 = calmjs\n'
             '\n'
             '[calmjs.registry]\n'
             'calmjs.r1 = calmjs.testing.module3.module:CustomModuleRegistry\n'
             'calmjs.r2 = calmjs.testing.module3.module:CustomModuleRegistry\n'
             'calmjs.r3 = calmjs.testing.module3.module:CustomModuleRegistry\n'
             ),
        ), 'an.external', '2.0')

        working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])
        with pretty_logging(stream=mocks.StringIO()) as stream:
            registry = calmjs.registry.Registry('calmjs.registry',
                                                _working_set=working_set)

        from calmjs.testing.module3.module import CustomModuleRegistry
        from calmjs.module import ModuleRegistry

        r1 = registry.get('calmjs.r1')
        r2 = registry.get('calmjs.r2')
        r3 = registry.get('calmjs.r3')

        # since this one is reserved to calmjs, not registered
        self.assertFalse(isinstance(r1, CustomModuleRegistry))
        self.assertTrue(isinstance(r1, ModuleRegistry))
        # whatever this is.
        self.assertTrue(isinstance(r2, ModuleRegistry))
        # this one is reserved to an.external
        self.assertTrue(isinstance(r3, CustomModuleRegistry))

        log = stream.getvalue()
        self.assertIn(
            "registry 'calmjs.r1' for 'calmjs.registry' is reserved for "
            "package 'calmjs'", log)
        self.assertIn(
            "registry 'calmjs.r3' for 'calmjs.registry' is reserved for "
            "package 'an.external'", log)
        self.assertIn(
            "registry 'calmjs.r2' for 'calmjs.registry' is already registered",
            log)
Esempio n. 19
0
    def test_karma_runtime_run_toolchain_auto_test_registry(self):
        def cleanup():
            root_registry.records.pop('calmjs.dev.module.tests', None)
            root_registry.records.pop(CALMJS_TOOLCHAIN_ADVICE, None)

        self.addCleanup(cleanup)
        stub_stdouts(self)

        make_dummy_dist(self, ((
            'entry_points.txt',
            '[calmjs.toolchain.advice]\n'
            'calmjs.dev.toolchain:KarmaToolchain'
            ' = calmjs.tests.test_toolchain:dummy\n'
        ),), 'example.package', '1.0')

        # in the main distribution we did not define this to avoid
        # potential contamination of test data by this package with the
        # rest of the framework, so we stub that function

        _called = []

        def fake_flatten_module_registry_names(package_names):
            _called.extend(package_names)
            return ['calmjs.dev.module']

        from calmjs.dev import toolchain
        stub_item_attr_value(
            self, toolchain, 'flatten_module_registry_names',
            fake_flatten_module_registry_names
        )

        working_set = WorkingSet([self._calmjs_testing_tmpdir])

        root_registry.records[
            CALMJS_TOOLCHAIN_ADVICE] = AdviceRegistry(
                CALMJS_TOOLCHAIN_ADVICE, _working_set=working_set)

        # manipulate the registry to remove the fail test
        reg = root_registry.get('calmjs.dev.module.tests')
        reg.records['calmjs.dev.tests'].pop('calmjs/dev/tests/test_fail', '')

        # use the full blown runtime
        rt = KarmaRuntime(self.driver)
        # the artifact in our case is identical to the source file
        artifact = resource_filename('calmjs.dev', 'main.js')
        result = rt([
            'run', '--artifact', artifact,
            '--test-with-package', 'calmjs.dev',
            '--toolchain-package', 'example.package',
        ])
        self.assertIn('calmjs.dev', _called)
        self.assertIn('karma_config_path', result)
        self.assertEqual(result['artifact_paths'], [artifact])
        # the spec key is written.
        self.assertEqual(result['dummy'], ['dummy'])
        self.assertEqual(
            result['calmjs_module_registry_names'], ['calmjs.dev.module'])
        self.assertIn(
            'calmjs/dev/tests/test_main', result['test_module_paths_map'])
Esempio n. 20
0
    def test_artifact_test_simulation(self):
        # don't actually run karma, since we are not setting up the full
        # integration environment for this isolated test - also keep the
        # spec reference here and have the helper return it so the
        # simplified verification can be done.
        spec = Spec(karma_advice_group=None)

        def generic_tester(package_names, export_target):
            spec['export_target'] = export_target
            return KarmaToolchain(), spec,

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

        self.addCleanup(sys.modules.pop, 'calmjs_dev_tester')
        sys.modules['calmjs_dev_tester'] = tester_mod

        working_dir = utils.mkdtemp(self)

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

        mock_ws = WorkingSet([working_dir])
        utils.stub_item_attr_value(self, dist, 'default_working_set', mock_ws)
        registry = ArtifactTestRegistry(
            'calmjs.artifacts.tests', _working_set=mock_ws)

        artifact_name = registry.get_artifact_filename('app', 'artifact.js')

        with self.assertRaises(ToolchainCancel) as e:
            # file not exist yet will cancel the execution
            registry.prepare_export_location(artifact_name)

        self.assertIn("missing export_target '", str(e.exception))
        self.assertIn("artifact.js'", str(e.exception))

        mkdir(dirname(artifact_name))
        with open(artifact_name, 'w') as fd:
            fd.write('console.log("test artifact");\n')

        # no longer raise an exception
        registry.prepare_export_location(artifact_name)

        self.assertNotIn('before_prepare', spec._advices)
        registry.process_package('app')
        # cheat a bit by probing some private bits to see that the
        # relevant advice is planted but not executed
        self.assertEqual(1, len(spec._advices['before_prepare']))
        # for whatever reason, instance methods are not identities of
        # itself thus `is` cannot be used as the validation operator.
        self.assertEqual(
            spec._advices['before_prepare'][0][0],
            registry.prepare_export_location,
        )
Esempio n. 21
0
    def test_record_internal_normalization(self):
        make_dummy_dist(self, (('entry_points.txt', '[modules]\n'
                                'some/where/path.js = calmjs.module\n'), ),
                        'unsafe_name', '1.0')

        working_set = WorkingSet([self._calmjs_testing_tmpdir])
        registry = DummyModuleRegistry('modules', _working_set=working_set)
        self.assertEqual(1,
                         len(registry.get_records_for_package('unsafe_name')))
Esempio n. 22
0
    def test_node_modules_registry_flattening(self):
        lib = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('bower.json',
             json.dumps({
                 'dependencies': {
                     'jquery': '~1.8.3',
                     'underscore': '1.8.3',
                 },
             })),
            ('extras_calmjs.json',
             json.dumps({
                 'bower_components': {
                     'jquery': 'jquery/dist/jquery.js',
                     'underscore': 'underscore/underscore-min.js',
                 },
                 'something_else': {
                     'parent': 'lib'
                 },
             })),
        ), 'lib', '1.0.0')

        app = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([
                'lib>=1.0.0',
            ])),
            ('bower.json',
             json.dumps({
                 'dependencies': {
                     'jquery': '~3.0.0',
                 },
             })),
            ('extras_calmjs.json',
             json.dumps({
                 'bower_components': {
                     'jquery': 'jquery/dist/jquery.min.js',
                 },
                 'something_else': {
                     'child': 'named'
                 },
             })),
        ), 'app', '2.0')

        working_set = WorkingSet()
        working_set.add(lib, self._calmjs_testing_tmpdir)
        working_set.add(app, self._calmjs_testing_tmpdir)

        results = dist.flatten_extras_calmjs(['app'], working_set=working_set)
        self.assertEqual(
            results['bower_components'], {
                'jquery': 'jquery/dist/jquery.min.js',
                'underscore': 'underscore/underscore-min.js',
            })
        # child takes precedences as this was not specified to be merged
        self.assertEqual(results['something_else'], {'child': 'named'})
Esempio n. 23
0
    def test_record_internal_normalization(self):
        make_dummy_dist(self, ((
            'entry_points.txt',
            '[modules]\n'
            'some/where/path.js = calmjs.module\n'
        ),), 'unsafe_name', '1.0')

        working_set = WorkingSet([self._calmjs_testing_tmpdir])
        registry = DummyModuleRegistry('modules', _working_set=working_set)
        self.assertEqual(
            1, len(registry.get_records_for_package('unsafe_name')))
Esempio n. 24
0
    def test_iter_builders_verify_export_target_legacy(self):
        mod = ModuleType('calmjs_testing_dummy')
        mod.complete = generic_builder
        self.addCleanup(sys.modules.pop, 'calmjs_testing_dummy')
        sys.modules['calmjs_testing_dummy'] = mod

        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (('entry_points.txt', '\n'.join([
            '[calmjs.artifacts]',
            'artifact.js = calmjs_testing_dummy:complete',
        ])), ),
                              'app',
                              '1.0',
                              working_dir=working_dir)
        mock_ws = WorkingSet([working_dir])
        root = join(working_dir, 'app-1.0.egg-info', 'calmjs_artifacts')
        targets = []

        def check_target(export_target):
            # manually create the root here, to allow the completion
            # of the build process by doing what an existing
            # implementation that reuse existing code might have done.
            targets.append(export_target)
            prepare_export_location(export_target)

        # ensure that the build directory exists, because the default

        class FakeArtifactRegistry(ArtifactRegistry):
            def verify_export_target(self, export_target):
                return check_target

        registry = FakeArtifactRegistry('calmjs.artifacts',
                                        _working_set=mock_ws)

        # the invalid.js should be filtered out
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            self.assertEqual(1, len(list(registry.iter_builders_for('app'))))

        self.assertIn(
            "FakeArtifactRegistry.verify_export_target returned a callable",
            str(w[-1].message))

        # ensure no early execution of check_target
        self.assertFalse(targets)
        self.assertFalse(exists(root))
        with warnings.catch_warnings(record=True):
            with pretty_logging(stream=mocks.StringIO()):
                registry.process_package('app')
        # ensure no early execution of check_target
        self.assertTrue(targets)
        self.assertTrue(exists(root))
Esempio n. 25
0
    def test_module_module_registry_names_success(self):
        base = make_dummy_dist(self, (('requires.txt', ''), ), 'base', '1.0.0')

        lib = make_dummy_dist(self, (
            ('requires.txt', 'base>=1.0.0'),
            (calmjs_dist.CALMJS_MODULE_REGISTRY_TXT, '\n'.join(
                ['reg1', 'reg2'])),
        ), 'lib', '1.0.0')

        app = make_dummy_dist(self, (
            ('requires.txt', 'lib>=1.0.0'),
            (calmjs_dist.CALMJS_MODULE_REGISTRY_TXT, '\n'.join(
                ['reg2', 'reg3'])),
        ), 'app', '2.0')

        working_set = pkg_resources.WorkingSet()
        working_set.add(base, self._calmjs_testing_tmpdir)
        working_set.add(lib, self._calmjs_testing_tmpdir)
        working_set.add(app, self._calmjs_testing_tmpdir)

        self.assertEqual(
            calmjs_dist.get_module_registry_names(['base'],
                                                  working_set=working_set), [])
        self.assertEqual(
            calmjs_dist.get_module_registry_names(['lib'],
                                                  working_set=working_set),
            ['reg1', 'reg2'])
        self.assertEqual(
            calmjs_dist.get_module_registry_names(['app'],
                                                  working_set=working_set),
            ['reg2', 'reg3'])
        self.assertEqual(
            calmjs_dist.get_module_registry_names(['nothing'],
                                                  working_set=working_set), [])

        self.assertEqual(
            calmjs_dist.flatten_module_registry_names(['base'],
                                                      working_set=working_set),
            [])
        self.assertEqual(
            calmjs_dist.flatten_module_registry_names(['lib'],
                                                      working_set=working_set),
            ['reg1', 'reg2'])
        self.assertEqual(
            calmjs_dist.flatten_module_registry_names(['app'],
                                                      working_set=working_set),
            ['reg1', 'reg2', 'reg3'])
        self.assertEqual(
            calmjs_dist.flatten_module_registry_names(['nothing'],
                                                      working_set=working_set),
            [])
Esempio n. 26
0
    def test_iter_builders_verify_export_target_legacy(self):
        mod = ModuleType('calmjs_testing_dummy')
        mod.complete = generic_builder
        self.addCleanup(sys.modules.pop, 'calmjs_testing_dummy')
        sys.modules['calmjs_testing_dummy'] = mod

        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                '[calmjs.artifacts]',
                'artifact.js = calmjs_testing_dummy:complete',
            ])),
        ), 'app', '1.0', working_dir=working_dir)
        mock_ws = WorkingSet([working_dir])
        root = join(working_dir, 'app-1.0.egg-info', 'calmjs_artifacts')
        targets = []

        def check_target(export_target):
            # manually create the root here, to allow the completion
            # of the build process by doing what an existing
            # implementation that reuse existing code might have done.
            targets.append(export_target)
            prepare_export_location(export_target)

        # ensure that the build directory exists, because the default

        class FakeArtifactRegistry(ArtifactRegistry):
            def verify_export_target(self, export_target):
                return check_target

        registry = FakeArtifactRegistry(
            'calmjs.artifacts', _working_set=mock_ws)

        # the invalid.js should be filtered out
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            self.assertEqual(1, len(list(registry.iter_builders_for('app'))))

        self.assertIn(
            "FakeArtifactRegistry.verify_export_target returned a callable",
            str(w[-1].message))

        # ensure no early execution of check_target
        self.assertFalse(targets)
        self.assertFalse(exists(root))
        with warnings.catch_warnings(record=True):
            with pretty_logging(stream=mocks.StringIO()):
                registry.process_package('app')
        # ensure no early execution of check_target
        self.assertTrue(targets)
        self.assertTrue(exists(root))
Esempio n. 27
0
    def test_karma_runtime_integration_coverage(self):

        class DummyToolchain(NullToolchain):
            """
            Need this step to prepare some actual sources from this
            project, and we are cheating a bit due to the lack of actual
            registry setup.
            """

            def prepare(self, spec):
                # manually set up the source and the tests.
                main = resource_filename(
                    'calmjs.dev', 'main.js')
                test_main = resource_filename(
                    'calmjs.dev.tests', 'test_main.js')
                spec.update(dict(
                    transpile_sourcepath={
                        'calmjs/dev/main': main,
                    },
                    test_module_paths_map={
                        'calmjs/test_main': test_main,
                    },
                ))

        stub_stdouts(self)
        target = join(mkdtemp(self), 'target')
        build_dir = mkdtemp(self)
        coverage_report_dir = join(build_dir, 'coverage')
        # ensure this does not already exist
        self.assertFalse(exists(coverage_report_dir))

        stub_item_attr_value(
            self, mocks, 'dummy',
            ToolchainRuntime(DummyToolchain()),
        )
        make_dummy_dist(self, ((
            'entry_points.txt',
            '[calmjs.runtime]\n'
            'null = calmjs.testing.mocks:dummy\n'
        ),), 'example.package', '1.0')
        working_set = WorkingSet([self._calmjs_testing_tmpdir])
        rt = KarmaRuntime(self.driver, working_set=working_set)
        result = rt([
            '--coverage', '--cover-report-dir', coverage_report_dir,
            'null', '--export-target', target, '--build-dir', build_dir,
        ])

        # ensure coverage report created
        self.assertTrue(result['coverage_enable'])
        self.assertTrue(exists(coverage_report_dir))
Esempio n. 28
0
    def tests_flatten_egginfo_json_missing_deps(self):
        """
        Missing dependencies should not cause a hard failure.
        """

        make_dummy_dist(self, (('requires.txt', '\n'.join([
            'uilib>=1.0',
        ])), ), 'app', '2.0')

        working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])

        # Python dependency acquisition failures should fail hard.
        with self.assertRaises(pkg_resources.DistributionNotFound):
            calmjs_dist.flatten_egginfo_json(['app'], working_set=working_set)
Esempio n. 29
0
    def tests_flatten_egginfo_json_nulled(self):
        """
        Need to ensure the *correct* version is picked.
        """

        lib = make_dummy_dist(
            self,
            (  # noqa: F841
                ('requires.txt', '\n'.join([])),
                (self.pkgname,
                 json.dumps({
                     'dependencies': {
                         'jquery': '~3.0.0',
                         'left-pad': '1.1.1',
                     },
                 })),
            ),
            'lib',
            '1.0.0')

        app = make_dummy_dist(
            self,
            (  # noqa: F841
                ('requires.txt', '\n'.join([
                    'lib>=1.0.0',
                ])),
                (self.pkgname,
                 json.dumps({
                     'dependencies': {
                         'jquery': '~3.0.0',
                         'left-pad': None,
                     },
                 })),
            ),
            'app',
            '2.0')

        working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])

        answer = {
            'dependencies': {
                'jquery': '~3.0.0',
                # left-pad will be absent as app removed via None.
            },
            'devDependencies': {},
        }
        result = calmjs_dist.flatten_egginfo_json(['app'],
                                                  working_set=working_set)
        self.assertEqual(result, answer)
Esempio n. 30
0
    def tests_instantiate_integration_registries(self):
        """
        Ensure that the integration registries, specifically the root
        registry, be instantiated (or re-instantiated) in a way that
        satisfies expectations of integration test creators.
        """

        make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                '[calmjs.registry]',
                'dummy.module = calmjs.module:ModuleRegistry',
                'other.module = calmjs.module:ModuleRegistry',
            ])),
        ), 'somepkg', '1.0')

        working_set = WorkingSet([self._calmjs_testing_tmpdir])
        registry = utils.instantiate_integration_registries(
            working_set, None,
            'dummy.module',
        )
        dummy_module = registry.get('dummy.module')
        other_module = registry.get('other.module')
        self.assertEqual('dummy.module', dummy_module.registry_name)
        self.assertIsNone(registry.get('dummy.module.tests'))

        make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                '[calmjs.registry]',
                'dummy.module.tests = calmjs.module:ModuleRegistry',
            ])),
        ), 'somepkg.testing', '1.0')
        # re-add the tmpdir to reinitialize the working set with the
        # newly added entry points
        working_set.add_entry(self._calmjs_testing_tmpdir)

        reinstantiated_registry = utils.instantiate_integration_registries(
            working_set, registry,
            'dummy.module',
            'dummy.module.tests',
        )
        # ensure that it is the same instance, as this could be used to
        # reinstantiate the registry with the additional entries.
        self.assertIs(registry, reinstantiated_registry)
        # the inner registries should be renewed.
        self.assertIsNot(dummy_module, registry.get('dummy.module'))
        # the not reinstantiated version is not renewed
        self.assertIs(other_module, registry.get('other.module'))
        # the newly added entry points should resolve now.
        self.assertIsNotNone(registry.get('dummy.module.tests'))
Esempio n. 31
0
 def test_pkg_names_to_dists(self):
     base = make_dummy_dist(self, (('requires.txt', ''), ), 'base', '1.0.0')
     working_set = pkg_resources.WorkingSet()
     working_set.add(base, self._calmjs_testing_tmpdir)
     self.assertEqual(
         calmjs_dist.pkg_names_to_dists(['nothing', 'base'],
                                        working_set=working_set), [base])
Esempio n. 32
0
    def tests_flatten_egginfo_json_missing_deps(self):
        """
        Missing dependencies should not cause a hard failure.
        """

        make_dummy_dist(self, (
            ('requires.txt', '\n'.join([
                'uilib>=1.0',
            ])),
        ), 'app', '2.0')

        working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])

        # Python dependency acquisition failures should fail hard.
        with self.assertRaises(pkg_resources.DistributionNotFound):
            calmjs_dist.flatten_egginfo_json(['app'], working_set=working_set)
Esempio n. 33
0
    def tests_make_dummy_dist_working_set(self):
        """
        Dummy distributions should work with pkg_resources.WorkingSet
        """

        # This also shows how WorkingSet might work.
        # A WorkingSet is basically a way to get to a collection of
        # distributions via the list of specified paths.  By default it
        # will go for sys.path, but for testing purposes we can control
        # this by creating our own instance on a temporary directory.

        parentpkg = make_dummy_dist(self, (  # noqa: F841
            ('requires.txt', '\n'.join([
            ])),
        ), 'parentpkg', '0.8')

        childpkg = make_dummy_dist(self, (  # noqa: F841
            ('requires.txt', '\n'.join([
                'parentpkg>=0.8',
            ])),
        ), 'childpkg', '0.1')

        grandchildpkg = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([
                'childpkg>=0.1',
                'parentpkg>=0.8',
            ])),
        ), 'grandchildpkg', '0.8')

        working_set = WorkingSet([self._calmjs_testing_tmpdir])
        distributions = working_set.resolve(grandchildpkg.requires())
        self.assertEqual(len(distributions), 2)
        self.assertEqual(distributions[0].requires(), [])
        self.assertEqual(distributions[1].requires(), [
            Requirement.parse('parentpkg>=0.8')])

        # overwrite should work
        make_dummy_dist(self, (
            ('requires.txt', '\n'.join([
                'parentpkg>=0.7',
            ])),
        ), 'childpkg', '0.1')
        # but the data have to be recreated
        working_set = WorkingSet([self._calmjs_testing_tmpdir])
        distributions = working_set.resolve(grandchildpkg.requires())
        self.assertEqual(distributions[1].requires(), [
            Requirement.parse('parentpkg>=0.7')])
Esempio n. 34
0
    def test_command_stacking(self):

        def cleanup():
            del mocks.nrt
            del mocks.krt

        self.addCleanup(cleanup)

        make_dummy_dist(self, ((
            'entry_points.txt',
            '[calmjs.runtime]\n'
            'fakerun = calmjs.testing.mocks:nrt\n'
            'fakekarma = calmjs.testing.mocks:krt\n'
        ),), 'example.package', '1.0')
        working_set = WorkingSet([self._calmjs_testing_tmpdir])

        mocks.nrt = TestToolchainRuntime(
            NullToolchain(), working_set=working_set)
        mocks.krt = KarmaRuntime(KarmaDriver(), working_set=working_set)

        runtime = Runtime(working_set=working_set)
        argparser = runtime.argparser

        ns = argparser.parse_args([
            'fakekarma',
            '--test-with-packages=pkg1', '--test-registries=dummy1',
        ])
        self.assertEqual(ns.calmjs_test_registry_names, ['dummy1'])
        self.assertEqual(ns.test_package_names, ['pkg1'])

        ns = argparser.parse_args([
            'fakekarma',
            '--test-with-packages=pkg1', '--test-registries=dummy1',
            'fakerun',
        ])
        self.assertEqual(ns.calmjs_test_registry_names, ['dummy1'])
        self.assertEqual(ns.test_package_names, ['pkg1'])

        ns = argparser.parse_args([
            'fakekarma',
            '--test-with-packages=pkg1', '--test-registries=dummy1',
            'fakerun',
            '--test-with-package=pkg2', '--test-registry=dummy2',
        ])
        self.assertEqual(ns.calmjs_test_registry_names, ['dummy1', 'dummy2'])
        self.assertEqual(ns.test_package_names, ['pkg1', 'pkg2'])
Esempio n. 35
0
 def test_missing_runtime_arg(self):
     stub_stdouts(self)
     stub_item_attr_value(
         self, mocks, 'dummy',
         ToolchainRuntime(NullToolchain()),
     )
     make_dummy_dist(self, ((
         'entry_points.txt',
         '[calmjs.runtime]\n'
         'null = calmjs.testing.mocks:dummy\n'
     ),), 'example.package', '1.0')
     working_set = WorkingSet([self._calmjs_testing_tmpdir])
     rt = KarmaRuntime(self.driver, working_set=working_set)
     rt([])
     # standard help printed
     self.assertIn('usage:', sys.stdout.getvalue())
     self.assertIn(
         'karma testrunner integration for calmjs', sys.stdout.getvalue())
Esempio n. 36
0
 def test_karma_runtime_integration_default_abort_on_error(self):
     stub_stdouts(self)
     target = join(mkdtemp(self), 'target')
     build_dir = mkdtemp(self)
     stub_item_attr_value(
         self, mocks, 'dummy',
         ToolchainRuntime(NullToolchain()),
     )
     make_dummy_dist(self, ((
         'entry_points.txt',
         '[calmjs.runtime]\n'
         'null = calmjs.testing.mocks:dummy\n'
     ),), 'example.package', '1.0')
     working_set = WorkingSet([self._calmjs_testing_tmpdir])
     rt = KarmaRuntime(self.driver, working_set=working_set)
     result = rt(
         ['null', '--export-target', target, '--build-dir', build_dir])
     self.assertFalse(result)
Esempio n. 37
0
    def test_calmjs_artifact_declarations(self):
        from calmjs.registry import _inst

        # the actual implementations this is supporting
        from calmjs.artifact import build_calmjs_artifacts
        from calmjs.artifact import ArtifactRegistry

        working_dir = mkdtemp(self)
        make_dummy_dist(self, (('entry_points.txt', '\n'.join([
            '[calmjs.registry]',
            'calmjs.artifacts = calmjs.artifact:ArtifactsRegistry',
        ])), ),
                        'calmjs',
                        '1.0',
                        working_dir=working_dir)

        make_dummy_dist(self, (('entry_points.txt', '\n'.join([
            '[calmjs.artifacts]',
            'example.js = example:builder',
        ])), ),
                        'some.package',
                        '1.0',
                        working_dir=working_dir)

        mock_ws = pkg_resources.WorkingSet([working_dir])
        registry_id = 'calmjs.artifacts'
        registry = ArtifactRegistry(registry_id, _working_set=mock_ws)
        # cleanup the about to be injected version.
        self.addCleanup(_inst.records.pop, registry_id, None)
        _inst.records['calmjs.artifacts'] = registry

        # construct a command for the declaration check.
        cmd = build_calmjs_artifacts(dist=distutils_dist.Distribution(
            attrs={'name': 'some.package'}))
        self.assertTrue(calmjs_dist.has_calmjs_artifact_declarations(cmd))

        cmd = build_calmjs_artifacts(dist=distutils_dist.Distribution(
            attrs={'name': 'missing.package'}))
        self.assertFalse(calmjs_dist.has_calmjs_artifact_declarations(cmd))

        cmd = build_calmjs_artifacts(dist=distutils_dist.Distribution(
            attrs={'name': 'calmjs'}))
        self.assertFalse(calmjs_dist.has_calmjs_artifact_declarations(cmd))
Esempio n. 38
0
    def test_init_argparser_with_valid_toolchains(self):
        stub_item_attr_value(
            self, mocks, 'dummy',
            ToolchainRuntime(NullToolchain()),
        )

        make_dummy_dist(self, ((
            'entry_points.txt',
            '[calmjs.runtime]\n'
            'null = calmjs.testing.mocks:dummy\n'
        ),), 'example.package', '1.0')
        working_set = WorkingSet([self._calmjs_testing_tmpdir])

        runtime = KarmaRuntime(self.driver, working_set=working_set)
        argparser = runtime.argparser
        stream = mocks.StringIO()
        argparser.print_help(file=stream)
        self.assertIn('--test-registry', stream.getvalue())
        self.assertIn('null', stream.getvalue())
Esempio n. 39
0
def setup_testing_mold_templates_registry(testcase_inst):
    from nunja.registry import MoldRegistry

    # first create a dummy of this package; we need the actual
    # version number
    make_dummy_dist(testcase_inst, (
        (
            'namespace_packages.txt',
            'nunja\n',
        ),
        (
            'entry_points.txt',
            '[nunja.mold]\n'
            '_core_ = nunja:_core_\n',
        ),
    ), 'nunja',
                    pkg_resources.get_distribution('nunja').version)

    # then make the one for the testing molds
    make_dummy_dist(testcase_inst, (
        (
            'namespace_packages.txt',
            'nunja\n',
        ),
        (
            'entry_points.txt',
            '[nunja.mold]\n'
            'nunja.testing.mold = nunja.testing:mold',
        ),
    ), 'nunja.testing', '0.0.0.dummy')

    working_set = pkg_resources.WorkingSet(
        [testcase_inst._calmjs_testing_tmpdir])

    # Ensure that both the "stubbed" modules can be found
    stub_mod_mock_resources_filename(
        testcase_inst, pkg_resources, {
            'nunja': resource_filename(Requirement.parse('nunja'), ''),
            'nunja.testing': resource_filename(Requirement.parse('nunja'), ''),
        })

    return MoldRegistry('nunja.mold', _working_set=working_set)
Esempio n. 40
0
    def setUp(self):
        # `dummyns.submod` emulates a package that also provide the
        # `dummyns` namespace package that got installed after the
        # other package `dummyns`.
        ds_egg_root = join(mkdtemp(self), 'dummyns.submod')
        dummyns_path = join(ds_egg_root, 'dummyns')
        dummyns = ModuleType('dummyns')
        dummyns.__file__ = join(dummyns_path, '__init__.py')
        dummyns.__path__ = [dummyns_path]
        self.addCleanup(sys.modules.pop, 'dummyns')
        sys.modules['dummyns'] = dummyns

        dummyns_submod_path = join(ds_egg_root, 'dummyns', 'submod')
        dummyns_submod = ModuleType('dummyns.submod')
        dummyns_submod.__file__ = join(dummyns_submod_path, '__init__.py')
        dummyns_submod.__path__ = [dummyns_submod_path]
        self.addCleanup(sys.modules.pop, 'dummyns.submod')
        sys.modules['dummyns.submod'] = dummyns_submod

        os.makedirs(dummyns_submod_path)

        with open(join(dummyns_path, '__init__.py'), 'w') as fd:
            fd.write('')

        with open(join(dummyns_submod_path, '__init__.py'), 'w') as fd:
            fd.write('')

        self.nested_res = join(dummyns_submod_path, 'data.txt')
        self.nested_data = 'data'
        with open(self.nested_res, 'w') as fd:
            fd.write(self.nested_data)

        # create the package proper
        self.dummyns_submod_dist = make_dummy_dist(self, (
            (
                'namespace_packages.txt',
                'dummyns\n'
                'dummyns.submod\n',
            ),
            (
                'entry_points.txt',
                '[dummyns.submod]\n'
                'dummyns.submod = dummyns.submod:attr\n',
            ),
        ),
                                                   'dummyns.submod',
                                                   '1.0',
                                                   working_dir=ds_egg_root)

        self.ds_egg_root = ds_egg_root
        self.dummyns_path = dummyns_path

        self.mod_dummyns = dummyns
        self.mod_dummyns_submod = dummyns_submod
Esempio n. 41
0
    def test_calmjs_artifact_declarations(self):
        from calmjs.registry import _inst

        # the actual implementations this is supporting
        from calmjs.artifact import build_calmjs_artifacts
        from calmjs.artifact import ArtifactRegistry

        working_dir = mkdtemp(self)
        make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                '[calmjs.registry]',
                'calmjs.artifacts = calmjs.artifact:ArtifactsRegistry',
            ])),
        ), 'calmjs', '1.0', working_dir=working_dir)

        make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                '[calmjs.artifacts]',
                'example.js = example:builder',
            ])),
        ), 'some.package', '1.0', working_dir=working_dir)

        mock_ws = pkg_resources.WorkingSet([working_dir])
        registry_id = 'calmjs.artifacts'
        registry = ArtifactRegistry(registry_id, _working_set=mock_ws)
        # cleanup the about to be injected version.
        self.addCleanup(_inst.records.pop, registry_id, None)
        _inst.records['calmjs.artifacts'] = registry

        # construct a command for the declaration check.
        cmd = build_calmjs_artifacts(dist=distutils_dist.Distribution(
            attrs={'name': 'some.package'}))
        self.assertTrue(calmjs_dist.has_calmjs_artifact_declarations(cmd))

        cmd = build_calmjs_artifacts(dist=distutils_dist.Distribution(
            attrs={'name': 'missing.package'}))
        self.assertFalse(calmjs_dist.has_calmjs_artifact_declarations(cmd))

        cmd = build_calmjs_artifacts(dist=distutils_dist.Distribution(
            attrs={'name': 'calmjs'}))
        self.assertFalse(calmjs_dist.has_calmjs_artifact_declarations(cmd))
Esempio n. 42
0
    def test_get_dist_package_fs(self):
        """
        Use the make_dummy_dist testing util to generate a working
        distribution based on upstream library.
        """

        package_json = {"dependencies": {"left-pad": "~1.1.1"}}
        mock_dist = make_dummy_dist(
            self, ((self.pkgname, json.dumps(package_json)), ),
            pkgname='dummydist')
        results = calmjs_dist.read_dist_egginfo_json(mock_dist)
        self.assertEqual(results['dependencies']['left-pad'], '~1.1.1')
Esempio n. 43
0
 def test_karma_runtime_integration_explicit_arguments(self):
     stub_stdouts(self)
     target = join(mkdtemp(self), 'target')
     build_dir = mkdtemp(self)
     stub_item_attr_value(
         self, mocks, 'dummy',
         ToolchainRuntime(NullToolchain()),
     )
     make_dummy_dist(self, ((
         'entry_points.txt',
         '[calmjs.runtime]\n'
         'null = calmjs.testing.mocks:dummy\n'
     ),), 'example.package', '1.0')
     working_set = WorkingSet([self._calmjs_testing_tmpdir])
     rt = KarmaRuntime(self.driver, working_set=working_set)
     result = rt([
         '--test-registry', 'calmjs.no_such_registry',
         '--test-with-package', 'no_such_pkg', '-vv',
         '-I', 'null', '--export-target', target, '--build-dir', build_dir,
     ])
     self.assertIn('karma_config_path', result)
     self.assertTrue(exists(result['karma_config_path']))
     self.assertFalse(result.get('karma_abort_on_test_failure'))
     self.assertIn(
         "karma exited with return code 1; continuing as specified",
         sys.stderr.getvalue()
     )
     self.assertIn(
         "spec has 'test_package_names' explicitly specified",
         sys.stderr.getvalue()
     )
     self.assertIn(
         "spec has 'calmjs_test_registry_names' explicitly specified",
         sys.stderr.getvalue()
     )
     self.assertIn(
         "karma driver to extract tests from packages ['no_such_pkg'] "
         "using registries ['calmjs.no_such_registry'] for testing",
         sys.stderr.getvalue()
     )
Esempio n. 44
0
    def tests_flatten_egginfo_json_nulled(self):
        """
        Need to ensure the *correct* version is picked.
        """

        lib = make_dummy_dist(self, (  # noqa: F841
            ('requires.txt', '\n'.join([])),
            (self.pkgname, json.dumps({
                'dependencies': {
                    'jquery': '~3.0.0',
                    'left-pad': '1.1.1',
                },
            })),
        ), 'lib', '1.0.0')

        app = make_dummy_dist(self, (  # noqa: F841
            ('requires.txt', '\n'.join([
                'lib>=1.0.0',
            ])),
            (self.pkgname, json.dumps({
                'dependencies': {
                    'jquery': '~3.0.0',
                    'left-pad': None,
                },
            })),
        ), 'app', '2.0')

        working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])

        answer = {
            'dependencies': {
                'jquery': '~3.0.0',
                # left-pad will be absent as app removed via None.
            },
            'devDependencies': {},
        }
        result = calmjs_dist.flatten_egginfo_json(
            ['app'], working_set=working_set)
        self.assertEqual(result, answer)
Esempio n. 45
0
    def test_relocated_distribution(self):
        root = mkdtemp(self)
        dummyns_path = join(root, 'dummyns')

        make_dummy_dist(self, (
            (
                'namespace_packages.txt',
                'dummyns\n',
            ),
            (
                'entry_points.txt',
                '[dummyns]\n'
                'dummyns = dummyns:attr\n',
            ),
        ),
                        'dummyns',
                        '1.0',
                        working_dir=root)
        working_set = pkg_resources.WorkingSet([
            root,
            self.ds_egg_root,
        ])
        # activate this as the working set
        stub_item_attr_value(self, pkg_resources, 'working_set', working_set)
        dummyns_ep = next(working_set.iter_entry_points('dummyns'))
        with pretty_logging(stream=StringIO()) as fd:
            p = indexer.resource_filename_mod_entry_point(
                'dummyns', dummyns_ep)
        # since the actual location is not created)
        self.assertIsNone(p)
        self.assertIn("does not exist", fd.getvalue())

        # retry with the module directory created at the expected location
        os.mkdir(dummyns_path)
        with pretty_logging(stream=StringIO()) as fd:
            p = indexer.resource_filename_mod_entry_point(
                'dummyns', dummyns_ep)
        self.assertEqual(normcase(p), normcase(dummyns_path))
        self.assertEqual('', fd.getvalue())
Esempio n. 46
0
 def test_missing_distribution(self):
     d_egg_root = join(mkdtemp(self), 'dummyns')
     make_dummy_dist(self, ((
         'namespace_packages.txt',
         'not_ns\n',
     ), (
         'entry_points.txt',
         '[dummyns]\n'
         'dummyns = dummyns:attr\n',
     ),), 'dummyns', '2.0', working_dir=d_egg_root)
     working_set = pkg_resources.WorkingSet([
         d_egg_root,
         self.ds_egg_root,
     ])
     dummyns_ep = next(working_set.iter_entry_points('dummyns'))
     with pretty_logging(stream=StringIO()) as fd:
         p = indexer.resource_filename_mod_entry_point(
             'dummyns', dummyns_ep)
     # not stubbed working_set, so this is derived using fallback
     # value from the sys.modules['dummyns'] location
     self.assertEqual(normcase(p), normcase(self.dummyns_path))
     self.assertIn("distribution 'dummyns 2.0' not found", fd.getvalue())
Esempio n. 47
0
    def test_module_module_registry_names_success(self):
        base = make_dummy_dist(self, (
            ('requires.txt', ''),
        ), 'base', '1.0.0')

        lib = make_dummy_dist(self, (
            ('requires.txt', 'base>=1.0.0'),
            (calmjs_dist.CALMJS_MODULE_REGISTRY_TXT,
                '\n'.join(['reg1', 'reg2'])),
        ), 'lib', '1.0.0')

        app = make_dummy_dist(self, (
            ('requires.txt', 'lib>=1.0.0'),
            (calmjs_dist.CALMJS_MODULE_REGISTRY_TXT,
                '\n'.join(['reg2', 'reg3'])),
        ), 'app', '2.0')

        working_set = pkg_resources.WorkingSet()
        working_set.add(base, self._calmjs_testing_tmpdir)
        working_set.add(lib, self._calmjs_testing_tmpdir)
        working_set.add(app, self._calmjs_testing_tmpdir)

        self.assertEqual(calmjs_dist.get_module_registry_names(
            ['base'], working_set=working_set), [])
        self.assertEqual(calmjs_dist.get_module_registry_names(
            ['lib'], working_set=working_set), ['reg1', 'reg2'])
        self.assertEqual(calmjs_dist.get_module_registry_names(
            ['app'], working_set=working_set), ['reg2', 'reg3'])
        self.assertEqual(calmjs_dist.get_module_registry_names(
            ['nothing'], working_set=working_set), [])

        self.assertEqual(calmjs_dist.flatten_module_registry_names(
            ['base'], working_set=working_set), [])
        self.assertEqual(calmjs_dist.flatten_module_registry_names(
            ['lib'], working_set=working_set), ['reg1', 'reg2'])
        self.assertEqual(calmjs_dist.flatten_module_registry_names(
            ['app'], working_set=working_set), ['reg1', 'reg2', 'reg3'])
        self.assertEqual(calmjs_dist.flatten_module_registry_names(
            ['nothing'], working_set=working_set), [])
Esempio n. 48
0
    def test_yarn_install_package_json_no_overwrite_interactive(self):
        """
        Most of these package_json testing will be done in the next test
        class specific for ``yarn init``.
        """

        # Testing the implied init call
        stub_mod_call(self, cli)
        stub_stdouts(self)
        stub_stdin(self, 'n\n')
        stub_check_interactive(self, True)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)

        # All the pre-made setup.
        app = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json',
             json.dumps({
                 'dependencies': {
                     'jquery': '~1.11.0'
                 },
             })),
        ), 'foo', '1.9.0')
        working_set = WorkingSet()
        working_set.add(app, self._calmjs_testing_tmpdir)
        stub_item_attr_value(self, dist, 'default_working_set', working_set)

        # We are going to have a fake package.json
        with open(join(tmpdir, 'package.json'), 'w') as fd:
            json.dump({}, fd)

        # capture the logging explicitly as the conditions which
        # determines how the errors are outputted differs from different
        # test harnesses.  Verify that later.
        with pretty_logging(stream=StringIO()) as stderr:
            # This is faked.
            yarn.yarn_install('foo', callback=prompt_overwrite_json)

        self.assertIn(
            "Overwrite '%s'? (Yes/No) [No] " % join(tmpdir, 'package.json'),
            sys.stdout.getvalue())
        # Ensure the error message.  Normally this is printed through
        # stderr via distutils custom logger and our handler bridge for
        # that which is tested elsewhere.
        self.assertIn("not continuing with 'yarn install'", stderr.getvalue())

        with open(join(tmpdir, 'package.json')) as fd:
            result = fd.read()
        # This should remain unchanged as no to overwrite is default.
        self.assertEqual(result, '{}')
Esempio n. 49
0
    def test_karma_runtime_run_toolchain_package(self):
        def cleanup():
            root_registry.records.pop('calmjs.dev.module.tests', None)
            root_registry.records.pop(CALMJS_TOOLCHAIN_ADVICE, None)

        self.addCleanup(cleanup)
        stub_stdouts(self)

        make_dummy_dist(self, ((
            'entry_points.txt',
            '[calmjs.toolchain.advice]\n'
            'calmjs.dev.toolchain:KarmaToolchain'
            ' = calmjs.tests.test_toolchain:dummy\n'
        ),), 'example.package', '1.0')
        working_set = WorkingSet([self._calmjs_testing_tmpdir])

        root_registry.records[
            CALMJS_TOOLCHAIN_ADVICE] = AdviceRegistry(
                CALMJS_TOOLCHAIN_ADVICE, _working_set=working_set)

        # manipulate the registry to remove the fail test
        reg = root_registry.get('calmjs.dev.module.tests')
        reg.records['calmjs.dev.tests'].pop('calmjs/dev/tests/test_fail', '')

        # use the full blown runtime
        rt = KarmaRuntime(self.driver)
        # the artifact in our case is identical to the source file
        artifact = resource_filename('calmjs.dev', 'main.js')
        result = rt([
            '--artifact', artifact, 'run',
            '--test-registry', 'calmjs.dev.module.tests',
            '--test-with-package', 'calmjs.dev',
            '--toolchain-package', 'example.package',
        ])
        self.assertIn('karma_config_path', result)
        self.assertEqual(result['artifact_paths'], [artifact])
        # the spec key is written.
        self.assertEqual(result['dummy'], ['dummy'])
Esempio n. 50
0
    def tests_make_dummy_dist_working_set(self):
        """
        Dummy distributions should work with pkg_resources.WorkingSet
        """

        # This also shows how WorkingSet might work.
        # A WorkingSet is basically a way to get to a collection of
        # distributions via the list of specified paths.  By default it
        # will go for sys.path, but for testing purposes we can control
        # this by creating our own instance on a temporary directory.

        parentpkg = make_dummy_dist(
            self,
            (  # noqa: F841
                ('requires.txt', '\n'.join([])), ),
            'parentpkg',
            '0.8')

        childpkg = make_dummy_dist(
            self,
            (  # noqa: F841
                ('requires.txt', '\n'.join([
                    'parentpkg>=0.8',
                ])), ),
            'childpkg',
            '0.1')

        grandchildpkg = make_dummy_dist(self, (('requires.txt', '\n'.join([
            'childpkg>=0.1',
            'parentpkg>=0.8',
        ])), ), 'grandchildpkg', '0.8')

        working_set = WorkingSet([self._calmjs_testing_tmpdir])
        distributions = working_set.resolve(grandchildpkg.requires())
        self.assertEqual(len(distributions), 2)
        self.assertEqual(distributions[0].requires(), [])
        self.assertEqual(distributions[1].requires(),
                         [Requirement.parse('parentpkg>=0.8')])
Esempio n. 51
0
    def test_get_dist_package_fs(self):
        """
        Use the make_dummy_dist testing util to generate a working
        distribution based on upstream library.
        """

        package_json = {"dependencies": {"left-pad": "~1.1.1"}}
        mock_dist = make_dummy_dist(
            self, (
                (self.pkgname, json.dumps(package_json)),
            ), pkgname='dummydist'
        )
        results = calmjs_dist.read_dist_egginfo_json(mock_dist)
        self.assertEqual(results['dependencies']['left-pad'], '~1.1.1')
Esempio n. 52
0
    def test_standard(self):
        d_egg_root = join(mkdtemp(self), 'dummyns')

        make_dummy_dist(self, (
            (
                'namespace_packages.txt',
                'dummyns\n',
            ),
            (
                'entry_points.txt',
                '[dummyns]\n'
                'dummyns = dummyns:attr\n',
            ),
        ),
                        'dummyns',
                        '1.0',
                        working_dir=d_egg_root)
        working_set = pkg_resources.WorkingSet([
            d_egg_root,
            self.ds_egg_root,
        ])
        # ensure the working_set is providing the distributions being
        # mocked here so that resource_filename will resolve correctly
        stub_item_attr_value(self, pkg_resources, 'working_set', working_set)

        moddir = join(d_egg_root, 'dummyns')
        os.makedirs(moddir)

        # make this also a proper thing
        with open(join(moddir, '__init__.py'), 'w') as fd:
            fd.write('')

        dummyns_ep = next(working_set.iter_entry_points('dummyns'))
        p = indexer.resource_filename_mod_entry_point('dummyns', dummyns_ep)

        # finally, this should work.
        self.assertEqual(normcase(p), normcase(moddir))
Esempio n. 53
0
    def test_denormalized_package_names(self):
        working_dir = utils.mkdtemp(self)
        utils.make_dummy_dist(self, (
            ('entry_points.txt', '\n'.join([
                '[calmjs.artifacts]',
                'full.js = calmjs_testbuild:full',
            ])),
        ), 'de_normal_name', '1.0', working_dir=working_dir)

        mock_ws = WorkingSet([working_dir])
        # stub the default working set in calmjs.dist for the resolver
        # to work.
        utils.stub_item_attr_value(self, dist, 'default_working_set', mock_ws)
        # still specify the working set.
        registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
        self.assertEqual(
            1, len(list(registry.iter_records_for('de_normal_name'))))
        # also test internal consistency
        self.assertIn('de_normal_name', registry.compat_builders['full'])
        self.assertIn('de_normal_name', registry.packages)
        default = registry.get_artifact_filename('de_normal_name', 'full.js')
        normal = registry.get_artifact_filename(
            safe_name('de_normal_name'), 'full.js')
        self.assertEqual(default, normal)
Esempio n. 54
0
    def test_yarn_install_package_json_no_overwrite_interactive(self):
        """
        Most of these package_json testing will be done in the next test
        class specific for ``yarn init``.
        """

        # Testing the implied init call
        stub_mod_call(self, cli)
        stub_stdouts(self)
        stub_stdin(self, 'n\n')
        stub_check_interactive(self, True)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)

        # All the pre-made setup.
        app = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'jquery': '~1.11.0'},
            })),
        ), 'foo', '1.9.0')
        working_set = WorkingSet()
        working_set.add(app, self._calmjs_testing_tmpdir)
        stub_item_attr_value(self, dist, 'default_working_set', working_set)

        # We are going to have a fake package.json
        with open(join(tmpdir, 'package.json'), 'w') as fd:
            json.dump({}, fd)

        # capture the logging explicitly as the conditions which
        # determines how the errors are outputted differs from different
        # test harnesses.  Verify that later.
        with pretty_logging(stream=StringIO()) as stderr:
            # This is faked.
            yarn.yarn_install('foo', callback=prompt_overwrite_json)

        self.assertIn(
            "Overwrite '%s'? (Yes/No) [No] " % join(tmpdir, 'package.json'),
            sys.stdout.getvalue())
        # Ensure the error message.  Normally this is printed through
        # stderr via distutils custom logger and our handler bridge for
        # that which is tested elsewhere.
        self.assertIn("not continuing with 'yarn install'", stderr.getvalue())

        with open(join(tmpdir, 'package.json')) as fd:
            result = fd.read()
        # This should remain unchanged as no to overwrite is default.
        self.assertEqual(result, '{}')
Esempio n. 55
0
    def test_yarn_install_package_json_overwrite_interactive(self):
        # Testing the implied init call
        stub_mod_call(self, cli)
        stub_stdin(self, 'y\n')
        stub_stdouts(self)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)

        # All the pre-made setup.
        app = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json',
             json.dumps({
                 'dependencies': {
                     'jquery': '~1.11.0'
                 },
             })),
        ), 'foo', '1.9.0')
        working_set = WorkingSet()
        working_set.add(app, self._calmjs_testing_tmpdir)
        stub_item_attr_value(self, dist, 'default_working_set', working_set)

        # We are going to have a fake package.json
        with open(join(tmpdir, 'package.json'), 'w') as fd:
            json.dump({}, fd)

        # This is faked.
        yarn.yarn_install('foo', overwrite=True)

        with open(join(tmpdir, 'package.json')) as fd:
            config = json.load(fd)

        # Overwritten
        self.assertEqual(
            config, {
                'dependencies': {
                    'jquery': '~1.11.0'
                },
                'devDependencies': {},
                'name': 'foo',
            })

        # No log level set.
        self.assertEqual(sys.stdout.getvalue(), '')
        self.assertEqual(sys.stderr.getvalue(), '')
Esempio n. 56
0
    def tests_make_dummy_dist(self):
        target = make_dummy_dist(  # noqa: F841
            self, (
                ('dummyinfo', 'hello world'),
                ('fakeinfo', 'these are actually metadata'),
            ), 'fakepkg', '0.999')

        fn = join(self._calmjs_testing_tmpdir, 'fakepkg-0.999.egg-info',
                  'dummyinfo')
        with open(fn) as fd:
            result = fd.read()
        self.assertEqual(result, 'hello world')

        fn = join(self._calmjs_testing_tmpdir, 'fakepkg-0.999.egg-info',
                  'fakeinfo')
        with open(fn) as fd:
            result = fd.read()
        self.assertEqual(result, 'these are actually metadata')
Esempio n. 57
0
    def setUp(self):
        remember_cwd(self)

        app = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'jquery': '~1.11.0'},
            })),
        ), 'foo', '1.9.0')

        working_set = WorkingSet()
        working_set.add(app, self._calmjs_testing_tmpdir)

        # Stub out the flatten_egginfo_json calls with one that uses our
        # custom working_set here.
        stub_item_attr_value(self, dist, 'default_working_set', working_set)
        # Quiet stdout from distutils logs
        stub_stdouts(self)
        # Force auto-detected interactive mode to True, because this is
        # typically executed within an interactive context.
        stub_mod_check_interactive(self, [cli], True)
Esempio n. 58
0
    def setup_runtime(self):
        make_dummy_dist(self, (('package.json',
                                json.dumps({
                                    'name': 'site',
                                    'dependencies': {
                                        'jquery': '~3.1.0',
                                    },
                                })), ), 'example.package1', '1.0')

        make_dummy_dist(self, (('package.json',
                                json.dumps({
                                    'name': 'site',
                                    'dependencies': {
                                        'underscore': '~1.8.3',
                                    },
                                })), ), 'example.package2', '2.0')

        make_dummy_dist(self, (
            ('requires.txt', '\n'.join([
                'example.package1',
                'example.package2',
            ])),
            ('package.json',
             json.dumps({
                 'dependencies': {
                     'backbone': '~1.3.2',
                 },
             })),
        ), 'example.package3', '2.0')

        working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])

        # Stub out the underlying data needed for the cli for the tests
        # to test against our custom data for reproducibility.
        stub_item_attr_value(self, dist, 'default_working_set', working_set)
        stub_mod_check_interactive(self, [cli], True)

        # Of course, apply a mock working set for the runtime instance
        # so it can use the npm runtime, however we will use a different
        # keyword.  Note that the runtime is invoked using foo.
        working_set = mocks.WorkingSet({
            'calmjs.runtime': [
                'foo = calmjs.npm:npm.runtime',
            ],
        })
        return runtime.Runtime(working_set=working_set)
Esempio n. 59
0
    def test_module_registry_dependencies_success(self):
        from calmjs.registry import _inst

        make_dummy_dist(self, (('requires.txt', '\n'.join([])), ), 'security',
                        '9999')

        make_dummy_dist(self, (('requires.txt', '\n'.join([
            'security',
        ])), ), 'framework', '2.4')

        make_dummy_dist(self, (('requires.txt', '\n'.join([
            'framework>=2.1',
        ])), ), 'widget', '1.1')

        make_dummy_dist(self, (('requires.txt', '\n'.join([
            'framework>=2.2',
            'widget>=1.0',
        ])), ), 'forms', '1.6')

        make_dummy_dist(self, (('requires.txt', '\n'.join([
            'framework>=2.1',
        ])), ), 'service', '1.1')

        make_dummy_dist(self, (('requires.txt', '\n'.join([
            'framework>=2.1',
            'widget>=1.1',
            'forms>=1.6',
            'service>=1.1',
        ])), ), 'site', '2.0')

        working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])

        dummy_regid = 'calmjs.module.dummy.test'

        # ensure the dummy record we adding will be cleaned up.
        def cleanup():
            _inst.records.pop(dummy_regid, None)

        self.addCleanup(cleanup)

        # set up/register a dummy registry with dummy records.
        dummy_reg = _inst.records[dummy_regid] = ModuleRegistry(dummy_regid)
        dummy_reg.records = {
            'site': {
                'site/config': '/home/src/site/config.js',
            },
            'widget': {
                'widget/ui': '/home/src/widget/ui.js',
                'widget/widget': '/home/src/widget/widget.js',
            },
            'forms': {
                'forms/ui': '/home/src/forms/ui.js',
            },
            'service': {
                'service/lib': '/home/src/forms/lib.js',
            },
        }
        dummy_reg.package_module_map = {
            'site': ['site'],
            'widget': ['widget'],
            'forms': ['forms'],
            'service': ['service'],
        }

        site = calmjs_dist.flatten_module_registry_dependencies(
            ['site'], registry_name=dummy_regid, working_set=working_set)
        self.assertEqual(
            site, {
                'site/config': '/home/src/site/config.js',
                'widget/ui': '/home/src/widget/ui.js',
                'widget/widget': '/home/src/widget/widget.js',
                'service/lib': '/home/src/forms/lib.js',
                'forms/ui': '/home/src/forms/ui.js',
            })

        self.assertEqual(
            calmjs_dist.flatten_parents_module_registry_dependencies(
                ['site'], registry_name=dummy_regid, working_set=working_set),
            {
                'widget/ui': '/home/src/widget/ui.js',
                'widget/widget': '/home/src/widget/widget.js',
                'service/lib': '/home/src/forms/lib.js',
                'forms/ui': '/home/src/forms/ui.js',
            })

        service = calmjs_dist.flatten_module_registry_dependencies(
            ['service'], registry_name=dummy_regid, working_set=working_set)
        self.assertEqual(service, {
            'service/lib': '/home/src/forms/lib.js',
        })

        forms = calmjs_dist.flatten_module_registry_dependencies(
            ['forms'], registry_name=dummy_regid, working_set=working_set)
        self.assertEqual(
            forms, {
                'forms/ui': '/home/src/forms/ui.js',
                'widget/ui': '/home/src/widget/ui.js',
                'widget/widget': '/home/src/widget/widget.js',
            })

        # merger
        merged = calmjs_dist.flatten_module_registry_dependencies(
            ['forms', 'service'],
            registry_name=dummy_regid,
            working_set=working_set)
        self.assertEqual(
            merged, {
                'forms/ui': '/home/src/forms/ui.js',
                'widget/ui': '/home/src/widget/ui.js',
                'widget/widget': '/home/src/widget/widget.js',
                'service/lib': '/home/src/forms/lib.js',
            })

        self.assertEqual(
            calmjs_dist.flatten_parents_module_registry_dependencies(
                ['forms', 'service', 'app'],
                registry_name=dummy_regid,
                working_set=working_set), {
                    'widget/ui': '/home/src/widget/ui.js',
                    'widget/widget': '/home/src/widget/widget.js',
                })

        # no declared exports/registry entries in security.
        security = calmjs_dist.flatten_module_registry_dependencies(
            ['security'], registry_name=dummy_regid, working_set=working_set)
        self.assertEqual(security, {})

        # package not even in working set
        missing_pkg = calmjs_dist.flatten_module_registry_dependencies(
            ['missing_pkg'],
            registry_name=dummy_regid,
            working_set=working_set)
        self.assertEqual(missing_pkg, {})

        # singlular methods
        self.assertEqual(
            calmjs_dist.get_module_registry_dependencies(
                ['site'], registry_name=dummy_regid, working_set=working_set),
            {'site/config': '/home/src/site/config.js'})

        self.assertEqual(
            calmjs_dist.get_module_registry_dependencies(
                ['security'],
                registry_name=dummy_regid,
                working_set=working_set), {})

        self.assertEqual(
            calmjs_dist.get_module_registry_dependencies(
                ['missing'],
                registry_name=dummy_regid,
                working_set=working_set), {})
Esempio n. 60
0
    def test_package_name_to_dists(self):
        lib1 = make_dummy_dist(self, (('requires.txt', '\n'.join([])), ),
                               'lib1', '1.0.0')
        lib2 = make_dummy_dist(self, (('requires.txt', '\n'.join([])), ),
                               'lib2', '1.0.0')
        lib3 = make_dummy_dist(self, (('requires.txt', '\n'.join([
            'lib1>=1.0.0',
            'lib2>=1.0.0',
        ])), ), 'lib3', '1.0.0')

        app = make_dummy_dist(self, (('requires.txt', '\n'.join([
            'lib3>=1.0.0',
        ])), ), 'app', '2.0')

        extra = make_dummy_dist(self, (('requires.txt', '\n'.join([])), ),
                                'extra', '2.0')

        working_set = pkg_resources.WorkingSet()
        working_set.add(lib1, self._calmjs_testing_tmpdir)
        working_set.add(lib2, self._calmjs_testing_tmpdir)
        working_set.add(lib3, self._calmjs_testing_tmpdir)
        working_set.add(app, self._calmjs_testing_tmpdir)
        working_set.add(extra, self._calmjs_testing_tmpdir)

        # finding individual packages
        self.assertEqual(['app'], [
            d.project_name
            for d in calmjs_dist.pkg_names_to_dists(['app'],
                                                    working_set=working_set)
        ])

        self.assertEqual(['lib3'], [
            d.project_name
            for d in calmjs_dist.pkg_names_to_dists(['lib3'],
                                                    working_set=working_set)
        ])

        # finding everything
        self.assertEqual(['lib1', 'lib2', 'lib3', 'app'], [
            d.project_name
            for d in calmjs_dist.find_packages_requirements_dists(
                ['app'], working_set=working_set)
        ])

        self.assertEqual(['lib1', 'lib2', 'lib3', 'extra'], [
            d.project_name
            for d in calmjs_dist.find_packages_requirements_dists(
                ['lib3', 'extra'], working_set=working_set)
        ])

        # only find the parents
        self.assertEqual(['lib1', 'lib2', 'lib3'], [
            d.project_name
            for d in calmjs_dist.find_packages_parents_requirements_dists(
                ['app'], working_set=working_set)
        ])

        self.assertEqual(['lib1', 'lib2'], [
            d.project_name
            for d in calmjs_dist.find_packages_parents_requirements_dists(
                ['app', 'lib3'], working_set=working_set)
        ])

        self.assertEqual(['lib1', 'lib2'], [
            d.project_name
            for d in calmjs_dist.find_packages_parents_requirements_dists(
                ['lib3', 'app'], working_set=working_set)
        ])

        self.assertEqual(['lib1', 'lib2'], [
            d.project_name
            for d in calmjs_dist.find_packages_parents_requirements_dists(
                ['lib3'], working_set=working_set)
        ])

        self.assertEqual([], [
            d.project_name
            for d in calmjs_dist.find_packages_parents_requirements_dists(
                ['lib1'], working_set=working_set)
        ])

        self.assertEqual([], [
            d.project_name
            for d in calmjs_dist.find_packages_parents_requirements_dists(
                ['lib2', 'lib1'], working_set=working_set)
        ])