def test_only_one_instance_of_the_bus(self): bus_a = Bus.get_or_create('bus_a') bus_b = Bus.get_bus('bus_a') bus_c = Bus.get_or_create('bus_c') bus_d = Bus() assert bus_a is bus_b assert bus_a is not bus_c assert bus_d is not bus_a
def test_timed_signal_with_eventbus(): time = datetime.now() # Create a signal a = TimedSignal('<1,2>', time) b = Bus() def callback(bus, signal=None): eq_(signal.time, time, "Expected same time value!") eq_(signal.neuron, '<1,2>', "Expected same neuron index!") b.subscribe('Fired', callback) # Fire the signal b.publish('Fired', signal=a)
def test_spiking_neuron(): bus = Bus() neuron = SpikingNeuron('<1,1>', bus, efficacy_pause=2, efficacy_duration=4, arp=2, threshold=1.5) presynaptic = SpikingNeuron('<0,1>', bus, efficacy_pause=2, efficacy_duration=4, arp=2, threshold=1.5) presynaptic.attach(neuron) eq_(neuron.compute(), 0, "Expected no preexisting action-potential") test_flag = {'foo': 'bar'} # Create a mock neuron class class MockNeuron: def __init__(self, test_flag): self.test_flag = test_flag def activate(self, bus, signal=None): self.test_flag['foo'] = 'baz' # Attach a mock neuron to 'neuron' to detect firings. neuron.attach(MockNeuron(test_flag)) # Activate the presynaptic neuron presynaptic._fire() presynaptic._fire() presynaptic._fire() for i in range(1, 10): neuron.touch() time.sleep(0.0005) # Allow time for spikes to propagate time.sleep(1) eq_(test_flag['foo'], 'baz', "This flag should be True")
def test_get_bus_name_string(self): bus_x = Bus('bus_x') assert Bus.get_bus_name(bus_x) == 'bus_x'
def test_bus_is_not_specific(self): bus_y = Bus() bus_z = Bus.get_or_create('bus_z') assert bus_y is not bus_z
def setUp(self): self.bus = Bus() self.reset_test()
def __init__(self, limiter_miss_timeout_ms=None): self.bus = Bus() self.limiter_miss_timeout_ms = limiter_miss_timeout_ms if self.limiter_miss_timeout_ms is None: self.limiter_miss_timeout_ms = 500
def __init__(self, config): """ . """ self.bus = Bus() self.bus.subscribe("viewchange", self.handle_viewchange) self.config = config self.octopi_client = OctoPiClient(self.config.api_baseurl, self.config.apikey) self.printer = Printer() self.done = False self.background_image = pygame.image.load(os.path.join(self.config.script_directory, 'assets/background.png')) self.menu_button_image = os.path.join(self.config.script_directory, 'assets/button-menu.png') self.temperature_icon = pygame.image.load( os.path.join(self.config.script_directory, 'assets/icon-temperature.png')) self.menu = MenuView(self.config, self.bus) self.views = dict() self.views["dashboard"] = DashboardView(self.config, self.bus, self.octopi_client, self.printer) self.views["graph"] = GraphView(self.config, self.bus, self.printer) self.views["control"] = ControlView(self.config, self.bus, self.octopi_client) self.views["settings"] = SettingsView(self.config, self.bus) self.active_view = self.views["dashboard"] self.menu_open = False # Status flags self.getstate_ticks = pygame.time.get_ticks() if platform.system() == 'Linux': # Init framebuffer/touchscreen environment variables os.putenv('SDL_VIDEODRIVER', 'fbcon') os.putenv('SDL_FBDEV', '/dev/fb1') os.putenv('SDL_MOUSEDRV', 'TSLIB') os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen') # init pygame and set up screen pygame.init() if platform.system() == 'Windows' or platform.system() == 'Darwin': pygame.mouse.set_visible(True) else: pygame.mouse.set_visible(False) self.screen = pygame.display.set_mode((self.config.width, self.config.height)) pygame.display.set_caption(self.config.caption) # Set font self.fntText = pygame.font.Font(os.path.join(self.config.script_directory, "assets/Roboto-Regular.ttf"), 12) self.fntTextSmall = pygame.font.Font(os.path.join(self.config.script_directory, "assets/Roboto-Regular.ttf"), 10) self.percent_txt = pygame.font.Font(os.path.join(self.config.script_directory, "assets/Roboto-Regular.ttf"), 30) # backlight on off status and control self.bglight_ticks = pygame.time.get_ticks() self.bglight_on = True self.clock = pygame.time.Clock() self.btnMenu = pygbutton.PygButton((260, 0, 40, 40), normal=self.menu_button_image) # I couldnt seem to get at pin 252 for the backlight using the usual method, # but this seems to work if platform.system() == 'Linux': os.system("echo 252 > /sys/class/gpio/export") os.system("echo 'out' > /sys/class/gpio/gpio252/direction") os.system("echo '1' > /sys/class/gpio/gpio252/value") # Init of class done print "OctoPiControlPanel initiated"
return proc # def eventHandler(self, msg): # self.updateLamportClock() # # # if msg.sourceID == self.uid or msg.sourceID == self.uid: # if msg.sourceID == self.uid: # localEvent(msg) # else: # remoteEvent(msg) class TestController(unittest.TestCase): def setUp(self): self.process1 = process(1, 2) self.process2 = process(2, 2) pass def testJava(self): pass def busTester(self, text): print(str(text)) if __name__ == "__main__": bus = Bus() bus.subscribe("tester", busTester) bus.publish("tester", text="Hi there!")
def setUp(self): self.bus = Bus() self.has_run = False self.called_bus = None
from kivy.app import App from kivy.app import Builder from kivy.config import Config from kivy.factory import Factory from context import Context from ui import UiConfigManager from ui import UiFactoryManager from ui import UiPathFinder environ['KIVY_GL_BACKEND'] = "glew" ui_config_manager = UiConfigManager(Config) ui_config_manager.setup() ui_factory_manager = UiFactoryManager(Factory, Bus(), Context()) ui_factory_manager.setup() class ApplicationUi(App): def build(self) -> App: self.title = "PathFinder" Builder.load_file('ui/ui_path_finder.kv') app = UiPathFinder() return app ApplicationUi.run(ApplicationUi())