@@ -1528,6 +1528,61 @@ def run_query(self, query, new_line=True):
15281528 assert MockMyCli .connect_args ['host' ] == 'env_host'
15291529
15301530
1531+ def test_hostname_option_alias (monkeypatch ):
1532+ class Formatter :
1533+ format_name = None
1534+
1535+ class Logger :
1536+ def debug (self , * args , ** args_dict ):
1537+ pass
1538+
1539+ def warning (self , * args , ** args_dict ):
1540+ pass
1541+
1542+ class MockMyCli :
1543+ config = {
1544+ 'main' : {},
1545+ 'alias_dsn' : {},
1546+ 'connection' : {
1547+ 'default_keepalive_ticks' : 0 ,
1548+ },
1549+ }
1550+
1551+ def __init__ (self , ** _args ):
1552+ self .logger = Logger ()
1553+ self .destructive_warning = False
1554+ self .main_formatter = Formatter ()
1555+ self .redirect_formatter = Formatter ()
1556+ self .ssl_mode = 'auto'
1557+ self .my_cnf = {'client' : {}, 'mysqld' : {}}
1558+ self .default_keepalive_ticks = 0
1559+
1560+ def connect (self , ** args ):
1561+ MockMyCli .connect_args = args
1562+
1563+ def run_query (self , query , new_line = True ):
1564+ pass
1565+
1566+ import mycli .main
1567+
1568+ monkeypatch .setattr (mycli .main , 'MyCli' , MockMyCli )
1569+ runner = CliRunner ()
1570+
1571+ result = runner .invoke (
1572+ mycli .main .click_entrypoint ,
1573+ args = [
1574+ '--hostname' ,
1575+ 'alias_host' ,
1576+ '--port' ,
1577+ f'{ DEFAULT_PORT } ' ,
1578+ '--database' ,
1579+ 'database' ,
1580+ ],
1581+ )
1582+ assert result .exit_code == 0
1583+ assert MockMyCli .connect_args ['host' ] == 'alias_host'
1584+
1585+
15311586def test_port_option_and_mysql_tcp_port_envvar (monkeypatch ):
15321587 class Formatter :
15331588 format_name = None
0 commit comments