Skip to content

[Code scan] Replace ineffective assertTrue checks with equality assertions #1919

Description

@njzjz

This issue is from a Codex global scan of the repository.

Two tests use assertTrue(actual, expected) where the second argument is only the failure message, so the intended comparison is never performed.

Evidence:

def _check_numb_models(testCase, iter_idx, numb_models):
models = glob.glob(
os.path.join("iter.%06d" % iter_idx, "00.train", "[0-9][0-9][0-9]") # noqa: UP031
)
testCase.assertTrue(len(models), numb_models)

def test_make_potential_files(self):
cwd = os.getcwd()
abs_equi_path = os.path.abspath(self.equi_path)
self.Lammps.make_potential_files(abs_equi_path)
self.assertTrue(os.path.islink(os.path.join(self.equi_path, "frozen_model.pb")))
self.assertTrue(os.path.isfile(os.path.join(self.equi_path, "inter.json")))
ret = loadfn(os.path.join(self.equi_path, "inter.json"))
self.assertTrue(self.inter_param, ret)

_check_numb_models() currently passes whenever len(models) is nonzero, even if it does not equal numb_models. test_make_potential_files() passes whenever self.inter_param is truthy; the loaded ret value is used only as a message and is not compared.

Expected behavior: use equality assertions such as assertEqual(len(models), numb_models) and assertEqual(ret, self.inter_param) so these tests catch regressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions