Beispiel #1
0
 def __init__(self, lock, user_text):
     Thread.__init__(self)
     # Initialises a thread. Stores the callback function.
     self.lock = lock
     self.sem_ready = Semaphore(0)
     self.lock.acquire()
     self.user_input = TextInput(user_text)
Beispiel #2
0
def test_valid_regex():
    with mock.patch('builtins.input', return_value="54.23"):
        tui = TextInput(text="An example question",
                        default="0.00",
                        regex="[0-9]+\\.[0-9]{2}")
        assert (tui.request_input() == UserInput.SUCCESS)
        assert (tui.get_answer() == "54.23")
Beispiel #3
0
class WaitingForInput(Thread):
    def __init__(self, lock, user_text):
        Thread.__init__(self)
        # Initialises a thread. Stores the callback function.
        self.lock = lock
        self.sem_ready = Semaphore(0)
        self.lock.acquire()
        self.user_input = TextInput(user_text)

    def run(self):
        self.sem_ready.release()
        self.user_input.request_input()
        self.lock.release()

    def wait_till_up(self):
        self.sem_ready.acquire()
Beispiel #4
0
    def add_task(self):
        tui_name = TextInput("What is the name of your task?")
        tui_frequency = TextInput("How often do you need to do this?")
        tui_ask = MultipleInput([tui_name, tui_frequency], self._add)

        tui_ask.request_inputs()
Beispiel #5
0
 def __init__(self, **kwargs):
     kwargs["regex"] = "[0-3][0-9]\/[0-1][0-9]\/20[1-3][0-9]"
     TextInput.__init__(self, **kwargs)
Beispiel #6
0
 def add_option(self):
     tui_name = TextInput("Name the new option:")
     tui_short_name = TextInput("Provide the short name:")
     tui_help_text = TextInput("Add help text")
     tui_ask = MultipleInput([tui_name,tui_short_name,tui_help_text],self._add)
     tui_ask.request_inputs()
Beispiel #7
0
            for service in services:
                loc = service.destination.location
                dest_name = loc[0].locationName
                return_string += "-----------------------------\n"
                return_string += service["std"] + " to " + dest_name + "\n"

                if service.etd == "On time":
                    return_string += "This service is on time\n"
                elif service.etd == "Delayed":
                    return_string += "This service is delayed\n"
                    details = self.client.service.GetServiceDetails(
                        service.serviceID, _soapheaders=self.token)
                else:
                    return_string += "Estimated arrival " + service.etd + "\n"

                if service.isCancelled != None:
                    return_string += "This service is cancelled\n"
        else:
            return_string += f"There are no services to/from {self.station_code} in the next {self.duration}"
        return_string += "-----------------------------\n"
        return return_string


if __name__ == "__main__":
    tui = TextInput("Which station would you like to see the departures of? "
                    "Please enter the 3 character station code.")
    rc = tui.request_input()
    if rc == UserInput.SUCCESS:
        rail_client = RailInfo(tui.answer)
        print(rail_client.live_departure_string())
Beispiel #8
0
def test_input():
    with mock.patch('builtins.input', return_value="correct_value"):
        tui = TextInput("An example question")
        assert (tui.request_input() == UserInput.SUCCESS)
        assert (tui.get_answer() == "correct_value")
Beispiel #9
0
def test_invalid_regex():
    with mock.patch('builtins.input', return_value="invalid_text"):
        tui = TextInput(text="An example question",
                        default="0.00",
                        regex="[0-9]+\\.[0-9]{2}")
        assert (tui._ask() == UserInput.INVALID_INPUT)
Beispiel #10
0
def test_help():
    with mock.patch('builtins.input', return_value="\\h"):
        tui = TextInput("An example question")
        assert (tui._ask() == UserInput.HELP)