def test_version_info_normalization(): obj1 = VersionInfo(**FAKE_VERSION_INFO_NO_CHECKER) assert obj1.get_normalized_ver() == [0, 9] obj1.version = "1.2.3.4.5.6" assert obj1.get_normalized_ver() == [1, 2, 3, 4, 5, 6] obj1.version = "1_2_3_4" assert obj1.get_normalized_ver() == [1, 2, 3, 4] obj1.version = "ghidra_9.1.2_PUBLIC_20200212" assert obj1.get_normalized_ver() == [9, 1, 2] obj1.version = "release-1.2.3" assert obj1.get_normalized_ver() == [1, 2, 3] # sha1 test - 40 char obj1.version = "ee9f16b4b95c28f8f79a39ca6a1840d8a6444c10" assert obj1.get_normalized_ver( ) == "ee9f16b4b95c28f8f79a39ca6a1840d8a6444c10" # sha256 test - 64 char obj1.version = "f8b09fba9fda9ffebae86611261cf628bd71022fb4348d876974f7c48ddcc6d5" assert (obj1.get_normalized_ver() == "f8b09fba9fda9ffebae86611261cf628bd71022fb4348d876974f7c48ddcc6d5") # missing couple characters from sha256 length obj1.version = "f809fba9fda9ffebae86611261cf628bd71022fb4348d876974f7c48ddcc65" assert obj1.get_normalized_ver() == [809998661126162871022434887697474865] obj1.version = "ABCDEFG" assert obj1.get_normalized_ver() == "ABCDEFG"
def test_version_info_eq(): obj1 = VersionInfo(**FAKE_VERSION_INFO_NO_CHECKER) obj2 = VersionInfo(**FAKE_VERSION_INFO_NO_CHECKER) assert obj1 == obj2 obj1.version = 1.2 assert obj1 != obj2 # We can compare for strings. assert obj1 == "1.2" assert obj1 != "1.3" # But not integers with pytest.raises(ValueError): assert obj1 != 1
def test_setters_version_info_no_checker(): obj = VersionInfo(**FAKE_VERSION_INFO_NO_CHECKER) assert obj.source == "no_checker_case" obj.source = "new case" assert obj.source == "new case" assert obj.version == "0.9" obj.version = 1.2 assert obj.version == "1.2" with pytest.raises(ValueError): obj.version = "" obj.updated = datetime(2020, 1, 1, 11, 11) obj.updated == datetime(2020, 1, 1, 11, 11) # Test invalid time format with pytest.raises(ValueError): obj.updated = "" # size with pytest.raises(ValueError): obj.size = "16062006" obj._size = None assert obj.size == "NaN" obj.size = 900 assert obj.size == "900 bytes" obj.size = 1001 assert obj.size == "1.00 KB" obj.size = 16062 assert obj.size == "16.06 KB" obj.size = 16062006 assert obj.size == "16.06 MB" obj.size = 1606200600 assert obj.size == "1.61 GB" obj_c = FAKE_VERSION_INFO_NO_CHECKER.copy() obj_c["size"] = "This is something" obj = VersionInfo(**obj_c) assert obj.size == "NaN"