Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup_paths():
root = Path(__file__).parents[2]
src_db_path = root.joinpath('united_states_of_browsers', 'AppData', 'all_merged.sqlite')
sink_db_path = root.joinpath('tests_unfinished_to_be_worked_from', 'data', 'db_for_testing_search.sqlite')
url_log_path = Path.joinpath(sink_db_path.parent,
f'{sink_db_path.stem}_written_url_hashes.json')
return src_db_path, sink_db_path, url_log_path
def data_path():
data_path = Path(__file__).parents[2]
data_path = Path.joinpath(data_path, 'data', 'tuner_results')
return data_path
def test_from_obj():
mesh = Mesh.from_obj(compas.get('faces.obj'))
assert mesh.number_of_faces() == 25
assert mesh.number_of_vertices() == 36
assert mesh.number_of_edges() == 60
# test pathlib integration
mesh = Mesh.from_obj(Path.joinpath(Path.cwd(), 'data/mesh.obj'))
assert mesh.number_of_faces() == 563
assert mesh.number_of_vertices() == 309
assert mesh.number_of_edges() == 872
# test importing using URL
mesh = Mesh.from_obj(
'https://raw.githubusercontent.com/compas-dev/compas/master/data/hypar.obj'
)
assert mesh.number_of_faces() == 64
assert mesh.number_of_vertices() == 81
assert mesh.number_of_edges() == 144
def test_s3_upload(self):
s3_uploader = S3Uploader(
s3_client=self.s3,
bucket_name=self.bucket_name,
prefix=self.prefix,
kms_key_id=self.kms_key_id,
force_upload=self.force_upload,
)
s3_uploader.artifact_metadata = {"a": "b"}
remote_path = Path.joinpath(Path(os.getcwd()), Path("tmp"))
self.s3.head_object = MagicMock(side_effect=ClientError(error_response={}, operation_name="head_object"))
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
s3_url = s3_uploader.upload(f.name, remote_path)
self.assertEqual(s3_url, "s3://{0}/{1}/{2}".format(self.bucket_name, self.prefix, remote_path))
import pytest
from pathlib import Path
from united_states_of_browsers.db_merge import db_search
from tests.tests_unfinished_to_be_worked_from.test_data_older import test_db_search_data as dbs_data
from tests.tests_unfinished_to_be_worked_from.test_data_older.test_db_search_data import TestFields
root = Path(__file__).parents[1]
db_for_testing = Path.joinpath(root, 'tests_unfinished_to_be_worked_from', 'data', 'db_for_testing_search.sqlite')
@pytest.mark.parametrize('test_case', [test_case for test_case in dbs_data.search_testdata['keywords only']])
def test_search_keywords(test_case):
actual_output = db_search.search(db_path=str(db_for_testing), word_query=test_case.input)
actual_output_data = [dict(record) for record in actual_output]
actual_output_data = [TestFields(record['title'], record['url'], record['url_hash'], record['guid'],)
for record in actual_output_data
]
expected_output_data = [TestFields(record.title, record.url, record.url_hash, record.guid,)
for record in test_case.expected
]
assert len(actual_output_data) == len(expected_output_data)
for actual_, expected_ in zip (actual_output_data, expected_output_data):
assert actual_ == expected_
models_folder += list(map(lambda path: Path.joinpath(Path.cwd(), path), glob.glob('src/modules/*/db_models')))
def register_components(app):
'''
Automatically registers all module that need some initializing with application.
To-do: make it not only for shared modules
'''
shared_modules_folder = Path.joinpath(Path.cwd(), 'src/modules', )
__register_extensions_auto(shared_modules_folder, app, 'modules', 'api')
services_modules_folder = Path.joinpath(Path.cwd(), 'src/shared/services')
__register_extensions_auto(services_modules_folder, app, 'shared.services', 'service')
def ensure_cache_dir_exists() -> None:
CACHE_DIR.mkdir(exist_ok=True)
pathlib.Path.joinpath(CACHE_DIR, 'set_checklists').mkdir(exist_ok=True)
pathlib.Path.joinpath(CACHE_DIR, 'set_mids').mkdir(exist_ok=True)
# -*- coding: utf-8 -*-
__author__ = '__apple'
__time__ = '2018/1/17 15:47'
from werkzeug.exceptions import HTTPException
from app import create_app
from app.help.error import APIException
from app.help.error_code import ServerError
from pathlib import Path
# 如果没有 image 目录就创建
base_dir = Path(__file__).parent
image_dir = Path.joinpath(base_dir, 'image')
if not Path.exists(image_dir):
Path.mkdir(image_dir)
app = create_app()
# 兼容 windows
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# AOP Flask 1.0
@app.errorhandler(Exception)
def framework_error(e):
if isinstance(e, APIException):
return e
if isinstance(e, HTTPException):
code = e.code