Skip to content

Commit

Permalink
Reformat code with black
Browse files Browse the repository at this point in the history
  • Loading branch information
dstufft committed Mar 22, 2018
1 parent f171672 commit 64a6c15
Show file tree
Hide file tree
Showing 212 changed files with 4,751 additions and 7,568 deletions.
9 changes: 4 additions & 5 deletions tests/common/db/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@


class UserFactory(WarehouseFactory):

class Meta:
model = User

Expand All @@ -31,15 +32,13 @@ class Meta:
is_staff = False
is_superuser = False
date_joined = factory.fuzzy.FuzzyNaiveDateTime(
datetime.datetime(2005, 1, 1),
datetime.datetime(2010, 1, 1),
)
last_login = factory.fuzzy.FuzzyNaiveDateTime(
datetime.datetime(2011, 1, 1),
datetime.datetime(2005, 1, 1), datetime.datetime(2010, 1, 1)
)
last_login = factory.fuzzy.FuzzyNaiveDateTime(datetime.datetime(2011, 1, 1))


class EmailFactory(WarehouseFactory):

class Meta:
model = Email

Expand Down
1 change: 1 addition & 0 deletions tests/common/db/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


class ClassifierFactory(WarehouseFactory):

class Meta:
model = Classifier

Expand Down
42 changes: 26 additions & 16 deletions tests/common/db/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,30 @@
import packaging.utils

from warehouse.packaging.models import (
BlacklistedProject, Dependency, DependencyKind, File, JournalEntry,
Project, Release, Role,
BlacklistedProject,
Dependency,
DependencyKind,
File,
JournalEntry,
Project,
Release,
Role,
)

from .accounts import UserFactory
from .base import WarehouseFactory


class ProjectFactory(WarehouseFactory):

class Meta:
model = Project

name = factory.fuzzy.FuzzyText(length=12)


class ReleaseFactory(WarehouseFactory):

class Meta:
model = Release

Expand All @@ -49,6 +57,7 @@ class Meta:


class FileFactory(WarehouseFactory):

class Meta:
model = File

Expand All @@ -62,23 +71,23 @@ class Meta:
lambda o: hashlib.sha256(o.filename.encode("utf8")).hexdigest()
)
blake2_256_digest = factory.LazyAttribute(
lambda o: hashlib.blake2b(o.filename.encode("utf8"),
digest_size=32).hexdigest()
)
upload_time = factory.fuzzy.FuzzyNaiveDateTime(
datetime.datetime(2008, 1, 1)
lambda o: hashlib.blake2b(o.filename.encode("utf8"), digest_size=32).hexdigest()
)
upload_time = factory.fuzzy.FuzzyNaiveDateTime(datetime.datetime(2008, 1, 1))
path = factory.LazyAttribute(
lambda o: "/".join([
o.blake2_256_digest[:2],
o.blake2_256_digest[2:4],
o.blake2_256_digest[4:],
o.filename,
])
lambda o: "/".join(
[
o.blake2_256_digest[:2],
o.blake2_256_digest[2:4],
o.blake2_256_digest[4:],
o.filename,
]
)
)


class RoleFactory(WarehouseFactory):

class Meta:
model = Role

Expand All @@ -88,6 +97,7 @@ class Meta:


class DependencyFactory(WarehouseFactory):

class Meta:
model = Dependency

Expand All @@ -98,19 +108,19 @@ class Meta:


class JournalEntryFactory(WarehouseFactory):

class Meta:
model = JournalEntry

id = factory.Sequence(lambda n: n)
name = factory.fuzzy.FuzzyText(length=12)
version = factory.Sequence(lambda n: str(n) + ".0")
submitted_date = factory.fuzzy.FuzzyNaiveDateTime(
datetime.datetime(2008, 1, 1)
)
submitted_date = factory.fuzzy.FuzzyNaiveDateTime(datetime.datetime(2008, 1, 1))
submitted_by = factory.SubFactory(UserFactory)


