def test_meta_missing(session): loader = Load(db.app, session) with HTTMock(atom_mock('meta_miss')): loader.run() assert loader.no_of_packages == 1 assert loader.skipped_packages == 1 assert loader.no_of_updates == 0 assert loader.new_packages == 0
def test_get_author(session): loader = Load(db.app, session) for author in author_data: author_value = loader.get_author({'author': author[0]}, "") assert author_value == author[1] author_value = loader.get_author({}, "https://github.com/yuji/atom") assert author_value == "yuji"
def test_license(session): loader = Load(db.app, session) for lic in license_data: model = loader.update_license({'license': lic}) assert License.query.count() == 3 assert License.query.filter_by(name='Apache-2.0').count() == 1 assert License.query.filter_by(name='MIT').count() == 2 assert loader.update_license({}) == None
def test_dependency(session): loader = Load(db.app, session) assert loader.update_dependencies({}) == [] assert loader.update_dependencies({'dependencies': []}) == [] for deps in deps_data: model_list = loader.update_dependencies({'dependencies': deps}) assert len(model_list) == 3 model = Dependency.query.filter_by(name='event-kit').first() assert model.url == 'http://github.com/event-kit'
def test_loader_third_run(session): loader = Load(db.app, session) with HTTMock(atom_mock('update_run_2')): loader.run() package = Package.query.first() assert package.name == "linter" assert package.dependencies.count() == 2 assert Dependency.query.count() == 4 assert package.license.name == "Apache-2.0" assert package.author == "atomlinter" return session
def test_loader_second_run(session): loader = Load(db.app, session) with HTTMock(atom_mock('update_run_1')): loader.run() package = Package.query.first() assert package.name == "linter" assert package.downloads.order_by(Downloads.id.desc()).first().downloads == 145999 assert package.stars == 699 assert package.version.order_by(Version.id.desc()).first().number == "0.9.2" assert package.dependencies.count() == 4 assert Dependency.query.count() == 4 assert package.license.name == "Apache-2.0" return session
def test_loader_first_run(session): clear_data() loader = Load(db.app, session) with HTTMock(atom_mock('first_run')): loader.run() package = Package.query.first() assert package.name == "linter" assert package.downloads.order_by(Downloads.id.desc()).first().downloads == 145375 assert package.stars == 609 assert package.version.first().number == "0.9.0" assert package.dependencies.count() == 3 assert package.license.name == "MIT" return session
def test_loader_first_run(session): clear_data() loader = Load(db.app, session) with HTTMock(atom_mock('first_run')): loader.run() package = Package.query.first() assert package.name == "linter" assert package.downloads.order_by( Downloads.id.desc()).first().downloads == 145375 assert package.stars == 609 assert package.version.first().number == "0.9.0" assert package.dependencies.count() == 3 assert package.license.name == "MIT" return session
def test_loader_second_run(session): loader = Load(db.app, session) with HTTMock(atom_mock('update_run_1')): loader.run() package = Package.query.first() assert package.name == "linter" assert package.downloads.order_by( Downloads.id.desc()).first().downloads == 145999 assert package.stars == 699 assert package.version.order_by( Version.id.desc()).first().number == "0.9.2" assert package.dependencies.count() == 4 assert Dependency.query.count() == 4 assert package.license.name == "Apache-2.0" return session
def _make_context(): ctx = app_instance.test_request_context() ctx.push() from app.packages import models return {"app": app_instance, "db": app.db, "models": models} # init flask migrate migrate = Migrate(app_instance, app.db) manager = Manager(app_instance) manager.add_command("runserver", Server()) manager.add_command("shell", Shell(make_context=_make_context, use_ipython=True)) manager.add_command('db', MigrateCommand) manager.add_command('load', Load(app_instance, app.db.session)) server = Server(host="0.0.0.0", port=9000) @manager.command def sitemap(): app_instance.config["SERVER_NAME"] = "atom.shortcircuits.io" sitemap = Sitemap(app=app_instance) @app_instance.route('/package/<name>') def package(name): pass @app_instance.route("/") def index(): pass
def test_request_exit(session): loader = Load(db.app, session) with HTTMock(atom_mock('test1')): loader.run() assert (loader.i - 1) == 2
from nltk.tag import StanfordNERTagger import pandas as pd from sklearn.metrics import f1_score, confusion_matrix from loader import Load train, test = Load('c') ner = StanfordNERTagger('./stanford-ner-2018-10-16/classifiers/english.all.3class.distsim.crf.ser.gz', './stanford-ner-2018-10-16/stanford-ner.jar') data = train data['tweet'] = ner.tag_sents(data['tweet'].str.split(' ')) pred = [] for i, d in data.iterrows(): tweet = d['tweet'] tag = 'IND' for w in tweet: if w[1] == 'ORGANIZATION': tag = 'GRP' # elif w[1] == 'PEOPLE': # tag = 'IND' pred.append(tag) print(confusion_matrix(data['label'], pred)) print(f1_score(data['label'], pred, average='macro'))
def test_get_link(session): loader = Load(db.app, session) for link in link_data: link_val = loader.get_link({"repository": link[0]}) assert link_val == link[1]
def build(self): self.msg('Loading mapfile...') builder = Load(self.mapfile,variables={},from_string=self.from_string) if not self.from_string: self.msg('Loaded %s...' % self.mapfile) else: self.msg('Loaded XML from string') self.map = builder.build_map(self.width,self.height) if self.srs: self.msg('Setting srs to: %s' % self.srs) self.map.set_easy_srs(self.srs) if self.layers: selected, disactivated = self.map.select_layers(self.layers) self.msg('Selected layers: %s' % selected) if not selected: self.output_error('Layer not found: available layers are: "%s"' % ', '.join(disactivated)) # handle shifts in pixel dimensions or bbox ratio # need to make as an option #try: # self.map.aspect_fix_mode = mapnik.aspect_fix_mode.ADJUST_CANVAS_HEIGHT #except: # self.msg('aspect_fix_mode not available!') # zoom to max extent at beginning if we later need to # zoom to a center point # or need to zoom to a zoom-level self.msg('Setting Map view...') if self.center or not self.zoom is None: if self.max_extent: self.msg('Zooming to max extent: %s' % self.max_extent) self.map.zoom_to_box(mapnik.Envelope(*self.max_extent)) else: self.map.zoom_max() self.msg('Zoomed to *estimated* max extent: %s' % self.map.envelope()) if self.center and not self.zoom is None: self.msg('Zooming to Center (%s) and Zoom Level "%s"' % (self.center,self.zoom)) self.map.set_center_and_zoom(self.center[0],self.center[1],self.zoom) elif self.center and self.radius: self.msg('Zooming to Center (%s) and Radius "%s"' % (self.center,self.radius)) self.map.set_center_and_radius(self.center[0],self.center[1],self.radius) elif not self.zoom is None: self.msg('Zooming to Zoom Level "%s"' % (self.zoom)) self.map.zoom_to_level(self.zoom) elif self.zoom_to_layers: self.msg('Zooming to Layers: "%s"' % (self.zoom_to_layers)) self.map.activate_layers(self.zoom_to_layers) if len(self.zoom_to_layers) > 1: self.map.zoom_to_layers(self.zoom_to_layers) else: self.map.zoom_to_layer(self.zoom_to_layers[0]) else: if self.extent: env = mapnik.Envelope(*self.extent) self.msg('Zooming to custom projected extent: "%s"' % env) self.map.zoom_to_box(env) from_prj = mapnik.Projection(self.map.srs) to_prj = mapnik.Projection('+proj=latlong +datum=WGS84') bbox = env.transform(from_prj,to_prj) self.msg('Custom extent in geographic coordinates: "%s"' % bbox) elif self.bbox: env = mapnik.Envelope(*self.bbox) self.msg('Zooming to custom geographic extent: "%s"' % env) from_prj = mapnik.Projection('+proj=latlong +datum=WGS84') to_prj = mapnik.Projection(self.map.srs) self.map.zoom_to_box(env.transform(from_prj,to_prj)) else: self.map.zoom_all() self.msg('Zoom to extent of all layers: "%s"' % self.map.envelope()) if self.bbox_factor: if self.bbox_factor > 0: bbox = self.map.envelope() * self.bbox_factor else: bbox = self.map.envelope() / self.bbox_factor self.map.zoom_to_box(bbox) self.msg('Adjusting final extent by factor of %s: "%s"' % (self.bbox_factor,self.map.envelope())) self.msg('Finished setting extents...') if self.save_xml: mapnik.save_map(self.map,self.save_xml) return builder