Ejemplo n.º 1
0
    def test_quit_tab(self):
        """Test console response to Q+tab (should be 'quit').

        NOTICE: This test is designed to be executed from the base of the
        source tree. If you want to run it from elsewhere, you will need
        to change the 'utildir' variable below.

        """
        options = {
            'verbosity': False,
            'quiet': False,
            'width': 80,
            'utildir': "./scripts",
            'variables': [],
            'prompt': '>',
            'welcome': "",
            'goodbye': "",
            'commands': [],
            'custom': True,
            'hide_util': False,
            'add_util': []
        }
        util_con = UtilitiesConsole(options)
        stdout_backup = sys.stdout
        try:
            sys.stdout = open(os.devnull, 'w')
            test_cases = ["q", "Q"]
            for key in test_cases:
                util_con.cmd_line.command = ""
                util_con.cmd_line.add(key)
                util_con.do_command_tab("q")
                self.assertEqual(util_con.cmd_line.command,
                                 "{0}uit ".format(key))
        finally:
            sys.stdout = stdout_backup
    def test_quit_tab(self):
        """Test console response to Q+tab (should be 'quit').

        NOTICE: This test is designed to be executed from the base of the
        source tree. If you want to run it from elsewhere, you will need
        to change the 'utildir' variable below.

        """
        options = {
            'verbosity': False,
            'quiet': False,
            'width': 80,
            'utildir': "./scripts",
            'variables': [],
            'prompt': '>',
            'welcome': "",
            'goodbye': "",
            'commands': [],
            'custom': True,
            'hide_util': False,
            'add_util': []
        }
        util_con = UtilitiesConsole(options)
        stdout_backup = sys.stdout
        try:
            sys.stdout = open(os.devnull, 'w')
            test_cases = ["q", "Q"]
            for key in test_cases:
                util_con.cmd_line.command = ""
                util_con.cmd_line.add(key)
                util_con.do_command_tab("q")
                self.assertEqual(util_con.cmd_line.command, "{0}uit ".format(key))
        finally:
            sys.stdout = stdout_backup
Ejemplo n.º 3
0
 def setUp(self):
     options = {
         'verbosity': False,
         'quiet': False,
         'width': 80,
         'utildir': _UTIL_DIR,
         'variables': [],
         'prompt': '>',
         'welcome': "",
         'goodbye': "",
         'commands': [],
         'custom': True,
         'hide_util': False,
         'add_util': []
     }
     self.util_con = UtilitiesConsole(options)
 def setUp(self):
     options = {
         'verbosity': False,
         'quiet': False,
         'width': 80,
         'utildir': _UTIL_DIR,
         'variables': [],
         'prompt': '>',
         'welcome': "",
         'goodbye': "",
         'commands': [],
         'custom': True,
         'hide_util': False,
         'add_util': []
     }
     self.util_con = UtilitiesConsole(options)
