def test_best_prefix_negative_huge_numbers(self): """best_prefix_base: large negative values retain their prefix unit""" positive_result = bitmath.best_prefix(10**8) negative_result = bitmath.best_prefix(-10**8) # Verify that the best prefix math works for negative and # positive numbers self.assertEqual(negative_result, -1 * positive_result) # Verify that they produce the same type self.assertIs(type(negative_result), type(positive_result)) # Verify that type is what we expect it to be self.assertIs(type(negative_result), bitmath.MiB)
def test_best_prefix_negative_less_than_a_byte(self): """best_prefix_base: negative values less than a byte stay as bits""" # assert that a Byte of -4 bits yields Bit(-4) bm1 = bitmath.Byte(bits=-4) expected = bitmath.Bit(-4) res = bitmath.best_prefix(bm1) # Verify that best prefix math works for negative numbers self.assertEqual(res, expected) # Verify that best prefix guessed the correct type self.assertIs(type(res), bitmath.Bit)
def gpu_info(gpu_handle, i: int = 0) -> List[Dict[str, Any]]: power = pynvml.nvmlDeviceGetPowerUsage(gpu_handle) / 1000 temperature = pynvml.nvmlDeviceGetTemperature(gpu_handle, pynvml.NVML_TEMPERATURE_GPU) free_memory = best_prefix(pynvml.nvmlDeviceGetMemoryInfo(gpu_handle).free) return [ dict(full_text=f'GPU Power {power:.1f} W', name=f'gpu{i}_power'), dict(full_text=free_memory.format('GPU RAM {value:.1f} {unit}'), name=f'gpu{i}_free_memory'), dict(full_text=f'GPU Temp {temperature} ℃', name=f'gpu{i}_temperature'), ]
def test_best_prefix_with_bitmath_input(self): """best_prefix_base: can handle bitmath type inputs""" bm1 = bitmath.Byte(1024) expected = bitmath.KiB(1) self.assertEqual(bitmath.best_prefix(bm1), expected)
def test_bitmath_best_prefix_NIST_exbi(self): """bitmath.best_prefix return an exbibyte for a huge number of bytes""" result = bitmath.best_prefix(1152921504606846977) self.assertIs(type(result), bitmath.EiB)
def test_bitmath_best_prefix_NIST(self): """bitmath.best_prefix return a Kibibyte for 1024""" result = bitmath.best_prefix(1024) self.assertIs(type(result), bitmath.KiB)
def test___init__invalid_input_types(self): """__init__: can identify (in)valid input parameters, raise ValueError if detected""" invalid_inputs = ["one hundred", 100 + 6j, None] for invalid_input in invalid_inputs: with self.assertRaises(ValueError): bitmath.best_prefix(invalid_input)
def test_bitmath_best_prefix_SI_yotta(self): """bitmath.best_prefix return a yottabyte for a huge number of bytes""" result = bitmath.best_prefix(1000000000000000000000001, system=bitmath.SI) self.assertIs(type(result), bitmath.YB)
def test_bitmath_best_prefix_SI(self): """bitmath.best_prefix return a Kilobyte for 1024""" result = bitmath.best_prefix(1024, system=bitmath.SI) self.assertIs(type(result), bitmath.kB)