def test___init__no_params(self): # if backplane is not running, start one for all the tests for pid in psutil.pids(): p = psutil.Process(pid) if p.name() == "backplane": break else: self.proc = Popen(['backplane'], stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE) break b = BanyanBase() s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # use the google dns try: s.connect(('8.8.8.8', 1)) back_plane_ip_address = s.getsockname()[0] except: back_plane_ip_address = '127.0.0.1' finally: s.close() b.clean_up() assert b.back_plane_ip_address == back_plane_ip_address
def __init__(self): """ :param player: 0 = player one, 1 = player two """ arcade.View.__init__(self) # initialize the threading.Thread parent threading.Thread.__init__(self) # create a threading lock self.the_lock = threading.Lock() # set this thread as a daemon thread self.daemon = True # create a threading event that will allow the start # and stopping of thread processing self.run_the_thread = threading.Event() # initially allow the thread to run self.run_the_thread = True self.start_backplane() # initialize the python-banyan base class parent. # if the backplane_ip_address is == None, then the local IP # address is used. # The process name is just informational for the Banyan header # printed on the console. # The loop_time the amount of idle time in seconds for the # banyan receive_loop to wait to check for the next message # available in its queue. BanyanBase.__init__(self, back_plane_ip_address=None, process_name=PROCESS_NAME, loop_time=.0001) # add banyan subscription topic self.set_subscriber_topic("ip_inserted") self.set_subscriber_topic("result_connection") self.ip_address = self.back_plane_ip_address # Set the working directory (where we expect to find files) to the same # directory this .py file is in. You can leave this out of your own # code, but it is needed to easily run the examples using "python -m" # as mentioned at the top of this program. file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) # start the second thread self.start() self.background = None
def test_numpy_publish_payload_valid_topic(self): b = BanyanBase(numpy=True) try: b.publish_payload({'payload': 1}, 'b') b.clean_up() assert True except TypeError: b.clean_up() assert False
def test_publish_payload_invalid_topic(self): b = BanyanBase() try: b.publish_payload({'payload': 1}, ['b']) b.clean_up() assert False except TypeError: b.clean_up() assert True
def test_set_subscriber_topic_valid(self): b = BanyanBase() try: b.set_subscriber_topic('a_topic') b.clean_up() assert True except TypeError: b.clean_up() assert False
def on_click(self): global ip_address_inserted ip_address_inserted = str(self.input_box.text) # initialize the threading.Thread parent threading.Thread.__init__(self) # create a threading lock self.the_lock = threading.Lock() # set this thread as a daemon thread self.daemon = True # create a threading event that will allow the start # and stopping of thread processing self.run_the_thread = threading.Event() # initially allow the thread to run self.run_the_thread = True BanyanBase.__init__(self, back_plane_ip_address=ip_address_inserted, process_name=PROCESS_NAME, loop_time=.0001) # add banyan subscription topic self.set_subscriber_topic("ip_inserted") self.set_subscriber_topic("result_connection") # start the second thread self.start() # send message topic = "ip_inserted" payload = {"ip": ip_address_inserted} self.publish_payload(payload, topic) print("Ip Sent")
def test___init__specify_backplane_address(self): b = BanyanBase('111.222.333.444') b.clean_up() assert b.back_plane_ip_address == '111.222.333.444'
def test_clean_up(self): b = BanyanBase() b.clean_up() assert True
def test_incoming_message_processing(self): b = BanyanBase() b.incoming_message_processing({'payload': 1}, 'the_topic') b.clean_up() assert True
def test_init_no_backplane(self): try: BanyanBase() except RuntimeError: assert True
def __init__(self, back_plane_ip_address=None, process_name=None, player=0): """ :param back_plane_ip_address: specify if running across multiple computers :param process_name: the name in the banyan header for this process :param player: 0=coins 1=female sprite """ # Call the parent class initializer title = SCREEN_TITLE + str(player) arcade.Window.__init__(self, SCREEN_WIDTH, SCREEN_HEIGHT, title) # Variables that will hold sprite lists self.all_sprites_list = None self.coin_list = None # Set up the player info self.player_sprite = None # save the player for this instance self.player = player # set score to zero self.score = 0 # Don't show the mouse cursor self.set_mouse_visible(False) # flag to start coin movement - change flag state # by pressing the left mouse button self.go = False # initially turn collision detection off. # pressing the right mouse button will enable it. self.run_collision_detection = False # initialize the threading.Thread parent threading.Thread.__init__(self) # create a threading lock self.the_lock = threading.Lock() # set this thread as a daemon thread self.daemon = True # create a threading event that will allow the start # and stopping of thread processing self.run_the_thread = threading.Event() # initially allow the thread to run self.run_the_thread = True # if not backplane address is specified, try to start # the backplane. If an address is specified, the user # is trying to connect to an already running backplane if not back_plane_ip_address: self.start_backplane() # initialize the python-banyan base class parent. # if the backplane_ip_address is == None, then the local IP # address is used. # The process name is just informational for the Banyan header # printed on the console. # The loop_time the amount of idle time in seconds for the # banyan receive_loop to wait to check for the next message # available in its queue. BanyanBase.__init__(self, back_plane_ip_address=back_plane_ip_address, process_name=process_name, loop_time=.0001) # add banyan subscription topics self.set_subscriber_topic('enable_coins') self.set_subscriber_topic('enable_collisions') self.set_subscriber_topic('p1_move') self.set_subscriber_topic('update_coins') self.set_subscriber_topic('remove_coin') arcade.set_background_color(arcade.color.AMAZON) # initialize some things self.setup() # start the second thread self.start() # start the arcade loop try: arcade.run() except KeyboardInterrupt: # stop the thread from further processing self.stop_event = False # we are outta here! sys.exit(0)