コード例 #1
0
ファイル: test_commands.py プロジェクト: java-tools/mike
 def test_delete_alias(self):
     self._deploy()
     commands.delete(['stable'])
     check_call_silent(['git', 'checkout', 'gh-pages'])
     self._test_delete(expected_versions=[
         versions.VersionInfo('2.0'),
         versions.VersionInfo('1.0'),
     ])
コード例 #2
0
 def test_update_aliases(self):
     assertPopen(['mike', 'deploy', '1.0', 'latest'])
     assertPopen(['mike', 'deploy', '2.0', 'latest', '-u'])
     check_call_silent(['git', 'checkout', 'gh-pages'])
     self._test_deploy(expected_versions=[
         versions.VersionInfo('2.0', aliases=['latest']),
         versions.VersionInfo('1.0'),
     ])
コード例 #3
0
ファイル: test_commands.py プロジェクト: java-tools/mike
 def test_alias_update(self):
     self._deploy()
     with commands.deploy(self.cfg, '2.0'):
         pass
     commands.alias(self.cfg, '2.0', ['latest'], update_aliases=True)
     check_call_silent(['git', 'checkout', 'gh-pages'])
     self._test_state(r'^Copied 2\.0 to latest', [
         versions.VersionInfo('2.0', '2.0', ['latest']),
         versions.VersionInfo('1.0', '1.0'),
     ])
コード例 #4
0
ファイル: test_commands.py プロジェクト: java-tools/mike
 def test_alias_overwrite_error(self):
     self._deploy()
     with commands.deploy(self.cfg, '2.0'):
         pass
     with self.assertRaises(ValueError):
         commands.alias(self.cfg, '2.0', ['latest'])
     check_call_silent(['git', 'checkout', 'gh-pages'])
     self._test_state(r'^Deployed \w+ to 2\.0', [
         versions.VersionInfo('2.0', '2.0'),
         versions.VersionInfo('1.0', '1.0', ['latest']),
     ])
コード例 #5
0
ファイル: test_alias.py プロジェクト: jimporter/mike
    def test_update_aliases(self):
        assertPopen(['mike', 'deploy', '1.0', 'latest'])
        assertPopen(['mike', 'deploy', '2.0'])
        assertPopen(['mike', 'alias', '2.0', 'latest', '-u'])
        check_call_silent(['git', 'checkout', 'gh-pages'])
        self._test_alias(expected_versions=[
            versions.VersionInfo('2.0', aliases=['latest']),
            versions.VersionInfo('1.0', ),
        ])

        with open('latest/index.html') as f:
            self.assertRegex(f.read(), match_redir('../2.0/'))
コード例 #6
0
ファイル: test_commands.py プロジェクト: java-tools/mike
 def test_update_aliases(self):
     self._mock_commit()
     with commands.deploy(self.cfg,
                          '2.0',
                          '2.0.0', ['latest'],
                          update_aliases=True):
         self._mock_build()
     check_call_silent(['git', 'checkout', 'gh-pages'])
     self._test_deploy('.*', [
         versions.VersionInfo('2.0', '2.0.0', ['latest']),
         versions.VersionInfo('1.0', '1.0', []),
     ])
コード例 #7
0
ファイル: test_deploy.py プロジェクト: pblitz/mike
    def _test_deploy(self, expected_message=None,
                     expected_versions=[versions.VersionInfo('1.0')]):
        rev = git_utils.get_latest_commit('master', short=True)
        message = subprocess.check_output(['git', 'log', '-1', '--pretty=%B'],
                                          universal_newlines=True).rstrip()
        if expected_message:
            self.assertEqual(message, expected_message)
        else:
            self.assertRegex(
                message,
                r'^Deployed {} to {} with MkDocs \S+ and mike \S+$'
                .format(rev, expected_versions[0].version)
            )

        dirs = set()
        for i in expected_versions:
            dirs |= {str(i.version)} | i.aliases
        contents = {'versions.json'} | set(chain.from_iterable(
            (d, d + '/index.html') for d in dirs
        ))
        assertDirectory('.', contents, allow_extra=True)

        with open('versions.json') as f:
            self.assertEqual(list(versions.Versions.loads(f.read())),
                             expected_versions)
コード例 #8
0
    def _test_delete(self,
                     expected_message=None,
                     expected_versions=[versions.VersionInfo('2.0')]):
        if not expected_message:
            expected_message = r'^Removed \S+ with mike \S+$'

        self._test_state(expected_message, expected_versions)
