Exemplo n.º 1
0
    def test_dump(self):
        conf_file = os.path.join(self.__priv_dir, 'test.json')
        with open(conf_file, 'w') as _:
            _.write('{\n'
                    '"index": "my_index.markdown",\n'
                    '"test_index": "/home/meh/test_index.markdown",\n'
                    '"test_sources": ["*.x"],\n'
                    '"test_source_filters": ["foobar.x"]\n'
                    '}\n')

        here = os.path.abspath(os.path.dirname(__file__))
        invoke_dir = os.getcwd()
        relpath = os.path.relpath(here, invoke_dir)
        overriden_src_dir = os.path.join(relpath, 'overridden_sources')

        cli = {
            'index': 'another_index.markdown',
            'test_sources': ['%s/*.x' % overriden_src_dir],
            'test_source_filters': ['%s/ignored.x' % overriden_src_dir]
        }

        cfg = Config(command_line_args=cli, conf_file=conf_file)
        cfg.dump(conf_file=conf_file)
        ncfg = Config(conf_file=conf_file)
        self.assertEqual(ncfg.get_index(),
                         os.path.join(invoke_dir, 'another_index.markdown'))
        self.assertListEqual(ncfg.get('test_sources'),
                             [u'../overridden_sources/*.x'])
Exemplo n.º 2
0
    def test_cli_overrides(self):
        conf_file = os.path.join(self.__priv_dir, 'test.json')
        with open(conf_file, 'w') as _:
            _.write('{\n'
                    '"index": "my_index.markdown",\n'
                    '"test_index": "/home/meh/test_index.markdown",\n'
                    '"test_sources": ["*.x"],\n'
                    '"test_source_filters": ["foobar.x"]\n'
                    '}\n')

        touch(os.path.join(self.__priv_dir, 'foo.x'))
        touch(os.path.join(self.__priv_dir, 'foobar.x'))

        here = os.path.abspath(os.path.dirname(__file__))
        invoke_dir = os.getcwd()
        relpath = os.path.relpath(here, invoke_dir)
        overriden_src_dir = os.path.join(relpath, 'overridden_sources')

        shutil.rmtree(overriden_src_dir, ignore_errors=True)
        os.mkdir(overriden_src_dir)
        touch(os.path.join(overriden_src_dir, 'other.x'))
        touch(os.path.join(overriden_src_dir, 'foobar.x'))
        touch(os.path.join(overriden_src_dir, 'ignored.x'))

        cli = {
            'index': 'another_index.markdown',
            'test_sources': ['%s/*.x' % overriden_src_dir],
            'test_source_filters': ['%s/ignored.x' % overriden_src_dir]
        }

        cfg = Config(command_line_args=cli, conf_file=conf_file)
        self.assertEqual(cfg.get('index'), 'another_index.markdown')

        self.assertEqual(cfg.get_index(),
                         os.path.join(invoke_dir, 'another_index.markdown'))

        overriden_abs_dir = os.path.join(invoke_dir, overriden_src_dir)

        self.assertSetEqual(
            set(cfg.get_sources('test')),
            set([
                os.path.join(overriden_abs_dir, 'other.x'),
                os.path.join(overriden_abs_dir, 'foobar.x')
            ]))

        shutil.rmtree(overriden_src_dir, ignore_errors=True)