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 lint errors #290

Merged
merged 8 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Linting

on: [push, pull_request]
on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.0
hooks:
- id: black

Expand Down
19 changes: 11 additions & 8 deletions custodian/ansible/tests/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import unittest

import pytest

from custodian.ansible.actions import FileActions
from custodian.ansible.interpreter import Modder

Expand Down Expand Up @@ -48,7 +50,8 @@ def test_dict_modify(self):
modder.modify(mod, d)
assert d == {"Bye": "World", "List": [1, 2, 3], "number": 10}
mod = {"_add_to_set": {"number": 3}}
self.assertRaises(ValueError, modder.modify, mod, d)
with pytest.raises(ValueError, match="Keyword number does not refer to an array"):
modder.modify(mod, d)
mod = {"_pull": {"List": 1}}
modder.modify(mod, d)
assert d == {"Bye": "World", "List": [2, 3], "number": 10}
Expand Down Expand Up @@ -121,7 +124,8 @@ def test_strict_mode(self):
modder = Modder(actions=[FileActions])
d = {"Hello": "World"}
mod = {"_set": {"Hello": "Universe", "Bye": "World"}}
self.assertRaises(ValueError, modder.modify, mod, d)
with pytest.raises(ValueError, match="_set is not a supported action"):
modder.modify(mod, d)

# In non-strict mode, unknown actions are ignored.
d = {"Hello": "World"}
Expand All @@ -131,12 +135,11 @@ def test_strict_mode(self):

# File actions not supported
modder = Modder()
self.assertRaises(
ValueError,
modder.modify,
{"_file_create": {"content": "Test data"}},
"test_file",
)
with pytest.raises(ValueError, match="_file_create is not a supported action"):
modder.modify(
{"_file_create": {"content": "Test data"}},
"test_file",
)

def test_modify_object(self):
modder = Modder()
Expand Down
4 changes: 2 additions & 2 deletions custodian/cli/run_vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def get_jobs(args):
ldauu = incar["LDAUU"]
ldauj = incar["LDAUJ"]

njobs = len(args.jobs)
n_jobs = len(args.jobs)
post_settings = [] # append to this list to have settings applied on next job
for i, job in enumerate(args.jobs):
final = i == njobs - 1
final = i == n_jobs - 1
suffix = "." + job if any(c.isdigit() for c in job) else f".{job}{i + 1}"
settings = post_settings
post_settings = []
Expand Down
10 changes: 5 additions & 5 deletions custodian/qchem/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from custodian.custodian import ErrorHandler
from custodian.utils import backup

try:
from openbabel import openbabel as ob
except ImportError:
ob = None

__author__ = "Samuel Blau, Brandon Wood, Shyam Dwaraknath, Ryan Kingsbury"
__copyright__ = "Copyright 2018, The Materials Project"
__version__ = "0.1"
Expand All @@ -17,11 +22,6 @@
__date__ = "3/26/18"
__credits__ = "Xiaohui Qu"

try:
from openbabel import openbabel as ob
except ImportError:
ob = None


class QChemErrorHandler(ErrorHandler):
"""
Expand Down
10 changes: 5 additions & 5 deletions custodian/qchem/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
from custodian.custodian import Job
from custodian.qchem.utils import perturb_coordinates, vector_list_diff

try:
from openbabel import openbabel as ob
except ImportError:
ob = None

__author__ = "Samuel Blau, Brandon Wood, Shyam Dwaraknath, Evan Spotte-Smith"
__copyright__ = "Copyright 2018, The Materials Project"
__version__ = "0.1"
Expand All @@ -24,11 +29,6 @@
__date__ = "3/20/18"
__credits__ = "Xiaohui Qu"

try:
from openbabel import openbabel as ob
except ImportError:
ob = None


class QCJob(Job):
"""A basic QChem Job."""
Expand Down
10 changes: 5 additions & 5 deletions custodian/qchem/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

from custodian.qchem.handlers import QChemErrorHandler

try:
from openbabel import openbabel as ob
except ImportError:
ob = None

__author__ = "Samuel Blau, Brandon Woods, Shyam Dwaraknath, Ryan Kingsbury"
__copyright__ = "Copyright 2018, The Materials Project"
__version__ = "0.1"
Expand All @@ -21,11 +26,6 @@
scr_dir = os.path.join(test_dir, "scr")
cwd = os.getcwd()

try:
from openbabel import openbabel as ob
except ImportError:
ob = None


@unittest.skipIf(ob is None, "openbabel not installed")
class QChemErrorHandlerTest(TestCase):
Expand Down
18 changes: 9 additions & 9 deletions custodian/qchem/tests/test_job_handler_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from custodian.qchem.handlers import QChemErrorHandler
from custodian.qchem.jobs import QCJob

try:
from openbabel import openbabel as ob
except ImportError:
ob = None

__author__ = "Samuel Blau"
__copyright__ = "Copyright 2022, The Materials Project"
__version__ = "0.1"
Expand All @@ -23,11 +28,6 @@
scr_dir = os.path.join(test_dir, "scr")
cwd = os.getcwd()

try:
from openbabel import openbabel as ob
except ImportError:
ob = None


@unittest.skipIf(ob is None, "openbabel not installed")
class FFopt_job_handler_interaction(TestCase):
Expand Down Expand Up @@ -102,7 +102,7 @@ def tearDown(self):
shutil.rmtree(scr_dir)

def test_OptFF(self):
myjob = QCJob.opt_with_frequency_flattener(
job = QCJob.opt_with_frequency_flattener(
qchem_command="qchem",
max_cores=40,
input_file="mol.qin",
Expand All @@ -119,7 +119,7 @@ def test_OptFF(self):
save_scratch=True,
backup=True,
).as_dict()
assert next(myjob).as_dict() == expected_next
assert next(job).as_dict() == expected_next

h = QChemErrorHandler(
input_file="mol.qin",
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_OptFF(self):
save_scratch=True,
backup=False,
).as_dict()
assert next(myjob).as_dict() == expected_next
assert next(job).as_dict() == expected_next
self._check_equivalent_inputs("mol.qin", "mol.qin.error5")

h = QChemErrorHandler(
Expand Down Expand Up @@ -198,6 +198,6 @@ def test_OptFF(self):
save_scratch=True,
backup=False,
).as_dict()
assert next(myjob).as_dict() == expected_next
assert next(job).as_dict() == expected_next

self._check_equivalent_inputs("mol.qin", "mol.qin.opt_1")
Loading