コード例 #9
0
    def test_update_aliases(self):
        with git_utils.Commit('gh-pages', 'add versions.json') as commit:
            commit.add_file(
                git_utils.FileInfo(
                    'versions.json',
                    '[{"version": "1.0", "title": "1.0", "aliases": ["latest"]}]',
                ))
            commit.add_file(git_utils.FileInfo('1.0/file.txt', ''))
            commit.add_file(git_utils.FileInfo('latest/file.txt', ''))

        commands.deploy(self.stage, '2.0', '2.0.0', ['latest'], True)
        check_call_silent(['git', 'checkout', 'gh-pages'])
        self._test_deploy('.*', [
            versions.VersionInfo('2.0', '2.0.0', ['latest']),
            versions.VersionInfo('1.0', '1.0', []),
        ])
コード例 #10
0
ファイル: test_deploy.py プロジェクト: java-tools/mike
 def test_aliases_copy(self):
     assertPopen(['mike', 'deploy', '1.0', 'latest', '--no-redirect'])
     check_call_silent(['git', 'checkout', 'gh-pages'])
     self._test_deploy(expected_versions=[
         versions.VersionInfo('1.0', aliases=['latest'])
     ],
                       redirect=False)
コード例 #11
0
ファイル: test_alias.py プロジェクト: jimporter/mike
    def _test_alias(self,
                    expected_message=None,
                    expected_versions=[
                        versions.VersionInfo('1.0', aliases=['latest'])
                    ],
                    redirect=True,
                    directory='.'):
        message = assertPopen(['git', 'log', '-1', '--pretty=%B']).rstrip()
        if expected_message:
            self.assertEqual(message, expected_message)
        else:
            self.assertRegex(message,
                             r'^Copied \S+ to latest( in .*)? with mike \S+$')

        files = {'versions.json'}
        for v in expected_versions:
            v_str = str(v.version)
            files |= {
                v_str, v_str + '/index.html',
                v_str + '/css/version-select.css',
                v_str + '/js/version-select.js'
            }
            for a in v.aliases:
                files |= {a, a + '/index.html'}
                if not redirect:
                    files |= {
                        a + '/css/version-select.css',
                        a + '/js/version-select.js'
                    }
        assertDirectory(directory, files, allow_extra=True)

        with open(os.path.join(directory, 'versions.json')) as f:
            self.assertEqual(list(versions.Versions.loads(f.read())),
                             expected_versions)
コード例 #12
0
 def test_update(self):
     assertPopen(['mike', 'deploy', '1.0', 'latest'])
     assertPopen(['mike', 'deploy', '1.0', 'greatest', '-t', '1.0.1'])
     check_call_silent(['git', 'checkout', 'gh-pages'])
     self._test_deploy(expected_versions=[
         versions.VersionInfo('1.0', '1.0.1', ['latest', 'greatest'])
     ])
コード例 #13
0
    def _test_deploy(self, expected_message=None,
                     expected_versions=[versions.VersionInfo('1.0')],
                     redirect=True, directory='.'):
        rev = git_utils.get_latest_commit('master', short=True)
        message = assertPopen(['git', 'log', '-1', '--pretty=%B']).rstrip()
        if expected_message:
            self.assertEqual(message, expected_message)
        else:
            self.assertRegex(
                message,
                r'^Deployed {} to {}( in .*)? with MkDocs \S+ and mike \S+$'
                .format(rev, expected_versions[0].version)
            )

        files = {'versions.json'}
        for v in expected_versions:
            v_str = str(v.version)
            files |= {v_str, v_str + '/index.html',
                      v_str + '/css/version-select.css',
                      v_str + '/js/version-select.js'}
            for a in v.aliases:
                files |= {a, a + '/index.html'}
                if not redirect:
                    files |= {a + '/css/version-select.css',
                              a + '/js/version-select.js'}
        assertDirectory(directory, files, allow_extra=True)

        with open(os.path.join(directory, 'versions.json')) as f:
            self.assertEqual(list(versions.Versions.loads(f.read())),
                             expected_versions)
コード例 #14
0
ファイル: test_commands.py プロジェクト: java-tools/mike
 def test_overwrite_include_same_alias(self):
     self._mock_commit()
     with commands.deploy(self.cfg, '1.0', '1.0.1', ['latest', 'greatest']):
         self._mock_build()
     check_call_silent(['git', 'checkout', 'gh-pages'])
     self._test_deploy(expected_versions=[
         versions.VersionInfo('1.0', '1.0.1', ['latest', 'greatest'])
     ])
