def opens_EDITOR_with_version_file_when_it_needs_update(self, _): with _mock_context(self) as c: all_(c) path = "{0}/_version.py".format(FAKE_PACKAGE) # TODO: real code should probs expand EDITOR explicitly so it can # run w/o a shell wrap / require a full env? cmd = "$EDITOR {0}".format(path) c.run.assert_any_call(cmd, pty=True, hide=False)
def opens_EDITOR_with_changelog_when_it_needs_update(self, _): with _mock_context(self) as c: all_(c) # Grab changelog path from the context config, why not path = c.config.packaging.changelog_file # TODO: real code should probs expand EDITOR explicitly so it can # run w/o a shell wrap / require a full env? cmd = "$EDITOR {0}".format(path) c.run.assert_any_call(cmd, pty=True, hide=False)
def if_prompt_response_negative_no_action_taken(self, _): with _mock_context(self) as c: all_(c) # TODO: move all action-y code into subroutines, then mock them and # assert they were never called? # Expect that only the status-y run() calls were made. eq_(c.run.call_count, 2) commands = [x[0][0] for x in c.run.call_args_list] ok_(commands[0].startswith('git rev-parse')) ok_(commands[1].startswith('git tag'))
def displays_status_output(self, _): with _mock_context(self) as c: all_(c) output = sys.stdout.getvalue() for action in ( Changelog.NEEDS_RELEASE, VersionFile.NEEDS_BUMP, Tag.NEEDS_CUTTING, ): err = "Didn't see '{0}' text in status output!".format(action.name) ok_(action.value in output, err)
def no_changelog_update_needed_means_no_changelog_edit(self, _): with _mock_context(self) as c: all_(c) # TODO: as with the 'took no actions at all' test above, # proving a negative sucks - eventually make this subroutine # assert based. Meh. path = c.config.packaging.changelog_file cmd = "$EDITOR {0}".format(path) err = "Saw {0!r} despite changelog not needing update!".format( cmd ) ok_(cmd not in [x[0][0] for x in c.run.call_args_list], err)
def commits_and_adds_git_tag_when_needs_cutting(self, _): with _mock_context(self) as c: all_(c) version = "1.1.2" # as changelog has issues & prev was 1.1.1 # Ensure the commit necessity test happened. (Default mock_context # sets it up to result in a commit being necessary.) check = "git status --porcelain | egrep -v \"^\\?\"" c.run.assert_any_call(check, hide=True, warn=True) commit = "git commit -am \"Cut {0}\"".format(version) # TODO: annotated, signed, etc? tag = "git tag {0}".format(version) for cmd in (commit, tag): c.run.assert_any_call(cmd, hide=False)
def does_not_commit_if_no_commit_necessary(self, _): with _mock_context(self) as c: # Set up for a no-commit-necessary result to check command check = "git status --porcelain | egrep -v \"^\\?\"" # TODO: update MockContext so modifying it post-instantiation feels # cleaner. Modifying 'private' attrs feels bad. (Though in this # case, can't really make it public, as that risks clashing with # "real" members of the context/config...?) c._run[check] = Result("", exited=1) all_(c) # Expect NO git commit commands = [x[0][0] for x in c.run.call_args_list] ok_(not any(x.startswith("git commit") for x in commands)) # Expect git tag c.run.assert_any_call("git tag 1.1.2", hide=False)
def _run_all(c, mute=True): try: return all_(c) except SystemExit: if not mute: raise
def prompts_before_taking_action(self, mock_input): with _mock_context(self) as c: all_(c) eq_(mock_input.call_args[0][0], "Take the above actions? [Y/n] ")