Ejemplo n.º 1
0
 def test_log(self):
     gLog.open("2", 10)
     gLog.print(
         """
                 Expected output:
                     Interleaved output from multiple threads
                     Each thread logs
                         (a) when it is starting
                         (b) multiple lines of output
                         (c) when it has ended
                     There should be NO BLANK LINES in the log and
                     each line should contain output from a single thread.
                     The line '....MIDPOINT...' appears half way through.
                     In the first half lines are about 90 characters long.
                     In the second half lines are twice as long.
         """
     )
     for digit in range(10):
         PrintManyLinesToLog(str(digit)).start()
     sleep(2)
     gLog.flush()
     gLog.print("...................... MIDPOINT.........................")
     for digit in range(10):
         PrintManyLinesToLog(str(digit) + str(digit) + str(digit)).start()
     sleep(5)
     gLog.close()
     raise Exception("EXCEPTION EXPECTED: Check correctness of output in file log_test.txt")
Ejemplo n.º 2
0
    def test_assertions(self):
        gLog.open("1")
        self.assertRaises(AssertionError, gLog.print, 3)  # trying to print a non string
        gLog.close()

        self.assertRaises(AssertionError, gLog.open, 1, 40)  # name is not a string
        self.assertRaises(AssertionError, gLog.open, "a", "cat")  # flushFrequency is not an integer
        self.assertRaises(AssertionError, gLog.open, "a", 2.5)  # flushFrequency is not an integer
        self.assertRaises(AssertionError, gLog.open, "a", -2)  # flushFrequency is < 0
Ejemplo n.º 3
0
#########################################################################################
########################### Unit Testing ################################################
#########################################################################################


from Log import gLog
from StartAndKill import StartAndKill


def raw_input(st):
    return input(st)

if __name__ == "__main__":
    gLog.open('1', 5)
    sak = StartAndKill(mode='testing')
    sak.start("simulator")
    sak.start("controller", ip = "127.0.0.1", port = "1234", trace = "yes")
    sak.start("ut4", ip = "127.0.0.1", port = "1234")
    sak.start("RBLDisplay", ip = "127.0.0.1", port = "1235")
    sak.start("adminthrottle", ip = "127.0.0.1", port = "1235", layoutFile = "layout.xml", logs = "no")
    print("\n")
    sak.start("controller", trace = "no")
    sak.start("ut4", port = "1236")
    sak.start("RBLDisplay", ip = "127.1.1.1")
    sak.start("adminthrottle", ip = "127.0.0.1", port = "1234", logs = "yes")
    print("\n")
    sak.kill("sim")
    sak.kill("cont")
    sak.kill("ut4")
    sak.kill("RBL")
    sak.kill("admin")
Ejemplo n.º 4
0
 def run(self):
     gLog.open(str(self.number))
     print("Running process {0}".format(self.number)); sys.stdout.flush()
     gLog.print("Running process {0}".format(self.number))
     TheGui(self.number, self.quSend, self.quRead).mainloop()
Ejemplo n.º 5
0
        message = self.inputField.getText()
        self.quSend.put(message)                  # send

    def printMessage(self, message):
        self.outputArea.appendText(message + "\n")
       

class QuReaderThread(Thread):
    
    def __init__(self, myGui, myQu):
        print("Initializing a queue reader"); sys.stdout.flush()
        gLog.print("Initializing a queue reader")
        Thread.__init__(self)
        self.myGui = myGui
        self.myQu = myQu

    def run(self):
        while True:
            message = self.myQu.get()
            self.myGui.printMessage(message)

if __name__ == "__main__":
    gLog.open("main")
    qu1 = Queue()
    qu2 = Queue()
    GuiProcess(1, qu1, qu2).start()
    GuiProcess(2, qu2, qu1).start()
    


Ejemplo n.º 6
0
from GuiThrottle import GuiThrottleProcess
from Log import gLog
from MsgHandler import *
from StartAndKill import StartAndKill
from Throttle import Throttle
from time import sleep


def raw_input(st):
    return input(st)

###################################################

if __name__ == "__main__":
    gLog.open()

    name = "Bill"

    #  Start the simulator and controller
    sak = StartAndKill()
    sak.start("simulator")
    sak.start("controller")

    # Create the communication resources for 5 users
    comRes = CommunicationResources(name = 'gui thr test', host = 'localhost', port = 1235, numberOfPackages = 5)

    # Create a throttle to read the layout file
    throttle = Throttle(name = name, comPkg = comRes.getNextPackage())
    gLog.print("Main: read layout file")
    msg = throttle.readLayout("../../runSoftware/Layout.xml")
    sleep(2)
Ejemplo n.º 7
0
            self.sk.send(LocoDirfMsg(slot=5, direction=kBackward, lights=kOn, horn=kOff, bell=kOn))
            time.sleep(0.2)
            self.sk.send(LocoDirfMsg(slot=5, direction=kForward, lights=kOff, horn=kOff, bell=kOff))
            time.sleep(0.2)
        raw_input("\nPress enter to kill RailroadBig and Controller and stop thread BlinkLightsViaController \n")
        sak.kill("simulator")
        sak.kill("controller")
        print("Ending thread TestBlinkLightsViaController\n")


############################################################################
#      RUN FROM WINDOWS EXPLORER
############################################################################

if __name__ == "__main__":
    gLog.open("1")
    while True:
        print("\n\n\n")
        print("1. Test send")
        print("2. Test receive")
        print("3. Test talking to controller")
        print("Q. Quit")
        option = raw_input(">>> ")
        print("\n\n\n")
        if option == "q":
            break
        elif option == "1":
            gLog.print("testSend()\n")
            testSend()
        elif option == "2":
            gLog.print("testReceive()\n")