Skip to content

Commit

Permalink
Merge pull request #1091 from stevenhua0320/lint-check-13
Browse files Browse the repository at this point in the history
Fix E501 F541 F841 for main, mongoclient, conftest, schemas.py
  • Loading branch information
sbillinge authored Jul 6, 2024
2 parents 8e5126b + 3d69841 commit 9d8c5f3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 36 deletions.
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
13 changes: 2 additions & 11 deletions regolith/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,8 @@ def load_schemas():
def load_exemplars():
here = Path(__file__).parent
exemplar_file = here / "exemplars.json"
with open(exemplar_file, "r", encoding="utf-8") as exemplar_file:
raw_exemplars = json.load(exemplar_file)
exemplars = raw_exemplars
return exemplars


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)
with open(exemplar_file, "r", encoding="utf-8") as efile:
exemplars = json.load(efile)
return exemplars


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

0 comments on commit 9d8c5f3

Please sign in to comment.