class BlacklistedProjectFactory(WarehouseFactory):

class Meta:
model = BlacklistedProject

Expand Down
1 change: 1 addition & 0 deletions tests/common/db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


class AdminFlagFactory(WarehouseFactory):

class Meta:
model = AdminFlag

Expand Down
36 changes: 14 additions & 22 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import webtest as _webtest

from pytest_postgresql.factories import (
init_postgresql_database, drop_postgresql_database, get_config,
init_postgresql_database, drop_postgresql_database, get_config
)
from sqlalchemy import event

Expand All @@ -37,8 +37,7 @@ def pytest_collection_modifyitems(items):
continue

module_path = os.path.relpath(
item.module.__file__,
os.path.commonprefix([__file__, item.module.__file__]),
item.module.__file__, os.path.commonprefix([__file__, item.module.__file__])
)

module_root_dir = module_path.split(os.pathsep)[0]
Expand All @@ -47,9 +46,7 @@ def pytest_collection_modifyitems(items):
elif module_root_dir.startswith("unit"):
item.add_marker(pytest.mark.unit)
else:
raise RuntimeError(
"Unknown test type (filename = {0})".format(module_path)
)
raise RuntimeError("Unknown test type (filename = {0})".format(module_path))


@pytest.fixture
Expand All @@ -69,7 +66,7 @@ def pyramid_config(pyramid_request):
def datadog():
return pretend.stub(
event=pretend.call_recorder(lambda *args, **kwargs: None),
increment=pretend.call_recorder(lambda *args, **kwargs: None),
increment=pretend.call_recorder(lambda *args, **kwargs: None)
)


Expand All @@ -93,6 +90,7 @@ def database(request):
init_postgresql_database(pg_user, pg_host, pg_port, pg_db)

# Ensure our database gets deleted.

@request.addfinalizer
def drop_database():
drop_postgresql_database(pg_user, pg_host, pg_port, pg_db, pg_version)
Expand Down Expand Up @@ -121,7 +119,7 @@ def app_config(database):
"sessions.url": "redis://localhost:0/",
"statuspage.url": "https://2p66nmmycsj3.statuspage.io",
"warehouse.xmlrpc.cache.url": "redis://localhost:0/",
},
}
)

# Ensure our migrations have been ran.
Expand All @@ -141,13 +139,15 @@ def db_session(app_config):
session.begin_nested()

# Then each time that SAVEPOINT ends, reopen it

@event.listens_for(session, "after_transaction_end")
def restart_savepoint(session, transaction):
if transaction.nested and not transaction._parent.nested:
session.begin_nested()

try:
yield session

finally:
session.close()
Session.remove()
Expand All @@ -158,18 +158,12 @@ def restart_savepoint(session, transaction):

@pytest.yield_fixture
def user_service(db_session, app_config):
return services.DatabaseUserService(
db_session, app_config.registry.settings
)
return services.DatabaseUserService(db_session, app_config.registry.settings)


@pytest.yield_fixture
def token_service(app_config):
return services.TokenService(
secret="secret",
salt="salt",
max_age=21600,
)
return services.TokenService(secret="secret", salt="salt", max_age=21600)


class QueryRecorder:
Expand Down Expand Up @@ -207,6 +201,7 @@ def query_recorder(app_config):

try:
yield recorder

finally:
event.remove(engine, "before_cursor_execute", recorder.record)

Expand Down Expand Up @@ -237,6 +232,7 @@ def webtest(app_config):

try:
yield _TestApp(app_config.make_wsgi_app())

finally:
app_config.registry["sqlalchemy.engine"].dispose()

