def test_ignore_staged(tmpcwd):
    '''
    When working directory is dirty, ignore staged changes
    '''
    create_release_project()
    write_file(Path('project.py'), '')  # Invalid project.py
    git_('add', 'project.py')
    result = release('1.0.0')
    assert result.exit_code == 0, result.output
 def test_ignore_unstaged(self, tmpcwd):
     '''
     Pre-commit must ignore unstaged changes
     '''
     self.create_project()
     git_('add', '.')
     mkproject & pb.FG  # install pre-commit hook
     remove_file(Path('README.md'))
     git_('commit', '-m', 'message')  # This fails if unstaged change is included
def test_ignore_staged(tmpcwd):
    '''
    When working directory is dirty, ignore staged changes
    '''
    create_release_project()
    write_file(Path('project.py'), '')  # Invalid project.py
    git_('add', 'project.py')
    result = release('1.0.0')
    assert result.exit_code == 0, result.output
 def test_ignore_untracked(self, tmpcwd):
     '''
     Pre-commit must ignore untracked changes
     '''
     self.create_project()
     git_('add', '.')
     mkproject & pb.FG  # install pre-commit hook
     test_fail_path = Path('operation/mittens/tests/test_fail.py')
     write_file(test_fail_path, extra_files[test_fail_path])
     git_('commit', '-m', 'message')  # This fails if the untracked test is included
 def test_invalid_project(self, tmpcwd):
     '''
     Invalid project cancels the commit
     '''
     self.create_project()
     mkproject & pb.FG  # install pre-commit hook
     remove_file(Path('README.md'))
     git_('add', '.')
     with assert_process_fails(stderr_matches='Missing file: README.md'):
         git_('commit', '-m', 'message')  # runs the hook
def test_happy_days(tmpcwd, mocked_release):
    '''
    When valid project with clean working dir and valid version, release
    '''
    create_release_project()
    result = release('1.0.0')
    git_('reset', '--hard')
    assert result.exit_code == 0, result.output
    assert mocked_release.call_args_list == [(('pypitest',),), (('pypi',),)]
    assert git_('tag').strip() == 'v1.0.0'
    setup_args = get_setup_args()
    assert setup_args['version'] == '1.0.0'
def test_happy_days(tmpcwd, mocked_release):
    '''
    When valid project with clean working dir and valid version, release
    '''
    create_release_project()
    result = release('1.0.0')
    git_('reset', '--hard')
    assert result.exit_code == 0, result.output
    assert mocked_release.call_args_list == [(('pypitest', ), ),
                                             (('pypi', ), )]
    assert git_('tag').strip() == 'v1.0.0'
    setup_args = get_setup_args()
    assert setup_args['version'] == '1.0.0'
def create_release_project(project=project1, test_index=True):
    '''
    Create valid project for release
    '''
    project = project.copy()
    test_succeed_path = Path('operation/mittens/tests/test_succeed.py')
    project.files[test_succeed_path] = extra_files[test_succeed_path] 
    if test_index:
        project.project_py['index_test'] = 'pypitest'
    create_project(project)
    
    git_('add', '.')
    mkproject()
    git_['commit', '-m', 'Initial commit'] & pb.FG
    
    # Create repo and use as remote
    path = Path.cwd() / '.cache'  # some location ignored by .gitignore
    path.mkdir()
    path /= 'other_repo'
    path.mkdir()
    with pb.local.cwd(str(path)):
        git_('init', '--bare')
    git_('remote', 'add', 'origin', path.as_uri())
    git_('push', '--set-upstream', 'origin', 'master')
    git_['status'] & pb.FG
