Пример #1
0
    def test_command_packages_configfile(self):
        sys.argv.append("build")
        f = open(TESTFN, "w")
        try:
            print >> f, "[global]"
            print >> f, "command_packages = foo.bar, splat"
            f.close()
            d = create_distribution([TESTFN])
            self.assertEqual(d.get_command_packages(),
                             ["distutils2.command", "foo.bar", "splat"])

            # ensure command line overrides config:
            sys.argv[1:] = ["--command-packages", "spork", "build"]
            d = create_distribution([TESTFN])
            self.assertEqual(d.get_command_packages(),
                             ["distutils2.command", "spork"])

            # Setting --command-packages to '' should cause the default to
            # be used even if a config file specified something else:
            sys.argv[1:] = ["--command-packages", "", "build"]
            d = create_distribution([TESTFN])
            self.assertEqual(d.get_command_packages(), ["distutils2.command"])

        finally:
            os.unlink(TESTFN)
Пример #2
0
    def test_hooks_callable(self):
        temp_home = self.mkdtemp()
        config_file = os.path.join(temp_home, "config1.cfg")

        self.write_file(config_file, textwrap.dedent('''\
            [test_dist]
            pre-hook.test = distutils2.tests.test_dist.__doc__'''))

        use_command(self, 'distutils2.tests.test_dist.test_dist')
        d = create_distribution([config_file])
        cmd = d.get_command_obj("test_dist")
        cmd.ensure_finalized()

        self.assertRaises(PackagingOptionError, d.run_command, 'test_dist')
Пример #3
0
 def test_command_packages_cmdline(self):
     from distutils2.tests.test_dist import test_dist
     sys.argv.extend(["--command-packages",
                      "foo.bar,distutils2.tests",
                      "test_dist",
                      "-Ssometext",
                      ])
     d = create_distribution()
     # let's actually try to load our test command:
     self.assertEqual(d.get_command_packages(),
                      ["distutils2.command", "foo.bar", "distutils2.tests"])
     cmd = d.get_command_obj("test_dist")
     self.assertTrue(isinstance(cmd, test_dist))
     self.assertEqual(cmd.sample_option, "sometext")
Пример #4
0
    def test_hooks_callable(self):
        temp_home = self.mkdtemp()
        config_file = os.path.join(temp_home, "config1.cfg")

        self.write_file(
            config_file,
            textwrap.dedent('''\
            [test_dist]
            pre-hook.test = distutils2.tests.test_dist.__doc__'''))

        use_command(self, 'distutils2.tests.test_dist.test_dist')
        d = create_distribution([config_file])
        cmd = d.get_command_obj("test_dist")
        cmd.ensure_finalized()

        self.assertRaises(PackagingOptionError, d.run_command, 'test_dist')
Пример #5
0
    def test_special_hooks_parsing(self):
        temp_home = self.mkdtemp()
        config_files = [os.path.join(temp_home, "config1.cfg"),
                        os.path.join(temp_home, "config2.cfg")]

        # Store two aliased hooks in config files
        self.write_file((temp_home, "config1.cfg"),
                        '[test_dist]\npre-hook.a = type')
        self.write_file((temp_home, "config2.cfg"),
                        '[test_dist]\npre-hook.b = type')

        use_command(self, 'distutils2.tests.test_dist.test_dist')

        dist = create_distribution(config_files)
        cmd = dist.get_command_obj("test_dist")
        self.assertEqual(cmd.pre_hook, {"a": 'type', "b": 'type'})
Пример #6
0
    def test_hooks_callable(self):
        temp_home = self.mkdtemp()
        config_file = os.path.join(temp_home, "config1.cfg")

        self.write_file(config_file, textwrap.dedent('''
            [test_dist]
            pre-hook.test = distutils2.tests.test_dist.__doc__'''))

        sys.argv.extend(["--command-packages",
                         "distutils2.tests",
                         "test_dist"])

        d = create_distribution([config_file])
        cmd = d.get_command_obj("test_dist")
        cmd.ensure_finalized()

        self.assertRaises(DistutilsOptionError, d.run_command, 'test_dist')
Пример #7
0
    def test_special_hooks_parsing(self):
        temp_home = self.mkdtemp()
        config_files = [
            os.path.join(temp_home, "config1.cfg"),
            os.path.join(temp_home, "config2.cfg")
        ]

        # Store two aliased hooks in config files
        self.write_file((temp_home, "config1.cfg"),
                        '[test_dist]\npre-hook.a = type')
        self.write_file((temp_home, "config2.cfg"),
                        '[test_dist]\npre-hook.b = type')

        use_command(self, 'distutils2.tests.test_dist.test_dist')

        dist = create_distribution(config_files)
        cmd = dist.get_command_obj("test_dist")
        self.assertEqual(cmd.pre_hook, {"a": 'type', "b": 'type'})
