def test_exception_known(self): names = dict(importer.INSTALL_NAMES, nonexistent='pynone') with patch.patch(importer, 'INSTALL_NAMES', names): # Patch in a known, "fake" module. importer.INSTALL_NAMES['nonexistent'] = 'pynone' with self.assertRaises(ImportError) as cm: import_symbol('nonexistent') e = str(cm.exception) self.assertTrue('pip install pynone' in e) self.assertTrue('You are missing module \'nonexistent\'' in e)
def test_existence(self): failed = [] for cl in alias_lists.BUILTIN_ALIASES.values(): try: importer.import_symbol(cl) except: failed.append(cl) if failed: print('Failed', *failed, sep='\n') self.assertFalse(failed)
def test_existence(self): failed = [] for name, cl in aliases.BUILTIN_ALIASES.items(): try: importer.import_symbol(cl) except: failed.append(name) if failed != NOT_ANIMATIONS: log.printer('Failed', *failed, sep='\n') self.assertTrue(False)
def test_existence(self): failed = [] for cl in alias_lists.BUILTIN_ALIASES.values(): try: importer.import_symbol(cl) except: failed.append(cl) if failed: log.printer('Failed', *failed, sep='\n') self.assertFalse(failed)
def test_exception_known(self): try: # Patch in a known, "fake" module. importer.INSTALL_NAMES['nonexistent'] = 'pynone' with self.assertRaises(ImportError) as cm: import_symbol('nonexistent') e = str(cm.exception) self.assertTrue('pip install pynone' in e) self.assertTrue('No module named \'nonexistent\'' in e) finally: importer.INSTALL_NAMES.pop('nonexistent')
def test_not_needed(self): just_one = '' failed, not_equal = [], [] for alias, path in aliases.BUILTIN_ALIASES.items(): if alias in NOT_ANIMATIONS or (just_one and alias != just_one): continue python_path = '.'.join(path.split('.', 2)[:2]) expected = importer.import_symbol(path) try: actual = importer.import_symbol(alias, python_path=python_path) except: failed.append(alias) if just_one: raise else: if actual is not expected: not_equal.append(alias) self.assertEqual([sorted(failed), sorted(not_equal)], [sorted(FAILED), sorted(NOT_EQUAL)])
def test_failed_double(self): with self.assertRaises(ImportError): import_symbol('math12.log') with self.assertRaises(ImportError): import_symbol('math.log12') with self.assertRaises(ImportError): import_symbol('bibliopixel.log12')
def main(anim_cls, fps, json_params, sim, num, verify, args): params = {} if json_params: params = json.loads(json_params) if anim_cls.startswith('BPAS'): anim_cls = anim_cls.replace('BPAS', 'BiblioPixelAnimations.strip') if sim: driver = SimPixel(num=144) num = 0 else: filename = './POV_Files/' + anim_cls.split('.')[::-1][0] + '.' + str(fps).zfill(3) cfg_filename = './POV_Files/' + anim_cls.split('.')[::-1][0] + '_' + str(fps) + '.json' if args: with open(cfg_filename, 'w') as cfg_json: json.dump(args, cfg_json) driver = POVGen(num=144, filename=filename) fps = None layout = Strip(driver) anim_obj = import_symbol(anim_cls) anim = anim_obj(layout, **params) anim.run(fps=fps, max_steps=num) driver.cleanup() if not sim and verify: with open(filename, 'rb') as data: data = list(bytearray(data.read())) color_list = [tuple(data[x:x + 3]) for x in range(0, len(data), 3)] rows = [color_list[x:x + NUM] for x in range(0, len(color_list), NUM)] row_count = len(rows) flat = [c for row in rows for c in row] img = Image.new('RGB', (NUM, row_count)) img.putdata(flat) img.save(filename + '.png') fl_img = Image.new('RGB', (NUM, 2)) fl_img.putdata(rows[-1] + rows[0]) fl_img.save(filename + '_fl.png')
def __init__(self, hardware_id, baudrate): self.hardware_id = hardware_id self.baudrate = baudrate self.serial = import_symbol('serial') self.list_ports = import_symbol('serial.tools.list_ports')
def test_empty(self): import_symbol('')
def test_empty(self): with self.assertRaises(ValueError): import_symbol('')
def test_exception_unknown(self): with self.assertRaises(ImportError) as cm: import_symbol('nonexistent') e = str(cm.exception) self.assertFalse('pip install' in e) self.assertEqual("Cannot import symbol 'nonexistent'", e)
def test_aliasing(self): import_symbol('bibliopixel.drivers.SimPixel.SimPixel')
def test_exception_unknown(self): with self.assertRaises(ImportError) as cm: import_symbol('nonexistent') e = str(cm.exception) self.assertFalse('pip install' in e) self.assertTrue('No module named \'nonexistent\'' in e)
def test_failed_single(self): with self.assertRaises(ImportError): import_symbol('DOESNT_EXIST')
def test_double(self): import_symbol('math.log') import_module('bibliopixel.util')
def test_longer(self): self.assertEqual( import_module('bibliopixel.project.importer'), importer) self.assertEqual( import_symbol('bibliopixel.project.importer.import_symbol'), import_symbol)
def test_longer(self): self.assertEqual(import_module('bibliopixel.project.importer'), importer) self.assertEqual( import_symbol('bibliopixel.project.importer.import_symbol'), import_symbol)
def test_single(self): import_symbol('math') import_symbol('bibliopixel')