def create_release_project(project=project1, test_index=True):
    '''
    Create valid project for release
    '''
    project = project.copy()
    test_succeed_path = Path('operation/mittens/tests/test_succeed.py')
    project.files[test_succeed_path] = extra_files[test_succeed_path]
    if test_index:
        project.project_py['index_test'] = 'pypitest'
    create_project(project)

    git_('add', '.')
    mkproject()
    git_['commit', '-m', 'Initial commit'] & pb.FG

    # Create repo and use as remote
    path = Path.cwd() / '.cache'  # some location ignored by .gitignore
    path.mkdir()
    path /= 'other_repo'
    path.mkdir()
    with pb.local.cwd(str(path)):
        git_('init', '--bare')
    git_('remote', 'add', 'origin', path.as_uri())
    git_('push', '--set-upstream', 'origin', 'master')
    git_['status'] & pb.FG
 def test_no_ignore(self, tmpcwd):
     '''
     When well-behaved pre_commit_no_ignore, copy matched files to pre-commit
     tmp dir
     '''
     project = self.project
     project.project_py['pre_commit_no_ignore'] = ['operation/mittens/test/mah_*']
     project.files[Path('operation/mittens/test/mah_file')] = 'content'
     project.files[Path('operation/mittens/test/mah_dir/some_file')] = 'some file content'
     project.files[Path('operation/mittens/test/test_it.py')] = dedent('''\
         from pathlib import Path
         def test_it():
             # file is there
             dir = Path(__file__).parent
             with (dir / 'mah_file').open('r') as f:
                 assert f.read() == 'content'
                 
             # recursively copied directory is there
             with (dir / 'mah_dir/some_file').open('r') as f:
                 assert f.read() == 'some file content'
         ''')
     create_project(project)
     mkproject() # install pre commit hook
     git_('add', '.')
     git_('reset', 'operation/mittens/test/mah_file')
     git_('reset', 'operation/mittens/test/mah_dir')
     git_('commit', '-m', 'message') # run pre-commit
 def test_happy_days(self, tmpcwd):
     '''
     If all well, commit
     '''
     project = self.project
     create_project(project)
     mkproject & pb.FG  # install pre-commit hook
     git_('add', '.')
     
     project.project_py['entry_points'] = {
         'console_scripts': [
             'mycli = operation.mittens.main:main',
         ],
     }
     project.files[Path('operation/mittens/main.py')] = 'def main(): pass'
     update_project(project)  # without staging it
     mkproject()
     
     git_('commit', '-m', 'message')  # runs the hook
     pb.local['sh']('-c', '. venv/bin/activate; mycli')  # mycli should be available in the venv, even though it wasn't part of the commit (it shouldn't be available in the venv during the pre-commit test run)
Ejemplo n.º 12
0
def test_older_than_ancestor(tmpcwd):
    '''
    Ask user before releasing with an older version than an ancestor commit 
    '''
    create_release_project()
    git_('tag', 'v2.0.0')
    Path('dummy1').touch()
    git_('add', '.')
    git_('commit', '-m', 'message')
    git_('tag', 'v0.5.0')
    
    result = release('1.0.0', input='y\n')
    assert result.exit_code == 0, result.output
    assert '2.0.0' in result.output
    assert 'less than' in result.output
    assert 'Do you want to' in result.output
Ejemplo n.º 13
0
def test_older_than_ancestor(tmpcwd):
    '''
    Ask user before releasing with an older version than an ancestor commit 
    '''
    create_release_project()
    git_('tag', 'v2.0.0')
    Path('dummy1').touch()
    git_('add', '.')
    git_('commit', '-m', 'message')
    git_('tag', 'v0.5.0')

    result = release('1.0.0', input='y\n')
    assert result.exit_code == 0, result.output
    assert '2.0.0' in result.output
    assert 'less than' in result.output
    assert 'Do you want to' in result.output
 def test_include_changes(self, tmpcwd):
     '''
     Changes made by mkproject must be staged, especially during precommit
     '''
     self.create_project()
     mkproject & pb.FG  # install pre-commit hook
     write_file('requirements.in', 'pytest')
     git_('add', '.')
     git_('commit', '-m', 'message')  # runs the hook, which calls ct-mkproject, which changes setup.py in this case
     
     # Expected change happened and is part of the commit
     git_('reset', '--hard')
     assert get_setup_args()['install_requires'] == ['pytest']
Ejemplo n.º 15
0
def test_older_than_other_branch(tmpcwd):
    '''
    Don't ask user before releasing with an older version than a commit in another branch (i.e. not an ancestor) 
    '''
    create_release_project()
    git_('tag', 'v0.5.0')
    
    git_('checkout', '-b', 'other')
    Path('dummy1').touch()
    git_('add', '.')
    git_('commit', '-m', 'message')
    git_('tag', 'v2.0.0')
    
    git_('checkout', 'master')
    Path('dummy2').touch()
    git_('add', '.')
    git_('commit', '-m', 'message')
    git_('tag', 'v0.8.0')
    
    result = release('1.0.0')
    assert result.exit_code == 0, result.output
    assert 'v2.0.0' not in result.output
    assert 'less than' not in result.output
    assert 'Do you want to' not in result.output
Ejemplo n.º 16
0
def test_older_than_other_branch(tmpcwd):
    '''
    Don't ask user before releasing with an older version than a commit in another branch (i.e. not an ancestor) 
    '''
    create_release_project()
    git_('tag', 'v0.5.0')

    git_('checkout', '-b', 'other')
    Path('dummy1').touch()
    git_('add', '.')
    git_('commit', '-m', 'message')
    git_('tag', 'v2.0.0')

    git_('checkout', 'master')
    Path('dummy2').touch()
    git_('add', '.')
    git_('commit', '-m', 'message')
    git_('tag', 'v0.8.0')

    result = release('1.0.0')
    assert result.exit_code == 0, result.output
    assert 'v2.0.0' not in result.output
    assert 'less than' not in result.output
    assert 'Do you want to' not in result.output