def setUp(self): all_procs = all_processors() self.playlist = Playlist.from_file(DEFAULT_PLAYLIST, all_procs) self.playlist_manager = PlaylistManager(self.playlist) self.driver = Mock() self.driver = self.new_fake_driver() self.controller = Controller([self.driver], self.playlist_manager)
def test_run_all_processors(): """Run each processor for 30 fake seconds.""" # Note: This test uses a fancy `nosetests` feature to generate # N tests, one for each processor. Mostly this makes reporting # a little nicer when a test fails. More info here: # https://nose.readthedocs.io/en/latest/writing_tests.html#test-generators fake_weights = [0] * 64 num_frames = TEST_FPS * TEST_SECONDS clock_time_per_frame = datetime.timedelta(seconds=1 / TEST_FPS) def run_test(processor_name, cls): with freeze_time('Jan 1, 2001') as fake_time: now = time.time() instance = cls() for i in range(num_frames): context = RenderContext( clock=now, downbeat=0, weights=fake_weights, bpm=120.0, ranged_values=[0] * 4, switches=[False] * 4, ) instance.get_next_frame(context) fake_time.tick(delta=clock_time_per_frame) processors = processor.all_processors() for processor_name, cls in processors.items(): yield run_test, processor_name, cls
def run(): args = get_options() log_level = logging.DEBUG if args.verbose else logging.INFO logging.basicConfig(level=log_level, format=LOG_FORMAT) procs = all_processors() processors_to_test = {} for processor_name in args.processors: if processor_name == 'all': processors_to_test.update(procs) else: processor = procs.get(processor_name) if not processor: logging.error('Processor not found: {}'.format(args.processor)) logging.error('Choices: {}'.format(', '.join( sorted(procs.keys())))) sys.exit(1) processors_to_test[processor_name] = processor results = {} names = sorted(processors_to_test.keys()) for name in names: processor = processors_to_test[name] logger.info('Starting benchmark of {} with {} iterations ...'.format( name, args.iterations)) result = benchmark_processor(name, processor, args.iterations, args.disable_gc) results[name] = result logger.info('Done!') print_results(results)
def __init__(self, drivers, playlist_manager, clocksource=time): """Constructor. Arguments: drivers {floor.driver.Base} -- One or more drivers for show output playlist_manager {floor.playlist.PlaylistManager} -- The show's playlist manager Keyword Arguments: clocksource {function} -- An object that should have `.time()` and `.sleep()` methods (default: {time}) """ assert len(drivers) > 0, 'Must provide 1 or more drivers' self.drivers = drivers assert isinstance( playlist_manager, PlaylistManager), 'playlist_manager is not a PlaylistManager' self.playlist_manager = playlist_manager self.clocksource = clocksource self.frame_start = 0 self.fps = None self.frame_seconds = None self.all_processors = processor.all_processors() self.set_fps(self.DEFAULT_FPS) # Ordered dict of layers to render, bottom-most layer first. self.layers = OrderedDict(( ('playlist', PlaylistRenderLayer(playlist_manager=self.playlist_manager, all_processors=self.all_processors)), ('overlay2', ProcessorRenderLayer()), ('overlay1', ProcessorRenderLayer()), )) self.bpm = None self.downbeat = None self.set_bpm(self.DEFAULT_BPM) # Give outside controllers a chance to fake foot steps on the floor self.synthetic_weights = [0] * 64 # A global "brightness" level, a value between 0.0 and 1.0. self.brightness = 1.0
def test_multiple_drivers_get_weights_are_blended(self): driver1 = Mock() driver1.get_weights = Mock(return_value=[0, 1, 0, 0] * 16) driver2 = Mock() driver2.get_weights = Mock(return_value=[0, 0, 0, 1] * 16) playlist = Playlist.from_file(DEFAULT_PLAYLIST, all_processors()) playlist_manager = PlaylistManager(playlist) controller = Controller([driver1, driver2], playlist_manager) weights = controller.get_weights() expected_weights = [0, 1] * 32 self.assertEqual(expected_weights, weights) controller.square_weight_on(1) expected_weights[0] = 1 weights = controller.get_weights() self.assertEqual(expected_weights, weights) controller.square_weight_off(1) expected_weights[0] = 0 weights = controller.get_weights() self.assertEqual(expected_weights, weights)
def test_all_processors_excludes_base(self): processors = processor.all_processors() self.assert_(BaseProcessor not in list(processors.values()))
def main(): args = get_options() log_level = logging.DEBUG if args.verbose else logging.INFO logging.basicConfig(level=log_level, format=LOG_FORMAT) layout = None if args.floor_config: layout = Layout(config_dir=CONFIG_DIR, config_name=args.floor_config) drivers = [] driver_names = set(args.driver_names or DEFAULT_DRIVERS) for driver_name in driver_names: logger.info('Initializing driver "{}"'.format(driver_name)) driver = load_driver(driver_name, {"config_dir": CONFIG_DIR}) if not driver: logger.error('No driver, exiting.') sys.exit(1) driver.init_layout(layout) logger.info("Using layout: {}".format(driver.layout.name)) drivers.append(driver) if args.playlist and args.processor_name: logger.error('Cannot provide both --playlist and --processor') sys.exit(1) if args.processor_name: try: playlist = Playlist.from_object({'name': args.processor_name}) except ProcessorNotFound: logger.error('Processor "{}" unknown'.format(args.processor_name)) sys.exit(1) elif args.playlist: playlist = Playlist.from_file(args.playlist, all_processors()) else: playlist = Playlist.from_file(DEFAULT_PLAYLIST, all_processors()) playlist_manager = PlaylistManager( playlist, user_playlists_dir=args.user_playlists_dir) show = Controller(drivers, playlist_manager) if args.midi_server_port: midi_manager = MidiManager( port=args.midi_server_port, controller=show, ) if args.midi_mapping: midi_manager.load_default_midi_mapping(MIDI_MAPPING_DIR, args.midi_mapping) midi_manager.run_server() if args.server_port >= 0: run_server(show, port=args.server_port) try: playlist_manager.initialize(all_processors()) show.run_forever() except KeyboardInterrupt: logger.info('Got CTRL-C, quitting.') sys.exit(0) except Exception as e: logger.exception('Unexpected error, aborting: {}'.format(e)) sys.exit(1)
def setUp(self): self.all_procs = all_processors()