Ejemplo n.º 5
0
class TestUtilitiesConsole(unittest.TestCase):
    """Test Case class for the Utilities Console"""
    def setUp(self):
        options = {
            'verbosity': False,
            'quiet': False,
            'width': 80,
            'utildir': _UTIL_DIR,
            'variables': [],
            'prompt': '>',
            'welcome': "",
            'goodbye': "",
            'commands': [],
            'custom': True,
            'hide_util': False,
            'add_util': []
        }
        self.util_con = UtilitiesConsole(options)

    def test_strange_keyboard_input(self):
        test_cases = {
            'R': "INSERT_KEY",
            'G': 'HOME_KEY',
            'O': 'END_KEY',
            'I': 'PAGE_UP_KEY',
            'Q': 'PAGE_DOWN_KEY'
        }

        for key in test_cases:
            self.assertEqual(_WIN_COMMAND_KEY.get(key), None)

    def test_backspace_beginning(self):
        """Test console response to BACKSPACE KEY when the cursor
        is at the beginning of the line.
        """

        test_cases = ['BACKSPACE_POSIX', 'BACKSPACE_WIN']
        self.util_con.cmd_line.command = "12345"
        self.util_con.cmd_line.length = 5
        self.util_con.cmd_line.position = 0
        for key in test_cases:
            self.util_con._process_command_keys(key)
            self.assertEqual("12345", self.util_con.cmd_line.command)

    def test_backspace_middle(self):
        """Test console response to BACKSPACE KEY when the cursor
        is in the middle of the line.
        """

        self.util_con.cmd_line.command = "12345"
        self.util_con.cmd_line.length = 5
        self.util_con.cmd_line.position = 3
        self.util_con._process_command_keys('BACKSPACE_POSIX')
        self.assertEqual("1245", self.util_con.cmd_line.command)
        self.util_con._process_command_keys('BACKSPACE_WIN')
        self.assertEqual("145", self.util_con.cmd_line.command)

    def test_backspace_end(self):
        """Test console response to BACKSPACE KEY when the cursor
        is in the end of the line.
        """

        self.util_con.cmd_line.command = "12345"
        self.util_con.cmd_line.length = 5
        self.util_con.cmd_line.position = 5
        self.util_con._process_command_keys('BACKSPACE_POSIX')
        self.assertEqual("1234", self.util_con.cmd_line.command)
        self.util_con._process_command_keys('BACKSPACE_WIN')
        self.assertEqual("123", self.util_con.cmd_line.command)

    def test_quit_tab(self):
        """Test console response to Q+tab (should be 'quit').

        NOTICE: This test is designed to be executed from the base of the
        source tree. If you want to run it from elsewhere, you will need
        to change the 'utildir' variable below.

        """
        options = {
            'verbosity': False,
            'quiet': False,
            'width': 80,
            'utildir': "./scripts",
            'variables': [],
            'prompt': '>',
            'welcome': "",
            'goodbye': "",
            'commands': [],
            'custom': True,
            'hide_util': False,
            'add_util': []
        }
        util_con = UtilitiesConsole(options)
        stdout_backup = sys.stdout
        try:
            sys.stdout = open(os.devnull, 'w')
            test_cases = ["q", "Q"]
            for key in test_cases:
                util_con.cmd_line.command = ""
                util_con.cmd_line.add(key)
                util_con.do_command_tab("q")
                self.assertEqual(util_con.cmd_line.command,
                                 "{0}uit ".format(key))
        finally:
            sys.stdout = stdout_backup
Ejemplo n.º 6
0
    extra_utils_dict = {}
    for utility in opt.add_util:
        extra_utils_dict[utility] = ()

    options = {
        'verbosity': verbosity,
        'quiet': quiet,
        'width': opt.width,
        'utildir': opt.utildir,
        'variables': build_variable_dictionary_list(args),
        'prompt': 'mysqluc> ',
        'welcome': WELCOME_MESSAGE.format(VERSION_STRING, COPYRIGHT_FULL),
        'goodbye': GOODBYE_MESSAGE,
        'commands': opt.commands,
        'custom': True,  # We are using custom commands
        'hide_util': opt.hide_util,
        'add_util': extra_utils_dict
    }

    try:
        print("Launching console ...")
        util_con = UtilitiesConsole(options)
        util_con.run_console()
    except KeyboardInterrupt:
        print(options['goodbye'])
    except UtilError:
        _, e, _ = sys.exc_info()
        print("ERROR: %s" % e.errmsg)

    sys.exit()