Expand All @@ -253,11 +249,7 @@ def pytest_runtest_makereport(item, call):
browser = item.funcargs["browser"]
for log_type in (set(browser.log_types) - {"har"}):
data = "\n\n".join(
filter(
None,
(l.get("message") for l in browser.get_log(log_type)))
filter(None, (l.get("message") for l in browser.get_log(log_type)))
)
if data:
rep.sections.append(
("Captured {} log".format(log_type), data)
)
rep.sections.append(("Captured {} log".format(log_type), data))
7 changes: 4 additions & 3 deletions tests/functional/legacy_api/test_removed.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
@pytest.mark.parametrize("action", ["submit", "submit_pkg_info"])
def test_removed_upload_apis(webtest, action):
resp = webtest.post("/legacy/?:action={}".format(action), status=410)
assert resp.status == \
("410 Project pre-registration is no longer required or supported, so "
"continue directly to uploading files.")
assert resp.status == (
"410 Project pre-registration is no longer required or supported, so "
"continue directly to uploading files."
)


def test_remove_doc_upload(webtest):
Expand Down
11 changes: 2 additions & 9 deletions tests/functional/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@


@pytest.mark.parametrize(
('domain', 'indexable'),
[
('pypi.org', True),
('test.pypi.org', False),
]
('domain', 'indexable'), [('pypi.org', True), ('test.pypi.org', False)]
)
def test_robots_txt(app_config, domain, indexable):
app_config.add_settings({
'warehouse.domain': domain,
'enforce_https': False,
})
app_config.add_settings({'warehouse.domain': domain, 'enforce_https': False})
testapp = webtest.TestApp(app_config.make_wsgi_app())
resp = testapp.get("/robots.txt")
assert resp.status_code == 200
Expand Down
40 changes: 20 additions & 20 deletions tests/functional/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,37 @@ def test_templates_for_empty_titles():
env = Environment(
loader=FileSystemLoader(dir_name),
extensions=[
"jinja2.ext.i18n",
"warehouse.utils.html.ClientSideIncludeExtension",
"jinja2.ext.i18n", "warehouse.utils.html.ClientSideIncludeExtension"
],
cache_size=0,
)

env.filters.update({
"format_date": "warehouse.i18n.filters:format_date",
"format_datetime": "warehouse.i18n.filters:format_datetime",
"format_rfc822_datetime":
"warehouse.i18n.filters:format_rfc822_datetime",
"format_number": "warehouse.i18n.filters:format_number",
"format_classifiers": "warehouse.filters:format_classifiers",
"format_tags": "warehouse.filters:format_tags",
"json": "warehouse.filters:tojson",
"readme": "warehouse.filters:readme",
"shorten_number": "warehouse.filters:shorten_number",
"urlparse": "warehouse.filters:urlparse",
"contains_valid_uris": "warehouse.filters:contains_valid_uris",
"format_package_type": "warehouse.filters:format_package_type",
"parse_version": "warehouse.filters:parse_version",
})
env.filters.update(
{
"format_date": "warehouse.i18n.filters:format_date",
"format_datetime": "warehouse.i18n.filters:format_datetime",
"format_rfc822_datetime": "warehouse.i18n.filters:format_rfc822_datetime",
"format_number": "warehouse.i18n.filters:format_number",
"format_classifiers": "warehouse.filters:format_classifiers",
"format_tags": "warehouse.filters:format_tags",
"json": "warehouse.filters:tojson",
"readme": "warehouse.filters:readme",
"shorten_number": "warehouse.filters:shorten_number",
"urlparse": "warehouse.filters:urlparse",
"contains_valid_uris": "warehouse.filters:contains_valid_uris",
"format_package_type": "warehouse.filters:format_package_type",
"parse_version": "warehouse.filters:parse_version",
}
)

for dir_, _, files in os.walk(dir_name):
if dir_.find("/includes") > -1 or \
dir_.find("/legacy") > -1:
if dir_.find("/includes") > -1 or dir_.find("/legacy") > -1:
continue

for file_name in files:
if file_name.endswith(".csi.html"):
continue

if file_name.endswith(".html"):
rel_dir = os.path.relpath(dir_, dir_name)
rel_file = os.path.join(rel_dir, file_name)
Expand Down
Loading

0 comments on commit 64a6c15

Please sign in to comment.