def test_prompts_for_bump_arg(self, mock_choice, __, ___): with patch.object(sys, 'argv', ['taggy']): main() assert mock_choice.called_once_with( 'Choose: [M]ajor/[m]inor/[p]atch: ', ('Major', 'minor', 'patch'), allow_prefix=True)
def test_creates_tag_on_confirmation(self, mock_create, _, __, ___): with pytest.raises(SystemExit): with patch.object(sys, 'argv', ['taggy']): with patch('os.getcwd', return_value='/home/user/proj'): main() assert mock_create.called_once_with( '/home/user/proj', '0.1.0', 'version {}')
def test_success_message(self, mock_create_tag, _, __, capsys): with patch.object(sys, 'argv', ['taggy', 'patch']): with patch.object(os, 'getcwd', return_value='/sample/path'): main() assert mock_create_tag.called_once_with( ['/sample/path', 'v2.1.1', 'version {}']) out, err = capsys.readouterr() assert out.strip() == 'Created new tag: 2.1.1'
def test_skip_commit_on_prompt(self, mock_args, mock_run, _, __, capsys): files = self.files ns = Namespace(bump='patch', files=files, preview=False, no_tag=True) mock_args.return_value = ns with pytest.raises(SystemExit): with patch('taggy.cli.confirm', return_value=False): with patch('taggy.cli.copy'): main() with patch('taggy.cli.run') as mock_run: assert not mock_run.called
def test_commits_changes(self, mock_args, _, __, ___, capsys): files = self.files ns = Namespace(bump='patch', files=files, preview=False, no_tag=True) mock_args.return_value = ns with patch('taggy.cli.run') as mock_run: with pytest.raises(SystemExit): with patch('taggy.cli.confirm', return_value=True): main() assert mock_run.call_args_list == [ (call(['git', 'add', 'foo.py', 'bar.py'])), (call(['git', 'commit', '-m', '"bump version number"'])) ]
def test_shows_file_diffs_on_preview(self, mock_args, _, __, ___, capsys): files = self.files ns = Namespace(bump='patch', files=files, preview=True, no_tag=True) mock_args.return_value = ns with pytest.raises(SystemExit): main() out, err = capsys.readouterr() assert out == "\n".join( ("\nVersion Diff:", "- v2.1.0", "? ^", "+ v2.1.1", "? ^", "\n--- a/foo.py", "+++ b/foo.py", "@@ -1 +1 @@", "-2.1.0", "+2.1.1", "\n--- a/bar.py", "+++ b/bar.py", "@@ -1 +1 @@", "-2.1.0", "+2.1.1\n\n"))
def test_prints_preview(self, _, __, capsys): with pytest.raises(SystemExit): with patch.object(sys, 'argv', ['taggy', 'patch', '--preview']): main() out, _ = capsys.readouterr() assert out.strip() == '\n'.join(( "Version Diff:", "- 2.1.0", "? ^", "+ 2.1.1", "? ^", ))
def test_handles_prefix(self, mock_create_tag, _, __): with patch.object(sys, 'argv', ['taggy', 'patch']): with patch.object(os, 'getcwd', return_value='/sample/path'): main() assert mock_create_tag.called_once_with( ['/sample/path', 'v2.1.1', 'version {}'])
def test_prompts_for_tag_creation(self, _, __, ___): with pytest.raises(SystemExit): with patch.object(sys, 'argv', ['taggy']): main()