Пример #8
0
    def test_hooks_get_run(self):
        temp_home = self.mkdtemp()
        config_file = os.path.join(temp_home, "config1.cfg")
        hooks_module = os.path.join(temp_home, "testhooks.py")

        self.write_file(config_file, textwrap.dedent('''
            [test_dist]
            pre-hook.test = testhooks.log_pre_call
            post-hook.test = testhooks.log_post_call'''))

        self.write_file(hooks_module, textwrap.dedent('''
        record = []

        def log_pre_call(cmd):
            record.append('pre-%s' % cmd.get_command_name())

        def log_post_call(cmd):
            record.append('post-%s' % cmd.get_command_name())
        '''))

        sys.argv.extend(["--command-packages",
                         "distutils2.tests",
                         "test_dist"])

        d = create_distribution([config_file])
        cmd = d.get_command_obj("test_dist")

        # prepare the call recorders
        sys.path.append(temp_home)
        from testhooks import record

        self.addCleanup(setattr, cmd, 'run', cmd.run)
        self.addCleanup(setattr, cmd, 'finalize_options',
                        cmd.finalize_options)

        cmd.run = lambda: record.append('run')
        cmd.finalize_options = lambda: record.append('finalize')

        d.run_command('test_dist')

        self.assertEqual(record, ['finalize',
                                  'pre-test_dist',
                                  'run',
                                  'post-test_dist'])
Пример #9
0
    def test_hooks_get_run(self):
        temp_home = self.mkdtemp()
        module_name = os.path.split(temp_home)[-1]
        pyname = '%s.py' % module_name
        config_file = os.path.join(temp_home, "config1.cfg")
        hooks_module = os.path.join(temp_home, pyname)

        self.write_file(
            config_file,
            textwrap.dedent('''\
            [test_dist]
            pre-hook.test = %(modname)s.log_pre_call
            post-hook.test = %(modname)s.log_post_call''' %
                            {'modname': module_name}))

        self.write_file(
            hooks_module,
            textwrap.dedent('''\
            record = []

            def log_pre_call(cmd):
                record.append('pre-%s' % cmd.get_command_name())

            def log_post_call(cmd):
                record.append('post-%s' % cmd.get_command_name())
            '''))

        use_command(self, 'distutils2.tests.test_dist.test_dist')
        d = create_distribution([config_file])
        cmd = d.get_command_obj("test_dist")

        # prepare the call recorders
        sys.path.append(temp_home)
        self.addCleanup(sys.path.remove, temp_home)
        self.addCleanup(unload, module_name)
        record = __import__(module_name).record

        cmd.run = lambda: record.append('run')
        cmd.finalize_options = lambda: record.append('finalize')
        d.run_command('test_dist')

        self.assertEqual(
            record, ['finalize', 'pre-test_dist', 'run', 'post-test_dist'])
Пример #10
0
    def test_hooks_get_run(self):
        temp_home = self.mkdtemp()
        module_name = os.path.split(temp_home)[-1]
        pyname = '%s.py' % module_name
        config_file = os.path.join(temp_home, "config1.cfg")
        hooks_module = os.path.join(temp_home, pyname)

        self.write_file(config_file, textwrap.dedent('''\
            [test_dist]
            pre-hook.test = %(modname)s.log_pre_call
            post-hook.test = %(modname)s.log_post_call'''
            % {'modname': module_name}))

        self.write_file(hooks_module, textwrap.dedent('''\
            record = []

            def log_pre_call(cmd):
                record.append('pre-%s' % cmd.get_command_name())

            def log_post_call(cmd):
                record.append('post-%s' % cmd.get_command_name())
            '''))

        use_command(self, 'distutils2.tests.test_dist.test_dist')
        d = create_distribution([config_file])
        cmd = d.get_command_obj("test_dist")

        # prepare the call recorders
        sys.path.append(temp_home)
        self.addCleanup(sys.path.remove, temp_home)
        self.addCleanup(unload, module_name)
        record = __import__(module_name).record

        cmd.run = lambda: record.append('run')
        cmd.finalize_options = lambda: record.append('finalize')
        d.run_command('test_dist')

        self.assertEqual(record, ['finalize',
                                  'pre-test_dist',
                                  'run',
                                  'post-test_dist'])
Пример #11
0
 def test_command_packages_unspecified(self):
     sys.argv.append("build")
     d = create_distribution()
     self.assertEqual(d.get_command_packages(), ["distutils2.command"])