Skip to content

Commit f64a3fa

Browse files
committed
#2358 increase coverage
1 parent 884c40a commit f64a3fa

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

pybamm/experiments/experiment.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -417,29 +417,24 @@ def convert_electric(self, electric):
417417
)
418418
)
419419

420-
def _read_and_drop_temperature(self, cond):
420+
def _detect_mistyped_temperatures(self, cond):
421421

422-
if (len(re.findall("at", cond)) > 1 or ("Run" in cond and "at" in cond)) and (
423-
"oC" not in cond
424-
):
425-
raise ValueError(
426-
"Instruction must be 'discharge', 'charge', 'rest', 'hold' or "
427-
f"'Run'. For example: {examples}"
428-
""
429-
"The following instruction does not comply: "
430-
f"{cond}"
431-
)
422+
mistype = False
432423

433-
matches = re.findall(r"at\s-*\d+\.*\d*\s*oC", cond)
424+
if "oC" in cond:
425+
mistype = True
434426

435-
if len(matches) == 0 and "oC" in cond:
436-
raise ValueError(
437-
f"Temperature not written "
438-
f"correctly on step: '{cond}'"
439-
)
427+
if mistype:
428+
raise ValueError(f"Temperature not written correctly on step: '{cond}'")
429+
430+
def _read_and_drop_temperature(self, cond):
431+
432+
matches = re.findall(r"at\s-*\d+\.*\d*\s*oC", cond)
440433

441434
if len(matches) == 0:
442435

436+
self._detect_mistyped_temperatures(cond)
437+
443438
if self.temperature is None:
444439

445440
pybamm.logger.warning(

tests/unit/test_experiments/test_experiment.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def test_bad_strings(self):
440440
TypeError, "Operating conditions should be strings or tuples of strings"
441441
):
442442
pybamm.Experiment([(1, 2, 3)])
443-
with self.assertRaisesRegex(ValueError, "Instruction must be"):
443+
with self.assertRaisesRegex(ValueError, "Operating conditions must"):
444444
pybamm.Experiment(["Discharge at 1 A at 2 hours"])
445445
with self.assertRaisesRegex(ValueError, "Instruction must be"):
446446
pybamm.Experiment(["Run at 1 A for 2 hours"])
@@ -450,12 +450,18 @@ def test_bad_strings(self):
450450
pybamm.Experiment(["Run at at 1 A for 2 hours"])
451451
with self.assertRaisesRegex(ValueError, "Instruction must be"):
452452
pybamm.Experiment(["Play at 1 A for 2 hours"])
453+
with self.assertRaisesRegex(ValueError, "Operating conditions must"):
454+
pybamm.Experiment(["Do at 1 A"])
455+
with self.assertRaisesRegex(ValueError, "Instruction must be"):
456+
pybamm.Experiment(["Run US06 at 1 A"])
453457
with self.assertRaisesRegex(ValueError, "Instruction"):
454458
pybamm.Experiment(["Cell Charge at 1 A for 2 hours"])
455459
with self.assertRaisesRegex(ValueError, "units must be"):
456460
pybamm.Experiment(["Discharge at 1 B for 2 hours"])
457461
with self.assertRaisesRegex(ValueError, "time units must be"):
458462
pybamm.Experiment(["Discharge at 1 A for 2 years"])
463+
with self.assertRaisesRegex(ValueError, "More than one temperature found"):
464+
pybamm.Experiment(["Discharge at 1 A for 2 hours at 25oC at 30oC"])
459465
with self.assertRaisesRegex(
460466
ValueError, "The temperature for the CC and CV steps"
461467
):
@@ -468,8 +474,6 @@ def test_bad_strings(self):
468474
],
469475
cccv_handling="ode",
470476
)
471-
with self.assertRaisesRegex(ValueError, "Instruction must be"):
472-
pybamm.Experiment(["Discharge at 1 A for 2 hours at 25C"])
473477

474478
with self.assertRaisesRegex(
475479
ValueError, "Temperature not written correctly on step"

0 commit comments

Comments
 (0)