Whole file

alengwenus/pypck

The author described this change as Fix VarUnit issues and add tests for conversion roundtrip and calibration (#83). It counts as a record because the checks below fail on the code as it stood at 58292b52b and pass on 3957c91f9, with nothing else changed between the two runs.

Fix saved2021-06-03
Sharing licenceMIT · LICENSE
Change size+3 3

What the code was meant to do, written into the code itself as a save note

Fix VarUnit issues and add tests for conversion roundtrip and calibration (#83)

The change

775775 elif unit == VarUnit.VOLT:
776776 var_value = VarValue.from_volt(value)
777777 elif unit == VarUnit.AMPERE:
778- var_value = VarValue.from_kelvin(value)
778+ var_value = VarValue.from_ampere(value)
779779 elif unit == VarUnit.DEGREE:
780780 var_value = VarValue.from_degree(value)
781781 else:
927927 :return: The variable value (never null)
928928 :rtype: VarValue
929929 """
930- return VarValue(int(round(value * 100)))
930+ return VarValue(int(round(value * 100000)))
931931
932932 @staticmethod
933933 def from_degree(value: float, is_abs: bool = True) -> "VarValue":
10771077 :return: The converted value
10781078 :rtype: float
10791079 """
1080- return self.native_value / 100.0
1080+ return self.native_value / 100000.0
10811081
10821082 def to_degree(self) -> float:
10831083 """Convert to degree value.

The check that tells the two apart

failpass·tests/test_vars.py::test_calibration[VarUnit.AMPERE-100-0.001]
failpass·tests/test_vars.py::test_calibration[VarUnit.AMPERE-4000-0.04]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-0-0_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-0-0_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-100-100_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-100-100_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-1000-1000_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-1000-1000_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-1023-1023_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-1023-1023_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-198-198_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-198-198_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-199-199_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-199-199_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-200-200_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-200-200_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-201-201_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-201-201_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-202-202_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-202-202_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-205-205_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-205-205_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-4095-4095_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-4095-4095_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-48-48_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-48-48_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-49-49_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-49-49_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-50-50_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-50-50_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-51-51_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-51-51_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-52-52_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-52-52_1]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-65535-65535_0]
failpass·tests/test_vars.py::test_roundtrip[VarUnit.AMPERE-65535-65535_1]

Check file tests/test_vars.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it58292b52b03838f0e953b00931c2cdd0c8a9ba29
Broken version dated2021-05-28
Modulepypck.lcn_defs
Units changedVarValue
Fingerprintbd22429adeeca00d
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in alengwenus/pypck