Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix E501 F541 F841 for main, mongoclient, conftest, schemas.py #1091

Merged
merged 2 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions regolith/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def create_parser():
)

# deploy subparser
depp = subp.add_parser("deploy", help="deploys what was built by regolith")
subp.add_parser("deploy", help="deploys what was built by regolith")

# email subparser
emlp = subp.add_parser("email", help="automates emailing")
Expand Down Expand Up @@ -225,9 +225,10 @@ def create_parser():
# mongo-to-fs subparser
mtf = subp.add_parser(
"mongo-to-fs",
help="Backup database from mongodb to filesystem as json. The database will be imported to the destination "
"specified by the 'database':'dst_url' key. For this to work, ensure that the database is included in the "
"dst_url, and that local is set to true.",
help="Backup database from mongodb to filesystem as json. "
"The database will be imported to the destination specified by the 'database':'dst_url' key. "
"For this to work, ensure that the database is included in the "
"dst_url, and that local is set to true.",
)

mtf.add_argument(
Expand Down
6 changes: 4 additions & 2 deletions regolith/mongoclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ def change_keys_id_and_date(obj, convert):
Recursively goes through the dictionary obj and replaces keys with the convert function.
"""
if isinstance(obj, datetime.date):
# Mongo cannot handle datetime.date format, but we have infrastructure to handle iso date strings present
# Mongo cannot handle datetime.date format,
# but we have infrastructure to handle iso date strings present
# Do not convert to datetime.datetime. Mongo can handle this, but regolith cannot.
return obj.isoformat()
if isinstance(obj, (str, int, float)):
Expand Down Expand Up @@ -342,7 +343,8 @@ def open(self):
except AttributeError:
print(
"ERROR:\n"
"Add a username and password to user.json in user/.config/regolith/user.json with the keys\n"
"Add a username and password to user.json in "
"user/.config/regolith/user.json with the keys\n"
"mongo_id and mongo_db_password respectively.\n\n"
"'uname_from_config' and 'pwd_from_config' can/should stand in for these field in the\n"
"mongo URL string in regolithrc.json.\n"
Expand Down
8 changes: 0 additions & 8 deletions regolith/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,6 @@ def load_exemplars():
return exemplars
stevenhua0320 marked this conversation as resolved.
Show resolved Hide resolved


def load_exemplars():
here = Path(__file__).parent
exemplars_file = here / "exemplars.json"
with open(exemplars_file, "r", encoding="utf-8") as exemplars_file:
exemplars = json.load(exemplars_file)
return exemplars


EXEMPLARS = load_exemplars()
SCHEMAS = load_schemas()

Expand Down
37 changes: 18 additions & 19 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import json
import os
import tempfile
from copy import deepcopy, copy
from unittest import mock
from copy import deepcopy

import pytest
from pymongo import MongoClient
Expand Down Expand Up @@ -94,7 +93,6 @@ def make_mongodb():
directory, as well as a mongo database.
This will yield the path to the repo.
"""
cwd = os.getcwd()
forked = False
name = "regolith_mongo_fake"
repo = os.path.join(tempfile.gettempdir(), name)
Expand Down Expand Up @@ -133,10 +131,10 @@ def make_mongodb():
f,
)
if os.name == "nt":
# If on windows, the mongod command cannot be run with the fork or syslog options. Instead, it is installed as
# a service and the exceptions that would typically be log outputs are handled by the exception handlers below.
# In addition, the database must always be manually deleted from the windows mongo instance before running a
# fresh test.
# If on windows, the mongod command cannot be run with the fork or syslog options.
# Instead, it is installed as a service and the exceptions that would typically be log outputs
# are handled by the exception handlers below. In addition, the database must always be manually
# deleted from the windows mongo instance before running a fresh test.
cmd = ["mongo", REGOLITH_MONGODB_NAME, "--eval", "db.dropDatabase()"]
try:
subprocess.check_call(cmd, cwd=repo)
Expand All @@ -156,8 +154,9 @@ def make_mongodb():
subprocess.check_call(cmd, cwd=repo)
except CalledProcessError:
print(
"If using linux or mac, Mongod command failed to execute. If using windows, the status of mongo could \n"
"not be retrieved. In order to run mongodb tests, make sure to install the mongodb community edition with"
"If using linux or mac, Mongod command failed to execute. "
"If using windows, the status of mongo could \n not be retrieved. "
"In order to run mongodb tests, make sure to install the mongodb community edition with "
"\nthe following link:\n"
"https://docs.mongodb.com/manual/installation/"
)
Expand Down Expand Up @@ -240,10 +239,10 @@ def make_mixed_db():
f,
)
if os.name == "nt":
# If on windows, the mongod command cannot be run with the fork or syslog options. Instead, it is installed as
# a service and the exceptions that would typically be log outputs are handled by the exception handlers below.
# In addition, the database must always be manually deleted from the windows mongo instance before running a
# fresh test.
# If on windows, the mongod command cannot be run with the fork or syslog options.
# Instead, it is installed as a service and the exceptions that would typically be log outputs
# are handled by the exception handlers below. In addition, the database must always be manually
# deleted from the windows mongo instance before running a fresh test.
cmd = ["mongo", REGOLITH_MONGODB_NAME, "--eval", "db.dropDatabase()"]
try:
subprocess.check_call(cmd, cwd=repo)
Expand Down Expand Up @@ -411,10 +410,10 @@ def make_migration_db(fs_to_mongo_true__mongo_to_fs_false):
f,
)
if os.name == "nt":
# If on windows, the mongod command cannot be run with the fork or syslog options. Instead, it is installed as
# a service and the exceptions that would typically be log outputs are handled by the exception handlers below.
# In addition, the database must always be manually deleted from the windows mongo instance before running a
# fresh test.
# If on windows, the mongod command cannot be run with the fork or syslog options.
# Instead, it is installed as a service and the exceptions that would typically be log outputs
# are handled by the exception handlers below. In addition, the database must always be manually
# deleted from the windows mongo instance before running a fresh test.
cmd = ["mongo", ALTERNATE_REGOLITH_MONGODB_NAME, "--eval", "db.dropDatabase()"]
try:
subprocess.check_call(cmd, cwd=repo)
Expand Down Expand Up @@ -467,8 +466,8 @@ def shut_down_fork(forked, repo):
subprocess.check_call(cmd, cwd=repo)
except CalledProcessError:
print(
f'Deleting the test database failed, insert "mongo admin --eval '
f'"db.shutdownServer()"" into command line manually'
'Deleting the test database failed, insert "mongo admin --eval '
'"db.shutdownServer()"" into command line manually'
)


Expand Down
Loading