def test_load_single(self): loaded = [] for item in asset.load('asset:test/data/file1.nl'): loaded.append(item) self.assertEqual(len(loaded), 1) self.assertEqual(loaded[0].package, 'asset') self.assertEqual(loaded[0].name, 'test/data/file1.nl') with self.assertRaises(asset.NoSuchAsset) as cm: asset.load('asset:no-such-file.ext').peek()
def test_filename(self): # NOTE: this requires that `pxml` was installed as a zipped egg, and # `globre` as an UNzipped egg, i.e.: # easy_install --zip-ok pxml # easy_install --always-unzip globre for item in asset.load('globre:__init__.py'): self.assertIsNotNone(item.filename) for item in asset.load('pxml:__init__.py'): self.assertIsNone(item.filename)
def test_load_group_read(self): self.assertEqual( asset.load('asset:test/data/file1.nl').read(), b'line-1\nline-2') self.assertEqual( asset.load('asset:test/data/file2.nl').read(), b'line-3\n') self.assertEqual( asset.load('asset:test/data/*.nl').read(), b'line-1\nline-2line-3\n') ag = asset.load('asset:test/data/*.nl') self.assertEqual(ag.readline(), b'line-1\n') self.assertEqual(ag.readline(), b'line-2') self.assertEqual(ag.readline(), b'line-3\n')
def test_load_multi(self): self.assertEqual(len(asset.load('asset:test/data/file1.nl')), 1) self.assertEqual( [str(ast) for ast in asset.load('asset:test/data/file1.nl')], ['asset:test/data/file1.nl']) self.assertEqual( [str(ast) for ast in asset.load('asset:test/data/**.nl')], [ 'asset:test/data/file1.nl', 'asset:test/data/file2.nl', 'asset:test/data/subdir/subfile1.nl' ]) self.assertEqual( [ast.read() for ast in asset.load('asset:test/data/**.nl')], [b'line-1\nline-2', b'line-3\n', b'sub-file-line-1\n'])
def test_streamIteration(self): stream = asset.load('asset:test/data/file**').stream() self.assertEqual(stream.readline(), b'line-1\n') self.assertEqual(stream.readline(), b'line-2') self.assertEqual(stream.readline(), b'line-3\n') self.assertEqual(stream.readline(), b'') stream = asset.load('asset:test/data/file**').stream() chk = list(reversed([ b'line-1\n', b'line-2', b'line-3\n', ])) for line in stream: self.assertEqual(line, chk.pop())
def test_readWithSize(self): self.assertEqual( asset.load('asset:test/data/file**').stream().read(), b'line-1\nline-2line-3\n') self.assertEqual( asset.load('asset:test/data/file**').stream().read(1024), b'line-1\nline-2line-3\n') stream = asset.load('asset:test/data/file**').stream() self.assertEqual(stream.read(5), b'line-') self.assertEqual(stream.read(5), b'1\nlin') self.assertEqual(stream.read(5), b'e-2li') self.assertEqual(stream.read(3), b'ne-') self.assertEqual(stream.read(3), b'3\n') self.assertEqual(stream.read(3), b'')
def test_load_multi(self): self.assertEqual(len(asset.load('asset:test/data/file1.nl')), 1) self.assertEqual( [str(ast) for ast in asset.load('asset:test/data/file1.nl')], ['asset:test/data/file1.nl']) self.assertEqual( [str(ast) for ast in asset.load('asset:test/data/**.nl')], ['asset:test/data/file1.nl', 'asset:test/data/file2.nl', 'asset:test/data/subdir/subfile1.nl']) self.assertEqual( [ast.read() for ast in asset.load('asset:test/data/**.nl')], [b'line-1\nline-2', b'line-3\n', b'sub-file-line-1\n'])
def __load_config(self): """Returns the configuration as specified in the project's config.ini file. The returned object is a configparser.Parser object which is essentially an OrderedDict() with subsections with for each major section in the .ini file. """ # initialize a configuration parser # the configparser.ExtendedInterpolation option allows the # values of one section of the .ini file to be referenced in other # sections. ini_parser = configparser.ConfigParser( interpolation=configparser.ExtendedInterpolation()) # asset.load just gives us a reference to the config.ini file # which is situtated in this program's directory ini_filename = asset.load("Yaemrs:config/config.ini").filename # load the parser with data from the config file ini_parser.read(ini_filename) # this part fixes the problem when the directories in the # config.ini file are preceded with a ~ (shortcut for home) # it calls __expand_path to expand the ~ to the value of the # home directory of user. # -- limitation = assumes a depth of 2 to the dictionary for key in ini_parser: for subkey in ini_parser[key]: subval = ini_parser[key][subkey] ini_parser[key][subkey] = str(self.__expand_path(subval)) return ini_parser
def loader(uri): if uri.startswith('file://'): # todo: what about closing this file descriptor?... let the gc do it? return open(uri[len('file://'):], 'rb') if assetspec_cre.match(uri): return asset.load(uri).peek() raise UnsupportedError('no asset loader for URI %r' % (uri, ))
def test_filename_egg(self): # NOTE: this requires that `pxml` be installed as a zipped egg, i.e.: # easy_install --zip-ok pxml if not isEgg('pxml'): raise unittest.SkipTest('package "pxml" must be installed as a zipped egg') for item in asset.load('pxml:__init__.py'): self.assertIsNone(item.filename)
def test_filename_noegg(self): # NOTE: this requires that `globre` be installed as an UNzipped pkg, i.e.: # easy_install --always-unzip globre if isEgg('globre'): raise unittest.SkipTest('package "globre" must not be installed as a zipped egg') for item in asset.load('globre:__init__.py'): self.assertIsNotNone(item.filename)
def loader(uri): if uri.startswith('file://'): # todo: what about closing this file descriptor?... let the gc do it? return open(uri[len('file://') : ], 'rb') if assetspec_cre.match(uri): return asset.load(uri).peek() raise UnsupportedError('no asset loader for URI %r' % (uri,))
def test_chunks_bytes(self): src = six.BytesIO('foo-1\nbar\nzig') self.assertEqual( list(asset.chunks(src, 3)), ['foo', '-1\n', 'bar', '\nzi', 'g']) self.assertEqual( list(asset.chunks(asset.load('asset:test/data/file1.nl').stream(), 3)), ['lin', 'e-1', '\nli', 'ne-', '2']) self.assertEqual( list(asset.chunks(asset.load('asset:test/data/file**').stream(), 3)), ['lin', 'e-1', '\nli', 'ne-', '2li', 'ne-', '3\n']) self.assertEqual( list(asset.load('asset:test/data/file1.nl').chunks(3)), ['lin', 'e-1', '\nli', 'ne-', '2']) self.assertEqual( list(asset.load('asset:test/data/file**').chunks(3)), ['lin', 'e-1', '\nli', 'ne-', '2li', 'ne-', '3\n'])
def test_filename_egg(self): # NOTE: this requires that `pxml` be installed as a zipped egg, i.e.: # easy_install --zip-ok pxml if not isEgg('pxml'): raise unittest.SkipTest( 'package "pxml" must be installed as a zipped egg') for item in asset.load('pxml:__init__.py'): self.assertIsNone(item.filename)
def test_chunks_lines(self): src = six.BytesIO('foo-1\nbar\nzig') self.assertEqual( list(asset.chunks(src, 'lines')), ['foo-1\n', 'bar\n', 'zig']) self.assertEqual( list(asset.chunks(asset.load('asset:test/data/file1.nl').stream(), 'lines')), ['line-1\n', 'line-2']) self.assertEqual( list(asset.chunks(asset.load('asset:test/data/file**').stream(), 'lines')), ['line-1\n', 'line-2', 'line-3\n']) self.assertEqual( list(asset.load('asset:test/data/file1.nl').chunks('lines')), ['line-1\n', 'line-2']) self.assertEqual( list(asset.load('asset:test/data/file**').chunks('lines')), ['line-1\n', 'line-2', 'line-3\n'])
def test_csv(self): import csv lines = [line.decode() for line in asset.load('asset:test/data.csv').stream()] reader = csv.reader(lines) self.assertEqual(six.next(reader), ['a', 'b', 'c']) self.assertEqual(six.next(reader), ['1', '2', '3']) with self.assertRaises(StopIteration): six.next(reader)
def test_filename_noegg(self): # NOTE: this requires that `globre` be installed as an UNzipped pkg, i.e.: # easy_install --always-unzip globre if isEgg('globre'): raise unittest.SkipTest( 'package "globre" must not be installed as a zipped egg') for item in asset.load('globre:__init__.py'): self.assertIsNotNone(item.filename)
def test_chunks_bytes(self): src = six.BytesIO('foo-1\nbar\nzig') self.assertEqual(list(asset.chunks(src, 3)), ['foo', '-1\n', 'bar', '\nzi', 'g']) self.assertEqual( list( asset.chunks( asset.load('asset:test/data/file1.nl').stream(), 3)), ['lin', 'e-1', '\nli', 'ne-', '2']) self.assertEqual( list(asset.chunks( asset.load('asset:test/data/file**').stream(), 3)), ['lin', 'e-1', '\nli', 'ne-', '2li', 'ne-', '3\n']) self.assertEqual( list(asset.load('asset:test/data/file1.nl').chunks(3)), ['lin', 'e-1', '\nli', 'ne-', '2']) self.assertEqual(list(asset.load('asset:test/data/file**').chunks(3)), ['lin', 'e-1', '\nli', 'ne-', '2li', 'ne-', '3\n'])
def test_csv(self): import csv lines = [ line.decode() for line in asset.load('asset:test/data.csv').stream() ] reader = csv.reader(lines) self.assertEqual(six.next(reader), ['a', 'b', 'c']) self.assertEqual(six.next(reader), ['1', '2', '3']) with self.assertRaises(StopIteration): six.next(reader)
def test_chunks_lines(self): src = six.BytesIO('foo-1\nbar\nzig') self.assertEqual(list(asset.chunks(src, 'lines')), ['foo-1\n', 'bar\n', 'zig']) self.assertEqual( list( asset.chunks( asset.load('asset:test/data/file1.nl').stream(), 'lines')), ['line-1\n', 'line-2']) self.assertEqual( list( asset.chunks( asset.load('asset:test/data/file**').stream(), 'lines')), ['line-1\n', 'line-2', 'line-3\n']) self.assertEqual( list(asset.load('asset:test/data/file1.nl').chunks('lines')), ['line-1\n', 'line-2']) self.assertEqual( list(asset.load('asset:test/data/file**').chunks('lines')), ['line-1\n', 'line-2', 'line-3\n'])
def loadExtension(self, spec): log.debug('loading type registry extensions from: %r', spec) try: sym = asset.symbol(spec) return sym(self) except (ImportError, AttributeError): pass try: return self.loadExtensionString(asset.load(spec).read(), source=spec) except (ImportError, AttributeError, ValueError): pass return self.loadExtensionString(spec)
def payload(self, request): files = [] for f in self.files: a = asset.load(f) fd = open(a.filename, "rb") fname = os.path.basename(a.filename) files.append({"filename": fname, "body": base64.b64encode(fd.read())}) return { "group": self.name, "executor": self.executor, "options": self.options, "environ": self.environ, "files": files, }
def onSense(self, topic, event, *args, **kw): if topic == 'motion': self.motion = event == 'started' self.app.shellexec(self.getConfig(topic + '.' + event + '.exec', None)) evt = topic + '.' + event + '.play' if evt not in self.sounds: # todo: support defaulting to ``raspi_door:res/audio/doorbell.ogg``... play = self.getConfig(evt, DEFAULT_EVENT_ACTION.get(evt, None)) if play and isAssetSpec.match(play): play = six.BytesIO(asset.load(play).read()) if play: self.sounds[evt] = pygame.mixer.Sound(play) if evt in self.sounds: self.sounds[evt].play()
def include_config(instring, loc, token): url = None file = None required = False if token[0] == 'required': required = True final_tokens = token[1:] else: final_tokens = token if len(final_tokens) == 1: # include "test" value = final_tokens[0].value if isinstance( final_tokens[0], ConfigQuotedString) else final_tokens[0] if value.startswith("http://") or value.startswith( "https://") or value.startswith("file://"): url = value else: file = value elif len(final_tokens) == 2: # include url("test") or file("test") value = final_tokens[1].value if isinstance( final_tokens[1], ConfigQuotedString) else final_tokens[1] if final_tokens[0] == 'url': url = value elif final_tokens[0] == 'package': file = asset.load(value).filename else: file = value if url is not None: logger.debug('Loading config from url %s', url) obj = ConfigFactory.parse_URL(url, resolve=False, required=required, unresolved_value=NO_SUBSTITUTION) elif file is not None: path = file if basedir is None else os.path.join(basedir, file) logger.debug('Loading config from file %s', path) obj = ConfigFactory.parse_file( path, resolve=False, required=required, unresolved_value=NO_SUBSTITUTION) else: raise ConfigException( 'No file or URL specified at: {loc}: {instring}', loc=loc, instring=instring) return ConfigInclude(obj if isinstance(obj, list) else obj.items())
def payload(self, request): files = [] for f in self.files: a = asset.load(f) fd = open(a.filename, 'rb') fname = os.path.basename(a.filename) files.append({ 'filename': fname, 'body': base64.b64encode(fd.read()) }) return { 'group': self.name, 'executor': self.executor, 'options': self.options, 'environ': self.environ, 'files': files }
def test_load_example(self): out = ET.Element('nodes') for item in asset.load('asset:test/data/**.nl'): cur = ET.SubElement(out, 'node', name=item.name) cur.text = item.read().decode() out = ET.tostring(out) chk = b'''\ <nodes> <node name="test/data/file1.nl">line-1 line-2</node> <node name="test/data/file2.nl">line-3 </node> <node name="test/data/subdir/subfile1.nl">sub-file-line-1 </node> </nodes> ''' self.assertXmlEqual(out, chk)
def capture(self, output, format=None, use_video_port=False, resize=None, splitter_port=0, **options): if format is not 'png': raise ValueError('MockCamera only supports format "png"') data = asset.load('raspi_door:res/mock/camera-%d.png' % (self.current,)).read() ret = None if resize is None: output.write(data) else: buf = six.BytesIO(data) img = pygame.image.load(buf) if True: # if img.get_size() == resize: # output.write(data) # else: img = pygame.transform.scale(img, resize) # todo: submit a patch to pygame to support a 'format=format' param... pygame.image.save(img, output) ret = pygame.image.tostring(img, 'RGB') self.current = ( self.current + 1 ) % 8 return ret
def _asset2templates(self, spec, root, hooks): if root == self.ROOT_AUTO: # todo: this feels "primitive"... it should really extract this # from globre's parse result in some way... if '/**' in spec: root = spec.split('/**', 1)[0] # todo: this is heavily assuming "PKG:RESOURCE" format... ugh. if ':' in root: root = root.split(':', 1)[1] else: root = '' if root and not root.endswith('/'): root += '/' for item in asset.load(spec): if not hooks.asset_filter(item.name): continue ## TODO: handle file encodings!... for fragment in self.fragments(item.name, root, item.read(), hooks): if fragment is not None: yield fragment
def test_asset_simple(self): self.assertEqual( Compiler().compile_asset('lessc:res/test-01.less'), asset.load('lessc:res/test-01.css').read())
def test_file_relative_import(self): self.assertEqual( Compiler().compile_asset('lessc:res/test-02.less'), asset.load('lessc:res/test-02.css').read())
def test_extension_defaulting(self): self.assertEqual( Compiler().compile_asset('lessc:res/test-03.less'), asset.load('lessc:res/test-03.css').read())
def getData(self, name): return asset.load(self.ASSET_DATA_DIR + name).read()
import pkg_resources from .i18n import _ #------------------------------------------------------------------------------ DEFAULT_INFLECT = 0.75 DEFAULT_WEIGHT = 1.0 DEFAULT_CLIPMIN = 0 DEFAULT_CLIPMAX = 1.3 DEFAULT_SKEW = 0 DEFAULT_SPREAD = 1.0 DEFAULT_FACTORS = 'length,charmix,variety,casemix,notword,phrase' #------------------------------------------------------------------------------ common10k = frozenset( asset.load('passwordmeter:res/common.txt').read().decode().split('\n')) #------------------------------------------------------------------------------ def asym(value, target, switch=DEFAULT_INFLECT): if value >= target: return 1 - ((1 - switch) * target / value) return switch * value / target #------------------------------------------------------------------------------ def curve(value, offset=0.05): if value < 0: value = 0 return 1.0 / (offset + value)
def test_count(self): self.assertEqual(asset.load('asset:test/data/file1.nl').count(), 1) self.assertEqual(len(asset.load('asset:test/data/file1.nl')), 1) self.assertEqual(asset.load('asset:test/data/**.nl').count(), 3) self.assertEqual(len(asset.load('asset:test/data/**.nl')), 3)
def test_exists(self): self.assertEqual(asset.load('asset:test/data/file1.nl').exists(), True) self.assertEqual(asset.load('asset:test/data/**.nl').exists(), True) self.assertEqual(asset.load('asset:no-such-file.ext').exists(), False)
def compile_asset(self, spec): return self._compile(spec, asset.load(spec))
def test_file_relative_import(self): self.assertEqual(Compiler().compile_asset('lessc:res/test-02.less'), asset.load('lessc:res/test-02.css').read())
def test_extension_defaulting(self): self.assertEqual(Compiler().compile_asset('lessc:res/test-03.less'), asset.load('lessc:res/test-03.css').read())
def test_mixed_import(self): self.assertEqual( Compiler().compile('@import "lessc:res/test-03.less";'), asset.load('lessc:res/test-03.css').read())
def main(args=None): cli = argparse.ArgumentParser( description = _('Raspberry Pi smart-ish door controller.'), ) cli.add_argument( _('-v'), _('--verbose'), dest='verbose', action='count', default=int(os.environ.get('RASPIDOOR_VERBOSE', DEFAULT_VERBOSE)), help=_('increase logging verbosity (can be specified multiple times)')) cli.add_argument( _('-i'), _('--initialize'), dest='init', default=False, action='store_true', help=_('output a default configuration to STDOUT (typically used with' ' something like' ' "%(prog)s --initialize > ' + DEFAULT_CONFIG + '"' ' and then edited by hand)')) cli.add_argument( _('-c'), _('--config'), metavar=_('FILENAME'), dest='configPath', default=os.environ.get('RASPIDOOR_CONFIG', DEFAULT_CONFIG), help=_('configuration filename (current default: "{}")', '%(default)s')) cli.add_argument( _('-g'), _('--geometry'), metavar=_('GEOMETRY'), dest='geometry', help=_('set the window geometry (either WIDTHxHEIGHT or "fullscreen")')) cli.add_argument( _('-m'), _('--mock'), dest='mock', default=False, action='store_true', help=_('enable mock mode of all services, hardware, software, wetware,' ' mother-in-laws, earth-spheroid gravitational laws, and general' ' parameters of the universe (where possible, of course)')) # cli.add_argument( # _('-r'), _('--remote'), # dest='remote', default=None, action='store', # help=_('specify remote raspi-door-server URL')) options = cli.parse_args(args=args) if options.init: sys.stdout.write(asset.load('raspi_door:res/config.ini').read()) return 0 # TODO: send logging to "log" window?... rootlog = logging.getLogger() rootlog.setLevel(logging.WARNING) rootlog.addHandler(logging.StreamHandler()) # TODO: add a logging formatter... # TODO: configure logging from config?... ==> `[gui] verbose = X` if options.verbose == 1: rootlog.setLevel(logging.INFO) elif options.verbose > 1: rootlog.setLevel(logging.DEBUG) options.configPath = os.path.expanduser(os.path.expandvars(options.configPath)) cfg = options.config = CP.SafeConfigParser() cfg.read(options.configPath) # todo: there has *got* to be a better way of merging options... if cfg.has_section('gui'): if cfg.has_option('gui', 'verbose'): options.verbose = max(options.verbose, cfg.getint('gui', 'verbose')) for opt in cfg.options('gui'): if opt in ('verbose',): continue if not getattr(options, opt, None): val = cfg.get('gui', opt) setattr(options, opt, val) App(options).start()
def include_config(instring, loc, token): url = None file = None required = False if token[0] == 'required': required = True final_tokens = token[1:] else: final_tokens = token if len(final_tokens) == 1: # include "test" value = final_tokens[0].value if isinstance(final_tokens[0], ConfigQuotedString) else final_tokens[0] if value.startswith("http://") or value.startswith("https://") or value.startswith("file://"): url = value else: file = value elif len(final_tokens) == 2: # include url("test") or file("test") value = final_tokens[1].value if isinstance(final_tokens[1], ConfigQuotedString) else final_tokens[1] if final_tokens[0] == 'url': url = value elif final_tokens[0] == 'package': file = asset.load(value).filename else: file = value if url is not None: logger.debug('Loading config from url %s', url) obj = ConfigFactory.parse_URL( url, resolve=False, required=required, unresolved_value=NO_SUBSTITUTION ) elif file is not None: path = file if basedir is None else os.path.join(basedir, file) def _make_prefix(path): return ('<root>' if path is None else '[%s]' % path).ljust(55).replace('\\', '/') _prefix = _make_prefix(path) def _load(path): _prefix = _make_prefix(path) logger.debug('%s Loading config from file %r', _prefix, path) obj = ConfigFactory.parse_file( path, resolve=False, required=required, unresolved_value=NO_SUBSTITUTION ) logger.debug('%s Result: %s', _prefix, obj) return obj if '*' in path or '?' in path: paths = glob(path, recursive=True) obj = None def _merge(a, b): if a is None or b is None: return a or b elif isinstance(a, ConfigTree) and isinstance(b, ConfigTree): return ConfigTree.merge_configs(a, b) elif isinstance(a, list) and isinstance(b, list): return a + b else: raise ConfigException('Unable to make such include (merging unexpected types: {a} and {b}', a=type(a), b=type(b)) logger.debug('%s Loading following configs: %s', _prefix, paths) for p in paths: obj = _merge(obj, _load(p)) logger.debug('%s Result: %s', _prefix, obj) else: logger.debug('%s Loading single config: %s', _prefix, path) obj = _load(path) else: raise ConfigException('No file or URL specified at: {loc}: {instring}', loc=loc, instring=instring) return ConfigInclude(obj if isinstance(obj, list) else obj.items())
import pkg_resources from .i18n import _ #------------------------------------------------------------------------------ DEFAULT_INFLECT = 0.75 DEFAULT_WEIGHT = 1.0 DEFAULT_CLIPMIN = 0 DEFAULT_CLIPMAX = 1.3 DEFAULT_SKEW = 0 DEFAULT_SPREAD = 1.0 DEFAULT_FACTORS = 'length,charmix,variety,casemix,notword,phrase' #------------------------------------------------------------------------------ common10k = frozenset( asset.load('passwordmeter:res/common.txt').read().decode().split('\n')) #------------------------------------------------------------------------------ def asym(value, target, switch=DEFAULT_INFLECT): if value >= target: return 1 - ( ( 1 - switch ) * target / value ) return switch * value / target #------------------------------------------------------------------------------ def curve(value, offset=0.05): if value < 0: value = 0 return 1.0 / ( offset + value ) #------------------------------------------------------------------------------ def curveavg(values):
(api.Event.LINE_ADD, api.Line('(blank line below)', newnum=3)), (api.Event.LINE_SAME, api.Line('', oldnum=4, newnum=4)), (api.Event.LINE_SAME, api.Line('', oldnum=5, newnum=5)), (api.Event.PROPENTRY_END, propent), (api.Event.ENTRY_END, entry), (api.Event.PATCH_END, patch), ] gen = parsedifflib.parse_svnlook(src, { 'lineNumbers': True, 'propertyUnifiedDiff': True}) chk = [(type, repr(obj)) for type, obj in chk] out = [(type, repr(obj)) for type, obj in gen] self.assertEqual(out, chk) #---------------------------------------------------------------------------- def runtest(self, item): out = colorize(asset.load('parsedifflib:' + item.name).read()) chk = asset.load('parsedifflib:' + item.name + '.output.reference').read() self.assertMultiLineEqual(out, chk) for item in asset.load('parsedifflib:data/*.diff'): safename = re.sub('[^a-zA-Z0-9]+', '_', item.name[5:-5]) def make_test(item): def test_asset(self): self.runtest(item) return test_asset setattr(TestParseDiffLib, 'test_auto_' + safename, make_test(item)) #------------------------------------------------------------------------------ # end of $Id$ #------------------------------------------------------------------------------
def test_raw(self): patch = api.Patch() ent1 = api.Entry( api.Entry.TYPE_CONTENT, 'app/bin/runner', 'app/bin/runner', '2013-05-31 16:43:09 UTC (rev 2958)', '2013-05-31 17:54:22 UTC (rev 2959)', 'Deleted: app/bin/runner') ent2 = api.Entry( api.Entry.TYPE_CONTENT, 'app/setup.py', 'app/setup.py', '2013-05-31 16:43:09 UTC (rev 2958)', '2013-05-31 17:54:22 UTC (rev 2959)', 'Modified: app/setup.py') ent3 = api.Entry( api.Entry.TYPE_CONTENT, 'app/lib/python/MANIFEST', 'app/lib/python/MANIFEST', '2013-05-31 16:43:09 UTC (rev 2958)', '2013-05-31 17:54:22 UTC (rev 2959)', 'Modified: app/lib/python/MANIFEST') ent4 = api.Entry( api.Entry.TYPE_CONTENT, comment = 'Added: app/lib/python/my_app-1.2.3.tar.gz') ent5 = api.Entry( api.Entry.TYPE_PROPERTY, comment = 'Property changes on: app/lib/python/my_app-1.2.3.tar.gz') chk = [ (api.Event.PATCH_START, patch), (api.Event.ENTRY_START, ent1), (api.Event.LINE_LOC, api.Line('@@ -1,4 +0,0 @@')), (api.Event.LINE_DELETE, api.Line('#!/usr/bin/env python')), (api.Event.LINE_DELETE, api.Line('import sys')), (api.Event.LINE_DELETE, api.Line('from app.cli import main')), (api.Event.LINE_DELETE, api.Line('sys.exit(main())')), (api.Event.ENTRY_END, ent1), (api.Event.ENTRY_START, ent2), (api.Event.LINE_LOC, api.Line('@@ -80,7 +80,7 @@')), (api.Event.LINE_SAME, api.Line(' \'Shapely == 1.2.17\',')), (api.Event.LINE_SAME, api.Line('')), (api.Event.LINE_SAME, api.Line(' # message queue')), (api.Event.LINE_DELETE, api.Line(' # \'my-app == x.x.x\',')), (api.Event.LINE_ADD, api.Line(' \'my-app == 1.2.3\',')), (api.Event.LINE_SAME, api.Line(' \'APScheduler == 2.1.0\',')), (api.Event.LINE_SAME, api.Line(' \'kombu == 2.5.10\',')), (api.Event.LINE_SAME, api.Line(' \'amqp == 1.0.11\',')), (api.Event.ENTRY_END, ent2), (api.Event.ENTRY_START, ent3), (api.Event.LINE_LOC, api.Line('@@ -68,4 +68,5 @@')), (api.Event.LINE_SAME, api.Line('https://pypi.python.org/packages/source/G/GeoAlchemy2/GeoAlchemy2-0.2.tar.gz#md5=14d73d09cdc47e3ed92e804883e61218')), (api.Event.LINE_SAME, api.Line('https://pypi.python.org/packages/source/t/transaction/transaction-1.4.1.zip#md5=8db2680bc0f999219861a67b8f335a88')), (api.Event.LINE_SAME, api.Line('https://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.5.tar.gz#md5=facd82faa067e99b80146a0ee2f842f6')), (api.Event.LINE_DELETE, api.Line('https://pypi.python.org/packages/source/p/pyramid/pyramid-1.4.1.tar.gz#md5=044d42f609d567d7db2948a03fffcf7c')), (api.Event.LINE_NOTE, api.Line('\ No newline at end of file')), (api.Event.LINE_ADD, api.Line('https://pypi.python.org/packages/source/p/pyramid/pyramid-1.4.1.tar.gz#md5=044d42f609d567d7db2948a03fffcf7c')), (api.Event.LINE_ADD, api.Line('https://pypi.python.org/packages/source/m/my_app/my_app-1.2.3.tar.gz')), (api.Event.LINE_NOTE, api.Line('\ No newline at end of file')), (api.Event.ENTRY_END, ent3), (api.Event.ENTRY_START, ent4), (api.Event.LINE_NOTE, api.Line('(Binary files differ)')), (api.Event.ENTRY_END, ent4), (api.Event.ENTRY_START, ent5), (api.Event.PROPENTRY, api.PropertyEntry('Added: svn:mime-type', None, 'application/octet-stream')), (api.Event.ENTRY_END, ent5), (api.Event.PATCH_END, patch), ] data = asset.load('parsedifflib:data/svnlook.diff').read() gen = parsedifflib.parse_svnlook(data) chk = [(type, repr(obj)) for type, obj in chk] out = [(type, repr(obj)) for type, obj in gen] self.assertEqual(out, chk)
def test_asset_simple(self): self.assertEqual(Compiler().compile_asset('lessc:res/test-01.less'), asset.load('lessc:res/test-01.css').read())
OPIYUM_CERTCHAIN = 'secpass:res/opiyum-cert-chain.pem' OPIYUM_URL = 'https://www.opiyum.net/secpass/' #------------------------------------------------------------------------------ def addConfigCommand(commands, common): subcli = commands.add_parser( _('config'), parents=[common], help=_('create and/or manage secpass/secnote configuration file')) subcli.set_defaults(call=cmd_config) #------------------------------------------------------------------------------ # TODO: make these 'tokens' that are then referenced by the 'en-US' locale... helpmsg = dict() for ast in asset.load('secpass:res/help/**.rst'): helpmsg[ast.name[9:-4]] = ast.read() #------------------------------------------------------------------------------ class ConfigManager(object): #---------------------------------------------------------------------------- def __init__(self, options): self.options = options self.config = None self._genv = None self._crtpem = None #---------------------------------------------------------------------------- def run(self): self.config = engine.Config(self.options.config)
def runtest(self, item): out = colorize(asset.load('parsedifflib:' + item.name).read()) chk = asset.load('parsedifflib:' + item.name + '.output.reference').read() self.assertMultiLineEqual(out, chk)