Exemple #1
0
	def test_sys_exit_failure(self):
		"""Test application exit with exit code 1"""
		with (self.assertRaises(SystemExit)) as sysexit:
			system.exit_fail()
			self.assertEqual(1, sysexit.code)
Exemple #2
0
def main():
    import sys
    from Naked.commandline import Command
    #from Naked.toolshed.state import StateObject
    from Naked.toolshed.system import stderr, exit_success, exit_fail
    from status.commands.http_request import Get, Post

    #------------------------------------------------------------------------------------------
    # [ Instantiate command line object ]
    #   used for all subsequent conditional logic in the CLI application
    #------------------------------------------------------------------------------------------
    c = Command(sys.argv[0], sys.argv[1:])
    #------------------------------------------------------------------------------
    # [ Instantiate state object ]
    #------------------------------------------------------------------------------
    # state = StateObject()
    #------------------------------------------------------------------------------------------
    # [ Command Suite Validation ] - early validation of appropriate command syntax
    # Test that user entered a primary command, print usage if not
    #------------------------------------------------------------------------------------------
    if not c.command_suite_validates():
        from status.commands.usage import Usage
        Usage().print_usage()
        exit_fail()

    #------------------------------------------------------------------------------------------
    # [ NAKED FRAMEWORK COMMANDS ]
    # Naked framework provides default help, usage, and version commands for all applications
    #   --> settings for user messages are assigned in the lib/status/settings.py file
    #------------------------------------------------------------------------------------------
    if c.help():  # User requested naked help (help.py module in commands directory)
        from status.commands.help import Help
        Help().print_help()
    elif c.usage():  # user requested naked usage info (usage.py module in commands directory)
        from status.commands.usage import Usage
        Usage().print_usage()
    elif c.version(): # user requested naked version (version.py module in commands directory)
        from status.commands.version import Version
        Version().print_version()
    #------------------------------------------------------------------------------------------
    # [ PRIMARY COMMAND LOGIC ]
    #   Enter your command line parsing logic below
    #------------------------------------------------------------------------------------------

    # POST request
    elif c.option("-p") or c.option("--post"):
        if c.arg1:
            post = Post(c.arg1)
            post.post_response()
        else:
            stderr("Please enter a URL to test.", 1)

    # GET request
    elif len(c.arg0) > 0:
        get = Get(c.arg0)
        get.get_response()

    #------------------------------------------------------------------------------------------
    # [ DEFAULT MESSAGE FOR MATCH FAILURE ]
    # Message to provide to the user when all above conditional logic fails to meet a true condition
    #------------------------------------------------------------------------------------------
    else:
        stderr("Please enter a URL to test.", 1)
 def ensure_git_repo(self):
     status_output = run('git status', suppress_stdout=True, suppress_stderr=True)
     if not status_output:
         print('Please run this command in a git repository', file=sys.stderr)
         exit_fail()
 def get_git_log(self):
     log_output = run('git log --numstat --reverse', suppress_stdout=True, suppress_stderr=False)
     if not log_output:
         print('Error fetching git log', file=sys.stderr)
         exit_fail()
     return log_output
Exemple #5
0
 def test_sys_exit_failure(self):
     """Test application exit with exit code 1"""
     with (self.assertRaises(SystemExit)) as sysexit:
         system.exit_fail()
         self.assertEqual(1, sysexit.code)