Ejemplo n.º 1
0
 def __run__(self):
     """
     Run the commands specified as
     CLI arguments, it will use __run_plot_commands__
     property intensively.
     """
     if self.command == "create_parking_lot":
         clear_tmp_file()
         # we are creating a parknig log manager
         # here which is used to do all the
         # combinotirc operations on parking_plot.
         if self.pickle:
             self.pickle.manager.empty = self.pickle.manager.empty.union(set([x for x in range(
                 self.pickle.manager.size + 1, self.pickle.manager.size + 1 + self.operation_value)]))  # NOQA
             self.pickle.manager.size = self.pickle.manager.size + int(self.operation_value)
             print("Created a parking lot with %s slots" %
                   len(self.pickle.manager.empty))
             self.__dump_data_to_pickle__
         else:
             self.pikcle = None
             self.manager = ParkingLotManager(**{'size': int(self.operation_value),
                                                 'empty': set(range(1,
                                                                    int(self.operation_value) + 1)),  # NOQA
                                                 'consumed': set()})  # NOQA
             print("Created a parking lot with %s slots" %
                   (int(self.operation_value)))
             self.__dump_data_to_pickle__
     elif self.pickle is not None:
         # if pickle is not None
         # it means we have already creaed
         # a parking_plot and it is stored
         # as a pickle file in tmp directory.
         self.__run_plot_commands_on_pickle__
     else:
         self.__run_plot_commands__
Ejemplo n.º 2
0
 def __run_plot_commands_on_pickle__(self):
     """
     Property used to run the commands
     specified as postional arguments,
     when there is a already created Parking lot
     """
     if self.command == "park":
         if len(self.extra_arguments) >= 2:
             # if colour is specified with the vehicle
             # registration number
             self.pickle.manager.allot_one_plot(
                 self.operation_value, self.extra_arguments[1])
         else:
             # if colour is not specified with the vehicle
             # registration number
             self.pickle.manager.allot_one_plot(self.operation_value, None)
         self.__dump_data_to_pickle__
     elif self.command == "leave":
         self.pickle.manager.clear_one_plot(self.operation_value)
         self.__dump_data_to_pickle__
     elif self.command == "status":
         self.pickle.manager.status()
     elif self.command == "registration_numbers_for_cars_with_colour":
         self.pickle.manager.get_registration_number_of_vehicle_with_colour(
             self.operation_value)
     elif self.command == "slot_numbers_for_cars_with_colour":
         self.pickle.manager.get_slot_number_for_cars_with_colour(
             self.operation_value)
     elif self.command == "slot_number_for_registration_number":
         self.pickle.manager.get_slot_number_for_registration_number(
             self.operation_value)
     elif self.command == "exit":
         clear_tmp_file()
     else:
         pass
Ejemplo n.º 3
0
 def __exec_file_commands__(self):
     """
     property used to read the
     the file containing the commnads
     """
     with open(self.file_path, 'r') as command_file:
         for line in command_file:
             args = self.parser.parse_args(shlex.split(line))
             ParkingLot(**vars(args))
         clear_tmp_file()
Ejemplo n.º 4
0
 def setup(self):
     """
     method executed before any test class
     method are executed.
     """
     self.plot_size = 5
     clear_tmp_file()
     self.parking_lot = ParkingLot(**{
         "comand": "create_parking_lot",
         "extra_arguments": [
             self.plot_size,
         ]
     })
Ejemplo n.º 5
0
 def __run_plot_commands__(self):
     """
     Property used to run those command
     which are executed after creating a
     parking lot, Initially there is no
     pickle object available which was used
     to store the parking_lot instance
     """
     if self.command == "park":
         self.__check_manager_existance__
         if len(self.extra_arguments) >= 2:
             # if colour is specified with the vehicle
             # registration number
             self.pickle.manager.allot_one_plot(
                 self.operation_value, self.extra_arguments[1])
         else:
             # if colour is not specified with the vehicle
             # registration number
             self.pickle.manager.allot_one_plot(self.operation_value, None)
         self.__dump_data_to_pickle__
     elif self.command == "leave":
         self.__check_manager_existance__
         self.manager.clear_one_plot(self.operation_value)
         self.__dump_data_to_pickle__
     elif self.command == "status":
         self.__check_manager_existance__
         self.manager.status()
     elif self.command == "registration_numbers_for_cars_with_colour":
         self.__check_manager_existance__
         self.manager.get_registration_number_of_vehicle_with_colour(
             self.operation_value)
     elif self.command == "slot_numbers_for_cars_with_colour":
         self.__check_manager_existance__
         self.manager.get_slot_number_for_cars_with_colour(
             self.operation_value)
     elif self.command == "slot_number_for_registration_number":
         self.__check_manager_existance__
         self.manager.get_slot_number_for_registration_number(
             self.operation_value)
     elif self.command == "exit":
         clear_tmp_file()
     else:
         pass
Ejemplo n.º 6
0
 def tearDown(self):
     """
     method run after all the test cases are completed
     """
     clear_tmp_file()