コード例 #1
0
 def test_isValidArgs_return_OK_empty_title(self):
   argv = []
   argv.append("filename.py")
   argv.append("targetfile.markdown")
   cli = CliHandler(argv)
   self.assertTrue(cli.isValidArgs() == ValidationResult.OK)
   self.assertTrue(cli.title == "")
   self.assertTrue(str(cli.targetFilename) == "targetfile.markdown")
コード例 #2
0
 def test_isValidArgs_return_OK_multiple_words(self):
   argv = []
   argv.append("filename")
   argv.append("somefile.markdown")
   argv.append("my title")
   cli = CliHandler(argv)
   self.assertTrue(cli.isValidArgs() == ValidationResult.OK)
   self.assertTrue(cli.title == "my title")
コード例 #3
0
 def test_isValidArgs_return_OK_sometitle(self):
   argv = []
   argv.append("filename")
   argv.append("somefile.markdown")
   argv.append("sometitle")
   cli = CliHandler(argv)
   self.assertTrue(cli.isValidArgs() == ValidationResult.OK)
   self.assertTrue(str(cli.title) == 'sometitle')
コード例 #4
0
def main(argv):
    cli = CliHandler(argv)
    if cli.isValidArgs() == ValidationResult.OK:
        writeMarkDownBlogFile(cli.targetFilename, cli.title)
    elif cli.isValidArgs() == ValidationResult.NOT_ENOUGH_ARGS:
        print("ERROR: You have not provided enough arguments!")
        print("Use -help to find out more about the usage...")
    elif cli.isValidArgs() == ValidationResult.HELP:
        print_usage()
    elif cli.isValidArgs() == ValidationResult.NOT_MARKDOWN:
        print("ERROR: The target file should be a markdown file!")
コード例 #5
0
 def test_isValidArgs_return_NOT_MARKDOWN(self):
   argv = []
   argv.append("filename")
   argv.append("filename.txt")
   cli = CliHandler(argv)
   self.assertTrue(cli.isValidArgs() == ValidationResult.NOT_MARKDOWN)
コード例 #6
0
 def test_isValidArgs_return_NOT_ENOUGH_ARGS(self):
   argv = []
   argv.append("filename")
   cli = CliHandler(argv)
   self.assertTrue(cli.isValidArgs() == ValidationResult.NOT_ENOUGH_ARGS)
コード例 #7
0
 def test_isValidArgs_return_HELP(self):
   argv = []
   argv.append("filename")
   argv.append("-help")
   cli = CliHandler(argv)
   self.assertTrue(cli.isValidArgs() == ValidationResult.HELP)
コード例 #8
0
# Openssl commands automation demo using python

from cli_handler import CliHandler
from cli_exception import CliException
import sys

openssl_binary = '/usr/bin/openssl'

try:
    cli_handle = CliHandler(openssl_binary)
    print(cli_handle)
    cli_handle.expect_data('OpenSSL>')
    cli_handle.send_data('version')  #Cheking version of openssl
    cli_handle.expect_data('OpenSSL 1.1.0g  2 Nov 2017')
    # Generate a random hex string of length 16
    cli_handle.send_data('rand -hex 16')
except CliException as e:
    print(e)
except Exception as exp:
    print(exp)
    sys.exit()