コード例 #15
0
ファイル: test_commands.py プロジェクト: java-tools/mike
 def test_overwrite_alias_error(self):
     self._mock_commit()
     with self.assertRaises(ValueError):
         with commands.deploy(self.cfg, '2.0', '2.0.0', ['latest']):
             raise AssertionError('should not get here')
     check_call_silent(['git', 'checkout', 'gh-pages'])
     self._test_deploy('add versions.json',
                       [versions.VersionInfo('1.0', '1.0', ['latest'])])
コード例 #16
0
    def _test_deploy(self,
                     expected_message=None,
                     expected_versions=[versions.VersionInfo('1.0')]):
        if not expected_message:
            rev = git_utils.get_latest_commit('master', short=True)
            expected_message = (
                r'^Deployed {} to {} with MkDocs \S+ and mike \S+$'.format(
                    rev, expected_versions[0].version))

        self._test_state(expected_message, expected_versions)
コード例 #17
0
ファイル: test_commands.py プロジェクト: java-tools/mike
    def test_versions_exist(self):
        with git_utils.Commit('gh-pages', 'add versions.json') as commit:
            commit.add_file(
                git_utils.FileInfo(
                    'versions.json',
                    '[{"version": "1.0", "title": "1.0", "aliases": []}]',
                ))

        self.assertEqual(list(commands.list_versions()), [
            versions.VersionInfo('1.0'),
        ])
コード例 #18
0
    def test_aliases_custom_redirect(self):
        assertPopen(['mike', 'deploy', '1.0', 'latest', '-T',
                     os.path.join(test_data_dir, 'template.html')])
        check_call_silent(['git', 'checkout', 'gh-pages'])
        self._test_deploy(expected_versions=[
            versions.VersionInfo('1.0', aliases=['latest'])
        ])
        check_call_silent(['git', 'checkout', 'gh-pages'])

        with open('latest/index.html') as f:
            self.assertEqual(f.read(), 'Redirecting to ../1.0/')
コード例 #19
0
ファイル: test_commands.py プロジェクト: java-tools/mike
 def test_prefix(self):
     with commands.deploy(self.cfg,
                          '1.0',
                          aliases=['latest'],
                          prefix='prefix'):
         self._mock_build()
     check_call_silent(['git', 'checkout', 'gh-pages'])
     self._test_deploy(expected_versions=[
         versions.VersionInfo('1.0', aliases=['latest'])
     ],
                       directory='prefix')
コード例 #20
0
ファイル: test_commands.py プロジェクト: java-tools/mike
 def test_aliases_copy(self):
     with commands.deploy(self.cfg,
                          '1.0',
                          aliases=['latest'],
                          redirect=False):
         self._mock_build()
     check_call_silent(['git', 'checkout', 'gh-pages'])
     self._test_deploy(expected_versions=[
         versions.VersionInfo('1.0', aliases=['latest'])
     ],
                       redirect=False)
コード例 #21
0
ファイル: test_commands.py プロジェクト: java-tools/mike
    def test_aliases(self):
        with commands.deploy(self.cfg, '1.0', aliases=['latest']):
            self._mock_build()
        check_call_silent(['git', 'checkout', 'gh-pages'])
        self._test_deploy(expected_versions=[
            versions.VersionInfo('1.0', aliases=['latest'])
        ])

        with open('latest/page.html') as f:
            self.assertRegex(f.read(), match_redir('../1.0/page.html'))
        with open('latest/dir/index.html') as f:
            self.assertRegex(f.read(), match_redir('../../1.0/dir/'))
コード例 #22
0
    def _test_alias(self,
                    expected_message=None,
                    expected_src='1.0',
                    expected_aliases=['greatest']):
        if not expected_message:
            expected_message = r'^Copied {} to {} with mike \S+$'.format(
                re.escape(expected_src),
                re.escape(', '.join(expected_aliases)))

        self._test_state(expected_message, [
            versions.VersionInfo('1.0', aliases=expected_aliases + ['latest'])
        ])
コード例 #23
0
ファイル: test_commands.py プロジェクト: java-tools/mike
    def _test_deploy(self,
                     expected_message=None,
                     expected_versions=[versions.VersionInfo('1.0')],
                     **kwargs):
        if not expected_message:
            rev = git_utils.get_latest_commit('master', short=True)
            expected_message = (
                r'^Deployed {} to {}( in .*)? with MkDocs \S+ and mike \S+$'.
                format(rev, expected_versions[0].version))

        if os.path.exists(self.cfg.site_dir):
            shutil.rmtree(self.cfg.site_dir)
        self._test_state(expected_message, expected_versions, **kwargs)
