Changeset a4623f4 for .tests/test1.py


Ignore:
Timestamp:
2021-03-16T14:23:56Z (4 years ago)
Author:
/ <>
Children:
c248e37
Parents:
23fd63d
Message:

more loud

File:
1 edited

Legend:

Unmodified
Added
Removed
  • .tests/test1.py

    r23fd63d ra4623f4  
    44import select
    55
     6YESTEST = True
    67MESSAGETEST = True
    7 BLOCKTEST = False
     8BLOCKTEST = True
    89OFFLINETEST = False
    910RENAMETEST = True
    10 BURPTEST = True
     11SHOWLOG = True
    1112
    12 FAILED = False
     13FAILED = []
     14
     15SEPARATOR = "================================"
     16SMOLPARATOR = "--------------------------------"
    1317
    1418class IrcClient:
     
    8387        self.send_priv_msg("&bitlbee", "rename " + oldnick + " " + newnick)
    8488       
    85 def test_send_message(sender, receiver, message):
     89def msg_comes_thru(sender, receiver, message):
    8690    sender.send_priv_msg(receiver.nick, message)
    8791    received = receiver.receive().find(message) != -1
    88     return received;
     92    return received
     93
     94def perform_test(clis, test_function, test_name):
     95    global FAILED
     96    for cli in clis:
     97        cli.tmplog=""
     98
     99    print("\n"+SEPARATOR)
     100    print("Test: "+test_name)
     101
     102    if test_function(clis):
     103        print("Test passed")
     104    else:
     105        print("Test failed")
     106        FAILED += [test_name]
     107
     108        flag = False
     109        for cli in clis:
     110            if cli.tmplog != "":
     111                print(SMOLPARATOR)
     112                print("Test Log "+ cli.nick+":")
     113                print(cli.tmplog)
     114                flag = True
     115        if flag:
     116            print(SMOLPARATOR)
     117
     118    print(SEPARATOR+"\n")
     119
     120def yes_test(clis):
     121    ret = False
     122    for _ in range(100):
     123        clis[0].send_raw("yes", loud = False)
     124        clis[0].receive()
     125        if (not ret) and clis[0].log.find("Did I ask you something?"):
     126            ret = True
     127        if clis[0].log.find("Buuuuuuuuuuuuuuuurp"):
     128            print("The RNG gods smile upon us")
     129            break
     130    return ret
     131
     132def message_test(clis):
     133    print("Test: Send message")
     134    ret = msg_comes_thru(clis[0], clis[1], 'ohai <3')
     135    ret = ret & msg_comes_thru(clis[1], clis[0], 'uwu *pounces*')
     136    return ret
     137
     138def block_test(clis):
     139    clis[0].block_jabber_buddy(clis[1].nick)
     140    ret = not msg_comes_thru(clis[1], clis[0], 'm-meow?')
     141    clis[0].unblock_jabber_buddy(clis[1].nick)
     142    ret = ret & msg_comes_thru(clis[1], clis[0], '*purrs*')
     143    return ret
     144
     145def rename_test(clis):
     146    newname = "xXx_pup_LINKENPARK4EVA"
     147    message = "rawr meanmz i luv<3 u in dinosaur"
     148
     149    clis[0].rename_jabber_buddy(clis[1].nick, newname)
     150    clis[0].send_priv_msg(newname, message)
     151    ret = clis[1].receive().find(message) != -1
     152
     153    clis[0].rename_jabber_buddy("-del", newname)
     154    ret = ret & msg_comes_thru(clis[0], clis[1], "rawr")
     155    return ret
    89156
    90157def run_tests():
     
    96163        cli.connect()
    97164
    98     if BURPTEST:
    99         print("Test: Yes")
    100         ret = False
    101         for _ in range(100):
    102             clis[0].send_raw("yes")
    103             clis[0].receive()
    104             if (not ret) and clis[0].log.find("Did I ask you something?"):
    105                 ret = True
    106             if clis[0].log.find("Buuuuuuuuuuuuuuuurp"):
    107                 print("The RNG gods smile upon us")
    108                 break
    109         if ret:
    110             print("Test passed")
    111         else:
    112             print("Test failed")
     165    if YESTEST:
     166        perform_test(clis, yes_test, "Yes")
    113167
    114168    for cli in clis:
     
    117171
    118172    if MESSAGETEST:
    119         print("Test: Send message")
    120         ret = test_send_message(clis[0], clis[1], 'ohai <3')
    121         ret = ret & test_send_message(clis[1], clis[0], 'uwu *pounces*')
    122         if ret:
    123             print("Test passed")
    124         else:
    125             print("Test failed")
    126             FAILED = True;
    127            
     173        perform_test(clis, message_test, "Send message")
    128174
    129175    if BLOCKTEST:
    130         print("Test: Block/Unblock")
    131         clis[0].block_jabber_buddy(clis[1].nick)
    132         ret = not test_send_message(clis[1], clis[0], 'm-meow?')
    133         clis[0].unblock_jabber_buddy(clis[1].nick)
    134         ret = ret & test_send_message(clis[1], clis[0], '*purrs*')
    135         if ret:
    136             print("Test passed")
    137         else:
    138             print("Test failed")
    139             FAILED = True;
     176        perform_test(clis, block_test, "Block user")
    140177
    141178    if RENAMETEST:
    142         print("Test: Rename buddy")
    143         newname = "xXx_pup_LINKENPARK4EVA"
    144         message = "rawr meanmz i luv<3 u in dinosaur"
     179        perform_test(clis, rename_test, "Rename user")
    145180
    146         clis[0].rename_jabber_buddy(clis[1].nick, newname)
    147         clis[0].send_priv_msg(newname, message)
    148         ret = clis[1].receive().find(message) != -1
     181    if FAILED or SHOWLOG:
     182        print("")
     183        for cli in clis:
     184            print(SMOLPARATOR)
     185            print("Log "+ cli.nick+":")
     186            print(cli.log)
     187        print(SMOLPARATOR)
    149188
    150         clis[0].rename_jabber_buddy("-del", newname)
    151         ret = ret & test_send_message(clis[0], clis[1], "rawr")
    152         if ret:
    153             print("Test passed")
    154         else:
    155             print("Test failed")
    156             FAILED = True;
    157 
    158     if FAILED:
    159         print("\ntest1 Log:\n"+clis[0].log)
    160         print("\ntest2 Log:\n"+clis[1].log)
     189    if len(FAILED) != 0:
     190        print("\n" + SEPARATOR + "\nSome test have failed:")
     191        for fail in FAILED:
     192            print(fail)
     193    else:
     194        print("\n" + SEPARATOR + "\nAll tests have passed")
    161195   
    162196if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.