class TestUtilitiesConsole(unittest.TestCase):
    """Test Case class for the Utilities Console"""

    def setUp(self):
        options = {
            'verbosity': False,
            'quiet': False,
            'width': 80,
            'utildir': _UTIL_DIR,
            'variables': [],
            'prompt': '>',
            'welcome': "",
            'goodbye': "",
            'commands': [],
            'custom': True,
            'hide_util': False,
            'add_util': []
        }
        self.util_con = UtilitiesConsole(options)

    def test_strange_keyboard_input(self):
        test_cases = {'R': "INSERT_KEY", 'G': 'HOME_KEY', 'O': 'END_KEY',
                      'I': 'PAGE_UP_KEY', 'Q': 'PAGE_DOWN_KEY'}

        for key in test_cases:
            self.assertEqual(_WIN_COMMAND_KEY.get(key), None)

    def test_backspace_beginning(self):
        """Test console response to BACKSPACE KEY when the cursor
        is at the beginning of the line.
        """

        test_cases = ['BACKSPACE_POSIX', 'BACKSPACE_WIN']
        self.util_con.cmd_line.command = "12345"
        self.util_con.cmd_line.length = 5
        self.util_con.cmd_line.position = 0
        for key in test_cases:
            self.util_con._process_command_keys(key)
            self.assertEqual("12345", self.util_con.cmd_line.command)

    def test_backspace_middle(self):
        """Test console response to BACKSPACE KEY when the cursor
        is in the middle of the line.
        """

        self.util_con.cmd_line.command = "12345"
        self.util_con.cmd_line.length = 5
        self.util_con.cmd_line.position = 3
        self.util_con._process_command_keys('BACKSPACE_POSIX')
        self.assertEqual("1245", self.util_con.cmd_line.command)
        self.util_con._process_command_keys('BACKSPACE_WIN')
        self.assertEqual("145", self.util_con.cmd_line.command)

    def test_backspace_end(self):
        """Test console response to BACKSPACE KEY when the cursor
        is in the end of the line.
        """

        self.util_con.cmd_line.command = "12345"
        self.util_con.cmd_line.length = 5
        self.util_con.cmd_line.position = 5
        self.util_con._process_command_keys('BACKSPACE_POSIX')
        self.assertEqual("1234", self.util_con.cmd_line.command)
        self.util_con._process_command_keys('BACKSPACE_WIN')
        self.assertEqual("123", self.util_con.cmd_line.command)

    def test_quit_tab(self):
        """Test console response to Q+tab (should be 'quit').

        NOTICE: This test is designed to be executed from the base of the
        source tree. If you want to run it from elsewhere, you will need
        to change the 'utildir' variable below.

        """
        options = {
            'verbosity': False,
            'quiet': False,
            'width': 80,
            'utildir': "./scripts",
            'variables': [],
            'prompt': '>',
            'welcome': "",
            'goodbye': "",
            'commands': [],
            'custom': True,
            'hide_util': False,
            'add_util': []
        }
        util_con = UtilitiesConsole(options)
        stdout_backup = sys.stdout
        try:
            sys.stdout = open(os.devnull, 'w')
            test_cases = ["q", "Q"]
            for key in test_cases:
                util_con.cmd_line.command = ""
                util_con.cmd_line.add(key)
                util_con.do_command_tab("q")
                self.assertEqual(util_con.cmd_line.command, "{0}uit ".format(key))
        finally:
            sys.stdout = stdout_backup
Ejemplo n.º 8
0
    verbosity = opt.verbosity

quiet = opt.quiet
if opt.quiet is None:
    quiet = False

options = {
    "verbosity": verbosity,
    "quiet": quiet,
    "width": opt.width,
    "utildir": opt.utildir,
    "variables": build_variable_dictionary_list(args),
    "prompt": "mysqluc> ",
    "welcome": WELCOME_MESSAGE % VERSION_STRING,
    "goodbye": GOODBYE_MESSAGE,
    "commands": opt.commands,
    "custom": True,  # We are using custom commands
}

try:
    print("Launching console ...")
    util_con = UtilitiesConsole(options)
    util_con.run_console()
except KeyboardInterrupt:
    print(options["goodbye"])
except UtilError:
    _, e, _ = sys.exc_info()
    print("ERROR: %s" % e.errmsg)

sys.exit()