コード例 #24
0
    def _test_retitle(self, expected_message=None):
        message = subprocess.check_output(['git', 'log', '-1', '--pretty=%B'],
                                          universal_newlines=True).rstrip()
        if expected_message:
            self.assertEqual(message, expected_message)
        else:
            self.assertRegex(message,
                             r'^Set title of \S+ to 1\.0\.1 with mike \S+$')

        assertDirectory('.', {'versions.json', '1.0', '1.0/file.txt'})
        with open('versions.json') as f:
            self.assertEqual(list(versions.Versions.loads(f.read())), [
                versions.VersionInfo('1.0', '1.0.1'),
            ])
コード例 #25
0
ファイル: test_commands.py プロジェクト: java-tools/mike
    def _test_retitle(self, expected_message=None, directory='.'):
        message = check_output(['git', 'log', '-1', '--pretty=%B']).rstrip()
        if expected_message:
            self.assertEqual(message, expected_message)
        else:
            self.assertRegex(
                message,
                r'^Set title of \S+ to 1\.0\.1( in .*)? with mike \S+$')

        assertDirectory(directory, {'versions.json', '1.0', '1.0/file.txt'})
        with open(os.path.join(directory, 'versions.json')) as f:
            self.assertEqual(list(versions.Versions.loads(f.read())), [
                versions.VersionInfo('1.0', '1.0.1'),
            ])
コード例 #26
0
    def test_overwrite_alias(self):
        with git_utils.Commit('gh-pages', 'add versions.json') as commit:
            commit.add_file(
                git_utils.FileInfo(
                    'versions.json',
                    '[{"version": "1.0", "title": "1.0", "aliases": ["latest"]}]',
                ))
            commit.add_file(git_utils.FileInfo('1.0/file.txt', ''))
            commit.add_file(git_utils.FileInfo('latest/file.txt', ''))

        with self.assertRaises(ValueError):
            commands.deploy(self.stage, '2.0', '2.0.0', ['latest'])
        check_call_silent(['git', 'checkout', 'gh-pages'])
        self._test_deploy('add versions.json',
                          [versions.VersionInfo('1.0', '1.0', ['latest'])])
コード例 #27
0
    def test_overwrite_version(self):
        with git_utils.Commit('gh-pages', 'add versions.json') as commit:
            commit.add_file(
                git_utils.FileInfo(
                    'versions.json',
                    '[{"version": "1.0", "title": "1.0", "aliases": ["latest"]}]',
                ))
            commit.add_file(git_utils.FileInfo('1.0/old-file.txt', ''))
            commit.add_file(git_utils.FileInfo('latest/old-file.txt', ''))

        commands.deploy(self.stage, '1.0', '1.0.1', ['greatest'])
        check_call_silent(['git', 'checkout', 'gh-pages'])
        self._test_deploy(expected_versions=[
            versions.VersionInfo('1.0', '1.0.1', ['latest', 'greatest'])
        ])
コード例 #28
0
    def _test_alias(self, expected_message=None):
        message = subprocess.check_output(['git', 'log', '-1', '--pretty=%B'],
                                          universal_newlines=True).rstrip()
        if expected_message:
            self.assertEqual(message, expected_message)
        else:
            self.assertRegex(message, r'^Copied \S+ to latest with mike \S+$')

        assertDirectory('.', {
            'versions.json',
            '1.0/index.html',
            'latest/index.html',
        },
                        allow_extra=True)

        with open('versions.json') as f:
            self.assertEqual(list(versions.Versions.loads(f.read())), [
                versions.VersionInfo('1.0', aliases=['latest']),
            ])
コード例 #29
0
ファイル: test_commands.py プロジェクト: java-tools/mike
    def test_aliases_custom_redirect(self):
        real_open = open
        with mock.patch('builtins.open',
                        mock.mock_open(read_data=b'{{href}}')):
            with commands.deploy(self.cfg,
                                 '1.0',
                                 aliases=['latest'],
                                 template='template.html'):
                # Un-mock `open` so we can copy files for real.
                with mock.patch('builtins.open', real_open):
                    self._mock_build()

        check_call_silent(['git', 'checkout', 'gh-pages'])
        self._test_deploy(expected_versions=[
            versions.VersionInfo('1.0', aliases=['latest'])
        ])

        with open('latest/page.html') as f:
            self.assertEqual(f.read(), '../1.0/page.html')
        with open('latest/dir/index.html') as f:
            self.assertEqual(f.read(), '../../1.0/dir/')
コード例 #30
0
 def test_title(self):
     assertPopen(['mike', 'deploy', '1.0', '-t', '1.0.0'])
     check_call_silent(['git', 'checkout', 'gh-pages'])
     self._test_deploy(expected_versions=[
         versions.VersionInfo('1.0', '1.0.0')
     ])