| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 804bc80 commit 04fa56f
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1018,8 +1018,8 @@ def _string_to_value(self, valuestr: Union[str, None]) -> Union[int, float, str, | |||
| 1018 | 1018 | for numtype in types: | |
| 1019 | 1019 | try: | |
| 1020 | 1020 | val = numtype(valuestr) | |
| 1021 | - # truncated value ? | ||
| 1022 | - if val != float(valuestr): | ||
| 1021 | + # Reject NaN without coercing exact integer values to float. | ||
| 1022 | + if numtype is float and val != float(valuestr): | ||
| 1023 | 1023 | continue | |
| 1024 | 1024 | return val | |
| 1025 | 1025 | except (ValueError, TypeError): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,6 +37,38 @@ def tearDown(self): | |||
| 37 | 37 | if osp.isfile(lfp): | |
| 38 | 38 | raise AssertionError("Previous TC left hanging git-lock file: {}".format(lfp)) | |
| 39 | 39 | ||
| 40 | + def test_integer_config_values_keep_precision(self): | ||
| 41 | + for text, expected in ( | ||
| 42 | + ("9007199254740993", 9007199254740993), | ||
| 43 | + ("9223372036854775807", 9223372036854775807), | ||
| 44 | + ("-9007199254740993", -9007199254740993), | ||
| 45 | + ): | ||
| 46 | + with self.subTest(text=text): | ||
| 47 | + config_file = io.BytesIO(("[limits]\nvalue = %s\n" % text).encode("ascii")) | ||
| 48 | + config_file.name = "integer_precision.config" | ||
| 49 | + with GitConfigParser(config_file) as config: | ||
| 50 | + value = config.get_value("limits", "value") | ||
| 51 | + self.assertEqual(value, expected) | ||
| 52 | + self.assertIs(type(value), int) | ||
| 53 | + self.assertEqual(config.get_values("limits", "value"), [expected]) | ||
| 54 | + | ||
| 55 | + def test_numeric_config_conversion_preserves_other_values(self): | ||
| 56 | + for text, expected in ( | ||
| 57 | + ("11.11", 11.11), | ||
| 58 | + ("1e3", 1000.0), | ||
| 59 | + ("nan", "nan"), | ||
| 60 | + ("NaN", "NaN"), | ||
| 61 | + ("true", True), | ||
| 62 | + ("false", False), | ||
| 63 | + ): | ||
| 64 | + with self.subTest(text=text): | ||
| 65 | + config_file = io.BytesIO(("[values]\nvalue = %s\n" % text).encode("ascii")) | ||
| 66 | + config_file.name = "numeric_conversion.config" | ||
| 67 | + with GitConfigParser(config_file) as config: | ||
| 68 | + value = config.get_value("values", "value") | ||
| 69 | + self.assertEqual(value, expected) | ||
| 70 | + self.assertIs(type(value), type(expected)) | ||
| 71 | + | ||
| 40 | 72 | def _to_memcache(self, file_path): | |
| 41 | 73 | with open(file_path, "rb") as fp: | |
| 42 | 74 | sio = io.BytesIO(fp.read()) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments