Best Python code snippet using pypom_form_python
test_save_pattern_serializers.py
Source:test_save_pattern_serializers.py
...121 self.assertEqual(data["source_directory"], "system_temp")122 with open(join(TEMP_DIRECTORY, filepath), "rb") as f:123 deserialized = cloudpickle.load(f)124 self.assertEqual(obj, deserialized)125 def test_deserialize(self):126 obj = TestSerializationClass("test_deserialize", 1, 2, 3, other=["abc"])127 filepath = f"{self.__class__.__name__}-test_deserialize-{RANDOM_RUN}"128 self.assertFalse(isfile(join(TEMP_DIRECTORY, filepath)))129 with open(join(TEMP_DIRECTORY, filepath), "wb") as f:130 cloudpickle.dump(obj, f)131 self.assertTrue(isfile(join(TEMP_DIRECTORY, filepath)))132 data = CloudpickleFileSerializer.deserialize(filepath)133 self.assertEqual(obj, data["obj"])134class CloudpickleInMemorySerializerTests(unittest.TestCase):135 def test_serialize(self):136 obj = TestSerializationClass("test_serialize", 1, 2, 3, other=["abc"])137 data = CloudpickleInMemorySerializer.serialize(obj)138 deserialized = cloudpickle.loads(data["obj"])139 self.assertEqual(obj, deserialized)140 def test_deserialize(self):141 obj = TestSerializationClass("test_deserialize", 1, 2, 3, other=["abc"])142 serialized = cloudpickle.dumps(obj)143 data = CloudpickleInMemorySerializer.deserialize(serialized)144 self.assertEqual(obj, data["obj"])145class PicklePersistenceMethodsTests(unittest.TestCase):146 def test_dump_object(self):147 obj = TestSerializationClass("test_dump_object", 1, 2, 3, other=["abc"])148 filepath = join(149 TEMP_DIRECTORY, f"{self.__class__.__name__}-test_dump_object-{RANDOM_RUN}"150 )151 self.assertFalse(isfile(filepath))152 PicklePersistenceMethods.dump_object(obj, filepath=filepath)153 self.assertTrue(isfile(filepath))154 with open(filepath, "rb") as f:155 deserialized = pickle.load(f)156 self.assertEqual(obj, deserialized)157 def test_dump_object_without_overwrite(self):158 obj = TestSerializationClass(159 "test_dump_object_without_overwrite", 1, 2, 3, other=["abc"]160 )161 obj2 = TestSerializationClass("overwrite", "a", 2, 3, other=["abc"])162 filepath = join(163 TEMP_DIRECTORY,164 f"{self.__class__.__name__}-test_dump_object_without_overwrite-{RANDOM_RUN}",165 )166 PicklePersistenceMethods.dump_object(obj, filepath=filepath)167 self.assertTrue(isfile(filepath))168 # try overwrite169 PicklePersistenceMethods.dump_object(obj2, filepath=filepath, overwrite=False)170 with open(filepath, "rb") as f:171 deserialized = pickle.load(f)172 self.assertEqual(obj, deserialized)173 self.assertNotEqual(obj2, deserialized)174 def test_dumps_object(self):175 obj = TestSerializationClass("test_dumps_object", 1, 2, 3, other=["abc"])176 serialized = PicklePersistenceMethods.dumps_object(obj)177 deserialized = pickle.loads(serialized)178 self.assertEqual(obj, deserialized)179 def test_load_object(self):180 obj = TestSerializationClass("test_load_object", 1, 2, 3, other=["abc"])181 filepath = join(182 TEMP_DIRECTORY, f"{self.__class__.__name__}-test_load_object-{RANDOM_RUN}"183 )184 self.assertFalse(isfile(filepath))185 with open(filepath, "wb") as f:186 pickle.dump(obj, f)187 self.assertTrue(isfile(filepath))188 deserialized = PicklePersistenceMethods.load_object(filepath)189 self.assertEqual(obj, deserialized)190 def test_loads_object(self):191 obj = TestSerializationClass("test_loads_object", 1, 2, 3, other=["abc"])192 serialized = pickle.dumps(obj)193 deserialized = PicklePersistenceMethods.loads_object(serialized)194 self.assertEqual(obj, deserialized)195class PickleFileSerializerTests(unittest.TestCase):196 def test_serialize(self):197 obj = TestSerializationClass("test_serialize", 1, 2, 3, other=["abc"])198 filepath = f"{self.__class__.__name__}-test_serialize-{RANDOM_RUN}"199 self.assertFalse(isfile(join(TEMP_DIRECTORY, filepath)))200 data = PickleFileSerializer.serialize(201 obj, filepath=filepath, format_directory="", format_extension=""202 )203 self.assertTrue(isfile(join(TEMP_DIRECTORY, filepath)))204 self.assertEqual(data["filepath"], filepath)205 self.assertEqual(data["source_directory"], "system_temp")206 with open(join(TEMP_DIRECTORY, filepath), "rb") as f:207 deserialized = pickle.load(f)208 self.assertEqual(obj, deserialized)209 def test_deserialize(self):210 obj = TestSerializationClass("test_deserialize", 1, 2, 3, other=["abc"])211 filepath = f"{self.__class__.__name__}-test_deserialize-{RANDOM_RUN}"212 self.assertFalse(isfile(join(TEMP_DIRECTORY, filepath)))213 with open(join(TEMP_DIRECTORY, filepath), "wb") as f:214 pickle.dump(obj, f)215 self.assertTrue(isfile(join(TEMP_DIRECTORY, filepath)))216 data = PickleFileSerializer.deserialize(filepath)217 self.assertEqual(obj, data["obj"])218class PickleInMemorySerializerTests(unittest.TestCase):219 def test_serialize(self):220 obj = TestSerializationClass("test_serialize", 1, 2, 3, other=["abc"])221 data = PickleInMemorySerializer.serialize(obj)222 deserialized = pickle.loads(data["obj"])223 self.assertEqual(obj, deserialized)224 def test_deserialize(self):225 obj = TestSerializationClass("test_deserialize", 1, 2, 3, other=["abc"])226 serialized = pickle.dumps(obj)227 data = PickleInMemorySerializer.deserialize(serialized)228 self.assertEqual(obj, data["obj"])229class HicklePersistenceMethodsTests(unittest.TestCase):230 def test_dump_object(self):231 obj = TestSerializationClass("test_dump_object", 1, 2, 3, other=["abc"])232 filepath = join(233 TEMP_DIRECTORY, f"{self.__class__.__name__}-test_dump_object-{RANDOM_RUN}"234 )235 self.assertFalse(isfile(filepath))236 HicklePersistenceMethods.dump_object(obj, filepath=filepath)237 self.assertTrue(isfile(filepath))238 deserialized = hickle.load(filepath)239 self.assertEqual(obj, deserialized)240 def test_dump_object_without_overwrite(self):241 obj = TestSerializationClass(242 "test_dump_object_without_overwrite", 1, 2, 3, other=["abc"]243 )244 obj2 = TestSerializationClass("overwrite", "a", 2, 3, other=["abc"])245 filepath = join(246 TEMP_DIRECTORY,247 f"{self.__class__.__name__}-test_dump_object_without_overwrite-{RANDOM_RUN}",248 )249 HicklePersistenceMethods.dump_object(obj, filepath=filepath)250 self.assertTrue(isfile(filepath))251 # try overwrite252 HicklePersistenceMethods.dump_object(obj2, filepath=filepath, overwrite=False)253 deserialized = hickle.load(filepath)254 self.assertEqual(obj, deserialized)255 self.assertNotEqual(obj2, deserialized)256 def test_load_object(self):257 obj = TestSerializationClass("test_load_object", 1, 2, 3, other=["abc"])258 filepath = join(259 TEMP_DIRECTORY, f"{self.__class__.__name__}-test_load_object-{RANDOM_RUN}"260 )261 self.assertFalse(isfile(filepath))262 hickle.dump(obj, filepath)263 self.assertTrue(isfile(filepath))264 deserialized = HicklePersistenceMethods.load_object(filepath)265 self.assertEqual(obj, deserialized)266class HickleFileSerializerTests(unittest.TestCase):267 def test_serialize(self):268 obj = TestSerializationClass("test_serialize", 1, 2, 3, other=["abc"])269 filepath = f"{self.__class__.__name__}-test_serialize-{RANDOM_RUN}"270 self.assertFalse(isfile(join(TEMP_DIRECTORY, filepath)))271 data = HickleFileSerializer.serialize(272 obj, filepath=filepath, format_directory="", format_extension=""273 )274 self.assertTrue(isfile(join(TEMP_DIRECTORY, filepath)))275 self.assertEqual(data["filepath"], filepath)276 self.assertEqual(data["source_directory"], "system_temp")277 deserialized = hickle.load(join(TEMP_DIRECTORY, filepath))278 self.assertEqual(obj, deserialized)279 def test_deserialize(self):280 obj = TestSerializationClass("test_deserialize", 1, 2, 3, other=["abc"])281 filepath = f"{self.__class__.__name__}-test_deserialize-{RANDOM_RUN}"282 self.assertFalse(isfile(join(TEMP_DIRECTORY, filepath)))283 # with open(join(TEMP_DIRECTORY, filepath), 'wb') as f:284 hickle.dump(obj, join(TEMP_DIRECTORY, filepath))285 self.assertTrue(isfile(join(TEMP_DIRECTORY, filepath)))286 data = HickleFileSerializer.deserialize(filepath)287 self.assertEqual(obj, data["obj"])288class DaskPersistenceMethodsTests(unittest.TestCase):289 def test_read_csv(self):290 pass291 def test_read_parquet(self):292 pass293 def test_read_json(self):294 pass295 def test_to_csv(self):296 pass297 def test_to_parquet(self):298 pass299 def test_to_json(self):300 pass301class DaskParquetSerializerTests(unittest.TestCase):302 def test_serialize(self):303 pass304 def test_deserialize(self):305 pass306class DaskCSVSerializerTests(unittest.TestCase):307 def test_serialize(self):308 pass309 def test_deserialize(self):310 pass311class DaskJSONSerializerTests(unittest.TestCase):312 def test_serialize(self):313 pass314 def test_deserialize(self):315 pass316class PandasPersistenceMethodsTests(unittest.TestCase):317 def test_read_csv(self):318 pass319 def test_read_parquet(self):320 pass321 def test_read_json(self):322 pass323 def test_to_csv(self):324 pass325 def test_to_parquet(self):326 pass327 def test_to_json(self):328 pass329class PandasParquetSerializerTests(unittest.TestCase):330 def test_serialize(self):331 pass332 def test_deserialize(self):333 pass334class PandasCSVSerializerTests(unittest.TestCase):335 def test_serialize(self):336 pass337 def test_deserialize(self):338 pass339class PandasJSONSerializerTests(unittest.TestCase):340 def test_serialize(self):341 pass342 def test_deserialize(self):343 pass344class KerasPersistenceMethodsTests(unittest.TestCase):345 def test_save_model(self):346 pass347 def test_load_model(self):348 pass349 def test_save_weights(self):350 pass351 def test_load_weights(self):352 pass353class KerasSavedModelSerializerTests(unittest.TestCase):354 def test_serialize(self):355 pass356 def test_deserialize(self):357 pass358class KerasH5SerializerTests(unittest.TestCase):359 def test_serialize(self):360 pass361 def test_deserialize(self):362 pass363if __name__ == "__main__":...
test_endpoints.py
Source:test_endpoints.py
2from ossapi import (RankingType, BeatmapsetEventType, AccessDeniedError,3 InsufficientScopeError)4from tests import api5class TestBeatmapsetDiscussionPosts(TestCase):6 def test_deserialize(self):7 api.beatmapset_discussion_posts()8class TestUserRecentActivity(TestCase):9 def test_deserialize(self):10 api.user_recent_activity(12092800)11class TestSpotlights(TestCase):12 def test_deserialize(self):13 api.spotlights()14class TestUserBeatmaps(TestCase):15 def test_deserialize(self):16 api.user_beatmaps(user_id=12092800, type_="most_played")17class TestUserKudosu(TestCase):18 def test_deserialize(self):19 api.user_kudosu(user_id=3178418)20class TestBeatmapScores(TestCase):21 def test_deserialize(self):22 api.beatmap_scores(beatmap_id=1981090)23class TestBeatmap(TestCase):24 def test_deserialize(self):25 api.beatmap(beatmap_id=221777)26class TestBeatmapset(TestCase):27 def test_deserialize(self):28 api.beatmapset(beatmap_id=3207950)29class TestBeatmapsetEvents(TestCase):30 def test_deserialize(self):31 api.beatmapset_events()32 def test_all_types(self):33 # beatmapset_events is a really complicated endpoint in terms of return34 # types. We want to make sure both that we're not doing anything wrong,35 # and the osu! api isn't doing anything wrong by returning something36 # that doesn't match their documentation.37 for event_type in BeatmapsetEventType:38 api.beatmapset_events(types=[event_type])39class TestRanking(TestCase):40 def test_deserialize(self):41 api.ranking("osu", RankingType.PERFORMANCE, country="US")42class TestUserScores(TestCase):43 def test_deserialize(self):44 api.user_scores(12092800, "best")45class TestBeatmapUserScore(TestCase):46 def test_deserialize(self):47 api.beatmap_user_score(beatmap_id=221777, user_id=2757689, mode="osu")48class TestBeatmapUserScores(TestCase):49 def test_deserialize(self):50 api.beatmap_user_scores(beatmap_id=221777, user_id=2757689, mode="osu")51class TestSearch(TestCase):52 def test_deserialize(self):53 api.search(query="peppy")54class TestComment(TestCase):55 def test_deserialize(self):56 api.comment(comment_id=1)57class TestDownloadScore(TestCase):58 def test_deserialize(self):59 # api instance is using client credentials which doesn't have access to60 # downloading replays61 self.assertRaises(AccessDeniedError,62 lambda: api.download_score(mode="osu", score_id=2797309065))63class TestSearchBeatmaps(TestCase):64 def test_deserialize(self):65 api.search_beatmapsets(query="the big black")66class TestUser(TestCase):67 def test_deserialize(self):68 api.user(12092800)69 def test_key(self):70 # make sure it automatically falls back to username if not specified71 api.user("tybug2")72 api.user("tybug2", key="username")73 self.assertRaises(Exception, lambda: api.user("tybug2", key="id"))74class TestMe(TestCase):75 def test_deserialize(self):76 # requires an authorization code api for the identify scope, client77 # credentials can only request the public scope78 self.assertRaises(InsufficientScopeError, api.get_me)79class TestWikiPage(TestCase):80 def test_deserialize(self):81 api.wiki_page("en", "Welcome")82class TestChangelogBuild(TestCase):83 def test_deserialize(self):84 api.changelog_build("stable40", "20210520.2")85class TestChangelogListing(TestCase):86 def test_deserialize(self):87 api.changelog_listing()88class TestChangelogLookup(TestCase):89 def test_deserialize(self):90 api.changelog_lookup("lazer")91class TestForumTopic(TestCase):92 def test_deserialize(self):93 api.forum_topic(141240)94class TestBeatmapsetDiscussionVotes(TestCase):95 def test_deserialize(self):96 api.beatmapset_discussion_votes().votes[0].score97class TestBeatmapsetDiscussions(TestCase):98 def test_deserialize(self):99 api.beatmapset_discussions()100class TestNewsListing(TestCase):101 def test_deserialize(self):102 api.news_listing(year=2021)103class TestNewsPost(TestCase):104 def test_deserialize(self):105 api.news_post(1025, key="id")106class TestSeasonalBackgrounds(TestCase):107 def test_deserialize(self):108 api.seasonal_backgrounds()109# TODO requires friends.read scope110# class TestFriends(TestCase):111# def test_deserialize(self):112# api.friends()113# TODO requires chat.write scope114# class TestCreateNewPM(TestCase):115# def test_deserialize(self):116# api.create_pm(2070907, "Unit test from ossapi "...
test_serialize.py
Source:test_serialize.py
...46 assert isinstance(47 serialized_model, db.PriorModel48 )49 assert serialized_model.cls is m.Gaussian50 def test_deserialize(51 self,52 serialized_model53 ):54 assert serialized_model().cls is m.Gaussian55class TestPriors:56 def test_serialize(57 self,58 serialized_model,59 ):60 assert len(serialized_model.children) == 361 def test_deserialize(62 self,63 serialized_model64 ):65 model = serialized_model()66 assert len(model.priors) == 367 assert isinstance(68 model.centre,69 af.UniformPrior70 )71class TestCollection:72 def test_serialize(73 self,74 serialized_collection75 ):76 assert isinstance(77 serialized_collection,78 db.CollectionPriorModel79 )80 child, = serialized_collection.children81 assert len(child.children) == 382 def test_deserialize(83 self,84 serialized_collection85 ):86 collection = serialized_collection()87 assert len(collection) == 188 assert isinstance(89 collection.model,90 af.PriorModel91 )92def test_none():93 assert db.Object.from_object(None)() is None94def test_commit(session):95 model = af.PriorModel(96 m.Gaussian...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!