def test_mod_string_parsing(self): # one normal, one "special" (nc and pf), and one multimod mod self.assertEqual(Mod("HD"), Mod.HD) self.assertEqual(Mod("NC"), Mod.NC) self.assertEqual(Mod("SOHDDT"), Mod.HD + Mod.DT + Mod.SO) self.assertRaises(ValueError, lambda: Mod("DTH")) self.assertRaises(ValueError, lambda: Mod("DH"))
def test_mod_ordering(self): self.assertEqual(Mod("DTHDSO"), Mod("SOHDDT"), "Identical mods ordered differently were not equal") self.assertEqual(Mod("DTHR").long_name(), Mod("HRDT").long_name(), "Long name of identical mods ordered differently were not equal") self.assertEqual(Mod("SOAPFLEZ").short_name(), Mod("EZSOFLAP").short_name(), "Short name of identical mods ordered differently were not equal") self.assertEqual(Mod("HD").short_name(), "HD") self.assertEqual(Mod("HR").long_name(), "HardRock") self.assertEqual(Mod("DTHR").long_name(), "DoubleTime HardRock") self.assertEqual(Mod("HRDT").long_name(), "DoubleTime HardRock")
def url_scheme_called(self, url): from circleguard import ReplayMap, Circleguard, Mod # url is bytes, so decode back to str url = url.decode() # windows appends an extra slash even if the original url didn't have # it, so remove it url = url.strip("/") # all urls can have any of the following parameters: # * m - the map id # * u - the first user's id # * u2 - the second user's id # * t - the timestamp to start at # * m1 - the mods the first replay was played with # * m2 - the mods the second replay was played with # For example, a url might look like # circleguard://m=221777&u=2757689&m1=HDHRu2=3219026&m2=HDHR map_id = int(re.compile(r"m=(.*?)(&|$)").search(url).group(1)) user_id = int(re.compile(r"u=(.*?)(&|$)").search(url).group(1)) timestamp_match = re.compile(r"t=(.*?)(&|$)").search(url) # start at the beginning if timestamp isn't specified timestamp = int(timestamp_match.group(1)) if timestamp_match else 0 # mods is optional, will take the user's highest play on the map if not # specified mods1_match = re.compile(r"m1=(.*?)(&|$)").search(url) mods1 = None if mods1_match: mods1 = mods1_match.group(1) user_id_2_match = re.compile(r"u2=(.*?)(&|$)").search(url) user_id_2 = None if user_id_2_match: user_id_2 = int(user_id_2_match.group(1)) mods2_match = re.compile(r"m2=(.*?)(&|$)").search(url) mods2 = None if mods2_match: mods2 = mods2_match.group(1) # convert the string into an actual mods object if we received it mods1 = Mod(mods1) if mods1 else None r = ReplayMap(map_id, user_id, mods1) cg = Circleguard(get_setting("api_key")) cg.load(r) replays = [r] if user_id_2: mods2 = Mod(mods2) if mods2 else None r2 = ReplayMap(map_id, user_id_2, mods2) cg.load(r2) replays.append(r2) # open visualizer for the given map and user, and jump to the timestamp result = URLAnalysisResult(replays, timestamp) self.cg_classic.main_tab.url_analysis_q.put(result)
def test_mod_str_list_parsing(self): self.assertEqual(Mod(["HD"]), Mod.HD) self.assertEqual(Mod(["NC"]), Mod.NC) self.assertEqual(Mod(["SO", "HD", "DT"]), Mod.HD + Mod.DT + Mod.SO) self.assertEqual(Mod(["SOHD", "DT"]), Mod.HD + Mod.DT + Mod.SO) self.assertEqual(Mod(["SOHDDT"]), Mod.HD + Mod.DT + Mod.SO) self.assertEqual(Mod(["HD", "SODT"]), Mod.HD + Mod.DT + Mod.SO) self.assertRaises(ValueError, lambda: Mod(["DTH"])) self.assertRaises(ValueError, lambda: Mod(["DH"])) self.assertRaises(ValueError, lambda: Mod(["DH", int()]))
def test_equality_reflexivity(self): # reflexivity test self.assertEqual(Mod("NC"), Mod("NC"))