How to use get_hash method in localstack

Best Python code snippet using localstack_python

DLCGenerator.py

Source:DLCGenerator.py Github

copy

Full Screen

...6import hashlib7import copy8910def get_hash(name):11 return int(hashlib.sha256(name.strip().lower().encode('utf-8')).hexdigest(), 16) % 10**81213#this is the only data that had to be inputted manually14dlcs = [15 {16 'id': get_hash('dlc' + 'Supersonic Fury'),17 'name': 'Supersonic Fury',18 'release_date': '2015-8-13',19 'image': 'http://www.dlcompare.com/upload/gameimage/file/7522.jpeg',20 'type': 'dlc',21 'description': 'Supersonic Fury was the first major DLC pack to be released for Rocket League.',22 'items': [23 get_hash('body' + 'Dominus'),24 get_hash('body' + 'Takumi'),25 get_hash('decal' + 'Chaser'),26 get_hash('decal' + 'Copycat'),27 get_hash('decal' + 'Crazy-8'),28 get_hash('decal' + 'Gaki'),29 get_hash('decal' + 'Reiko'),30 get_hash('decal' + 'Stripes'),31 get_hash('decal' + 'Flames'),32 get_hash('decal' + 'Scorpions'),33 get_hash('decal' + 'Skulls'),34 get_hash('decal' + 'Stripes'),35 get_hash('decal' + 'Tats'),36 get_hash('decal' + 'Wings'),37 get_hash('wheel' + 'Cristiano'),38 get_hash('wheel' + 'Spinner'),39 get_hash('paint' + 'wood'),40 get_hash('paint' + 'pearlescent'),41 get_hash('paint' + 'metallic pearl'),42 get_hash('paint' + 'carbon fiber'),43 get_hash('paint' + 'brushed metal'),44 get_hash('boost' + 'nitrous'),45 get_hash('boost' + 'burnout'),46 ]47 },48 {49 'id': get_hash('dlc' + 'Revenge of the Battle-Cars'),50 'name': 'Revenge of the Battle-Cars',51 'release_date': '2015-10-13',52 'image': 'http://ecx.images-amazon.com/images/I/61OeESrZ35L._SX342_QL70_.jpg',53 'type': 'dlc',54 'description': 'Revenge of the Battle-Cars was the second major DLC pack to be released for Rocket League.',55 'items': [56 get_hash('body' + 'Scarab'),57 get_hash('body' + 'Zippy'),58 get_hash('decal' + 'Chaser'),59 get_hash('decal' + 'Bomani'),60 get_hash('decal' + 'Derby Girl'),61 get_hash('decal' + 'Flames'),62 get_hash('decal' + 'Hearts'),63 get_hash('decal' + 'Tiger'),64 get_hash('decal' + 'Tribal'), 65 get_hash('decal' + 'Caboodle'),66 get_hash('decal' + 'Callous'),67 get_hash('decal' + 'Flames'),68 get_hash('decal' + 'Hearts'),69 get_hash('decal' + 'Leopard'),70 get_hash('decal' + 'Tiger'),71 get_hash('wheel' + 'Zippy'),72 get_hash('wheel' + 'Scarab'),73 get_hash('paint' + 'toon matte'),74 get_hash('paint' + 'toon glossy'),75 get_hash('paint' + 'toon wood'), 76 get_hash('boost' + 'Accelerato'),77 get_hash('boost' + 'Battle-Stars'),78 get_hash('topper' + 'Cavalier'),79 get_hash('topper' + 'Locomotive'),80 get_hash('topper' + 'Pixelated Shades'),81 get_hash('topper' + 'Shark Fin'),82 get_hash('antenna' + 'Retro Ball - Urban'),83 get_hash('antenna' + 'Retro Ball - Utopia'),84 ]85 },86 {87 'id': get_hash('dlc' + 'Chaos Run'),88 'name': 'Chaos Run',89 'release_date': '2015-12-1',90 'description': 'Chaos Run was the third major DLC pack added to the game.',91 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/0/03/Chaosr.jpg/revision/latest?cb=20161110054220',92 'type': 'dlc',93 'items': [94 get_hash('body' + 'Ripper'),95 get_hash('body' + 'Grog'),96 get_hash('decal' + 'Bomber'),97 get_hash('decal' + 'Flames'),98 get_hash('decal' + 'Ockie'),99 get_hash('decal' + 'Shot Fox'),100 get_hash('decal' + 'Spikes'),101 get_hash('decal' + 'Tribal'),102 get_hash('decal' + 'Bomber'),103 get_hash('decal' + 'Cyclops'),104 get_hash('decal' + 'Lepus'),105 get_hash('decal' + 'Stripes'),106 get_hash('decal' + 'Tagged'),107 get_hash('decal' + 'Tribal'),108 get_hash('wheel' + 'Grog'),109 get_hash('wheel' + 'Ripper'),110 get_hash('paint' + 'Camo'),111 get_hash('paint' + 'Sun-Damaged'), 112 get_hash('boost' + 'Nuts & Bolts'),113 get_hash('boost' + 'Sandstorm'),114 get_hash('topper' + 'Boombox'),115 get_hash('topper' + 'Cow Skull'),116 get_hash('topper' + 'Mohawk'),117 get_hash('antenna' + 'Bomb Pole'),118 get_hash('antenna' + 'Radioactive'),119 get_hash('antenna' + 'Retro Ball - Wasteland'),120 ]121 },122 {123 'id': get_hash('dlc' + 'DeLorean Time Machine'),124 'release_date': '2015-10-21',125 'description': 'Great Scott! The time continuum has been disrupted and as of October 21, 2015, the "Future" is now!\nCelebrate one of the most anticipated days of the last 30 years in Rocket League with the official Back to the Future DeLorean Time Machine!\nDon\'t waste another minute. Get yours today!',126 'name': 'DeLorean Time Machine',127 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/9/95/DeLorean_Time_Machine_promo_art_1.jpg/revision/latest/scale-to-width-down/310?cb=20170530114548',128 'type': 'dlc',129 'items': [get_hash('body' + 'DeLorean Time Machine'), get_hash('trail' + 'DeLorean Time Machine'), get_hash('wheel' + 'DeLorean Time Machine')]130 },131 {132 'id': get_hash('dlc' + 'Batman v Superman: Dawn of Justice'),133 'description': 'Black and blue, god vs man, day vs night!\nUnleash your own one-car reign of terror with the official Batmobile Battle-Car from the upcoming blockbuster mega-film, Batman v Superman: Dawn of Justice!\nThree exclusive antenna flags to pledge your allegiance to the World\'s Finest trio of Batman, Superman, or Wonder Woman.',134 'release_date': '2016-3-8',135 'name': 'Batman v Superman: Dawn of Justice',136 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/3/3c/Batman_v_Superman_Dawn_of_Justice_DLC_pack.jpg/revision/latest/scale-to-width-down/310?cb=20170710214612',137 'type': 'dlc',138 'items': [get_hash('body' + 'Batmobile'), get_hash('trail' + 'Batmobile'), get_hash('wheel' + 'Batmobile'), get_hash('boost' + 'Batmobile'), get_hash('antenna' + 'batman'), get_hash('antenna' + 'superman'), get_hash('antenna' + 'wonder woman')]139 },140 {141 'id': get_hash('dlc' + 'Aftershock'),142 'name': 'Aftershock',143 'description': 'Drive the fan-favorite, jet-inspired dynamo, Aftershock, and relive the glory days of the original Supersonic Acrobatic Rocket-Powered Battle-Cars, today!',144 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/2/2e/Aftershock_hero_art.jpg/revision/latest/scale-to-width-down/310?cb=20170531180331',145 'type': 'dlc',146 'release_date': '2016-7-18',147 'items': [148 get_hash('body' + 'Aftershock'), 149 get_hash('wheel' + 'Aftershock'), 150 get_hash('decal' + 'Copycat'),151 get_hash('decal' + 'MIRV'),152 get_hash('decal' + 'Seismic'),153 get_hash('decal' + 'Tiger'),154 get_hash('decal' + 'Tribal'),155 get_hash('decal' + 'Wings'), 156 ]157 },158 {159 'id': get_hash('dlc' + 'Marauder'),160 'name': 'Marauder',161 'description': 'Because you demanded it, a Supersonic Acrobatic Rocket-Powered Battle-Cars classic, the monstrous Marauder, returns to the pitch!',162 'release_date': '2016-7-18',163 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/7/79/Marauder_hero_art.jpg/revision/latest/scale-to-width-down/310?cb=20170531202512',164 'type': 'dlc',165 'items': [166 get_hash('body' + 'Marauder'), 167 get_hash('wheel' + 'Marauder'), 168 get_hash('decal' + 'Big Buck'),169 get_hash('decal' + 'Ruffian'),170 get_hash('decal' + 'Safari'),171 get_hash('decal' + 'Stripes'),172 get_hash('decal' + 'Vagabond'),173 get_hash('decal' + 'Wings'), 174 ]175 },176 {177 'id': get_hash('dlc' + 'Esper'),178 'name': 'Esper',179 'description': 'Taken from the streets of Japan\'s not-too-distant future, Esper combines roadster and motorcycle for the coolest ride in the apocalypse!',180 'release_date': '2016-7-18',181 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/3/3b/Esper_hero_art.jpg/revision/latest/scale-to-width-down/310?cb=20170601160548',182 'type': 'dlc',183 'items': [184 get_hash('body' + 'Esper'), 185 get_hash('wheel' + 'Esper'), 186 get_hash('decal' + 'Kaiju'),187 get_hash('decal' + 'Mouse Cat'),188 get_hash('decal' + 'Neo'),189 get_hash('decal' + 'Pegasus'),190 get_hash('decal' + 'Shank'),191 get_hash('decal' + 'Super F3'), 192 ]193 },194 {195 'id': get_hash('dlc' + 'Masamune'),196 'name': 'Masamune',197 'release_date': '2016-7-18',198 'description': 'Use the science of aerodynamics and slice through the competition with Masamune, a cutting-edge racer from the streets of Neo Tokyo!',199 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/8/81/Masamune_hero_art.jpg/revision/latest/scale-to-width-down/310?cb=20170601162859',200 'type': 'dlc',201 'items': [202 get_hash('body' + 'Masamune'), 203 get_hash('wheel' + 'Masamune'), 204 get_hash('decal' + 'DJ Sushi'),205 get_hash('decal' + 'Otaku'),206 get_hash('decal' + 'Road Rage'),207 get_hash('decal' + 'Stars'),208 get_hash('decal' + 'Stripes'),209 get_hash('decal' + 'Wildfire'), 210 ]211 },212 {213 'id': get_hash('dlc' + 'Proteus'),214 'name': 'Proteus',215 'description': 'From the darkest fathoms of the ocean comes Proteus, an imposing deep-sea diver built to handle pressure!',216 'release_date': '2016-10-4',217 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/c/cf/Proteus_hero_art.jpg/revision/latest/scale-to-width-down/310?cb=20170602180338',218 'type': 'dlc',219 'items': [220 get_hash('body' + 'Proteus'), 221 get_hash('wheel' + 'Proteus'), 222 get_hash('decal' + 'Crash Dive'),223 get_hash('decal' + 'Cuttle Time'),224 get_hash('decal' + 'Fathom'),225 get_hash('decal' + 'Ladybug'),226 get_hash('decal' + 'Stripes'),227 get_hash('decal' + 'Tiger Shark'), 228 ]229 },230 {231 'id': get_hash('dlc' + 'Triton'),232 'name': 'Triton',233 'release_date': '2016-10-4',234 'description': 'Embrace your inner sea god and rule the high seas with Triton, the AquaDome\'s sleekest submersible Battle-Car!',235 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/9/94/Triton_hero_art.jpg/revision/latest/scale-to-width-down/310?cb=20170602185705',236 'type': 'dlc',237 'items': [238 get_hash('body' + 'Triton'), 239 get_hash('wheel' + 'Triton'), 240 get_hash('decal' + 'Daddy-O'),241 get_hash('decal' + 'Fugu'),242 get_hash('decal' + 'Makai'),243 get_hash('decal' + 'Modus Bestia'),244 get_hash('decal' + 'Ragnarok'),245 get_hash('decal' + 'Stripes'), 246 ]247 },248 {249 'id': get_hash('dlc' + 'Vulcan'),250 'name': 'Vulcan',251 'release_date': '2016-12-6',252 'description': 'Defend the universe (and your goal line) with Vulcan, the most elite sports-craft in the galaxy!',253 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/6/64/Vulcan_hero_art.jpg/revision/latest/scale-to-width-down/310?cb=20170529185045',254 'type': 'dlc',255 'items': [256 get_hash('body' + 'Vulcan'), 257 get_hash('wheel' + 'Vulcan'), 258 get_hash('decal' + 'ARC'),259 get_hash('decal' + 'Armada'),260 get_hash('decal' + 'Combat'),261 get_hash('decal' + 'Cryo-Flames'),262 get_hash('decal' + 'Medic'),263 get_hash('decal' + 'Space Worm'), 264 ]265 },266 {267 'id': get_hash('dlc' + 'TWIN MILL III'),268 'name': 'Twin Mill III',269 'release_date': '2017-02-21',270 'description': 'Powered by not one, but TWO blown big-block engines and dual front intakes, Hot Wheels® world famous Twin Mill™ III has arrived!',271 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/3/30/Twin_Mill_III_hero_art.jpg/revision/latest/scale-to-width-down/310?cb=20170611140210',272 'type': 'dlc',273 'items': [274 get_hash('body' + 'TWIN MILL III'), 275 get_hash('wheel' + 'OH5'), 276 get_hash('decal' + 'Flames'),277 get_hash('decal' + 'Javelin'),278 get_hash('decal' + 'Overline'),279 get_hash('decal' + 'Primo'),280 get_hash('decal' + 'Pyro'),281 get_hash('decal' + 'Speedster'), 282 ]283 },284 {285 'id': get_hash('dlc' + 'Bone Shaker'),286 'name': 'Bone Shaker',287 'description': 'Take control of the field with one of the most beloved hot rods of all time, the Hot Wheels® Bone Shaker™!',288 'release_date': '2017-02-21',289 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/4/41/Bone_Shaker_hero_art.jpg/revision/latest/scale-to-width-down/310?cb=20170611123904',290 'type': 'dlc',291 'items': [292 get_hash('body' + 'Bone Shaker'), 293 get_hash('wheel' + 'WW5SP'), 294 get_hash('decal' + 'Bone Jack'),295 get_hash('decal' + 'Diablo'),296 get_hash('decal' + 'Inferno'),297 get_hash('decal' + 'Pro-Street'),298 get_hash('decal' + 'Starstruck'),299 get_hash('decal' + 'Stripes'), 300 ]301 },302 {303 'id': get_hash('dlc' + 'Ice Charger'),304 'name': 'Ice Charger',305 'release_date': '2017-04-04',306 'description': 'Now you can own Dom Toretto\'s Dodge Ice Charger from Universal Pictures\' explosive movie, The Fate of the Furious.',307 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/6/68/Ice_Charger_hero_art.jpg/revision/latest/scale-to-width-down/310?cb=20170530130044',308 'type': 'dlc',309 'items': [310 get_hash('body' + 'Ice Charger'), 311 get_hash('decal' + 'CDXL'),312 get_hash('decal' + 'Clean Cut'),313 get_hash('decal' + 'Crazy Sandwich'),314 get_hash('decal' + 'Flames'),315 get_hash('decal' + 'Rakugaki'),316 get_hash('decal' + 'Rally'), 317 ]318 },319 {320 'id': get_hash('dlc' + '\'70 DODGE CHARGER R-T'),321 'name': '\'70 Dodge Charger R-T',322 'release_date': '2017-10-11',323 'description': 'Challenge the rules with Dom Toretto\'s 1970 Dodge Charger R-T from from the film that launched the epic saga, The Fast and the Furious, by Universal Pictures.',324 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/4/49/%2770_Dodge_Charger_RT_hero_art.jpg/revision/latest/scale-to-width-down/310?cb=20171004211508',325 'type': 'dlc',326 'items': [327 get_hash('body' + '\'70 Dodge Charger R-T'), 328 get_hash('wheel' + '\'70 Dodge Charger R-T'),329 get_hash('decal' + 'Alameda Twin'),330 get_hash('decal' + 'Good Graces'),331 get_hash('decal' + 'Flames'),332 get_hash('decal' + 'Rally'),333 get_hash('decal' + 'Sinclair'),334 get_hash('decal' + 'Wheelman'), 335 ]336 },337 {338 'id': get_hash('dlc' + '\'99 Nissan Skyline GT-R R34'),339 'name': '\'99 Nissan Skyline GT-R R34',340 'release_date': '2017-10-11',341 'description': 'Rev up Brian O\'Conner\'s 1999 Nissan Skyline GT-R R34 from Universal Pictures\' 2 Fast 2 Furious!',342 'image': 'https://vignette.wikia.nocookie.net/rocketleague/images/a/a5/%2799_Nissan_Skyline_GT-R_R34_hero_art.jpg/revision/latest/scale-to-width-down/310?cb=20171004211431',343 'type': 'dlc',344 'items': [345 get_hash('body' + '\'99 Nissan Skyline GT-R R34'), 346 get_hash('wheel' + '\'99 Nissan Skyline GT-R R34'),347 get_hash('decal' + '2Bold'),348 get_hash('decal' + '2Cool'),349 get_hash('decal' + '2Tuff'),350 get_hash('decal' + 'Clean Cut'),351 get_hash('decal' + 'Home Stretch'),352 get_hash('decal' + 'The Clutch'), 353 ]354 }355]356357if __name__ == '__main__':358 with open('dlcs_items.txt', 'w') as f:359 for dlc in dlcs:360 for item in dlc['items']:361 item_dlc = {"from_type": "dlc", "from_id": dlc['id'], "from_relation": "items", "to_id": item}362 f.write(json.dumps(item_dlc)+'\n')363 with open('dlcs.txt', 'w') as f:364 for dlc in dlcs:365 del dlc['items']366 f.write(json.dumps(dlc)+'\n')

Full Screen

Full Screen

hashing_test.py

Source:hashing_test.py Github

copy

Full Screen

...26import streamlit as st27from streamlit.hashing import NP_SIZE_LARGE, PANDAS_ROWS_LARGE, CodeHasher28get_main_script_director = MagicMock(return_value=os.getcwd())29# Get code hasher and mock the main script directory.30def get_hash(f, context=None):31 hasher = CodeHasher("md5")32 hasher._get_main_script_directory = MagicMock()33 hasher._get_main_script_directory.return_value = os.getcwd()34 hasher.update(f, context)35 return hasher.digest()36class HashTest(unittest.TestCase):37 def test_string(self):38 self.assertEqual(get_hash("hello"), get_hash("hello"))39 self.assertNotEqual(get_hash("hello"), get_hash("hellö"))40 def test_int(self):41 self.assertEqual(get_hash(145757624235), get_hash(145757624235))42 self.assertNotEqual(get_hash(10), get_hash(11))43 self.assertNotEqual(get_hash(-1), get_hash(1))44 self.assertNotEqual(get_hash(2 ** 7), get_hash(2 ** 7 - 1))45 self.assertNotEqual(get_hash(2 ** 7), get_hash(2 ** 7 + 1))46 def test_list(self):47 self.assertEqual([1, 2], [1, 2])48 self.assertNotEqual([1, 2], [2, 2])49 self.assertNotEqual([1], 1)50 def test_tuple(self):51 self.assertEqual((1, 2), (1, 2))52 self.assertNotEqual((1, 2), (2, 2))53 self.assertNotEqual((1,), 1)54 self.assertNotEqual((1,), [1])55 def test_float(self):56 self.assertEqual(get_hash(0.1), get_hash(0.1))57 self.assertNotEqual(get_hash(23.5234), get_hash(23.5235))58 def test_bool(self):59 self.assertEqual(get_hash(True), get_hash(True))60 self.assertNotEqual(get_hash(True), get_hash(False))61 def test_none(self):62 self.assertEqual(get_hash(None), get_hash(None))63 self.assertNotEqual(get_hash(None), get_hash(False))64 def test_builtins(self):65 self.assertEqual(get_hash(abs), get_hash(abs))66 self.assertNotEqual(get_hash(abs), get_hash(type))67 def test_pandas_dataframe(self):68 df1 = pd.DataFrame({"foo": [12]})69 df2 = pd.DataFrame({"foo": [42]})70 df3 = pd.DataFrame({"foo": [12]})71 self.assertEqual(get_hash(df1), get_hash(df3))72 self.assertNotEqual(get_hash(df1), get_hash(df2))73 df4 = pd.DataFrame(np.zeros((PANDAS_ROWS_LARGE, 4)), columns=list("ABCD"))74 df5 = pd.DataFrame(np.zeros((PANDAS_ROWS_LARGE, 4)), columns=list("ABCD"))75 self.assertEqual(get_hash(df4), get_hash(df5))76 def test_pandas_series(self):77 series1 = pd.Series([1, 2])78 series2 = pd.Series([1, 3])79 series3 = pd.Series([1, 2])80 self.assertEqual(get_hash(series1), get_hash(series3))81 self.assertNotEqual(get_hash(series1), get_hash(series2))82 series4 = pd.Series(range(PANDAS_ROWS_LARGE))83 series5 = pd.Series(range(PANDAS_ROWS_LARGE))84 self.assertEqual(get_hash(series4), get_hash(series5))85 def test_numpy(self):86 np1 = np.zeros(10)87 np2 = np.zeros(11)88 np3 = np.zeros(10)89 self.assertEqual(get_hash(np1), get_hash(np3))90 self.assertNotEqual(get_hash(np1), get_hash(np2))91 np4 = np.zeros(NP_SIZE_LARGE)92 np5 = np.zeros(NP_SIZE_LARGE)93 self.assertEqual(get_hash(np4), get_hash(np5))94 def test_partial(self):95 p1 = functools.partial(int, base=2)96 p2 = functools.partial(int, base=3)97 p3 = functools.partial(int, base=2)98 self.assertEqual(get_hash(p1), get_hash(p3))99 self.assertNotEqual(get_hash(p1), get_hash(p2))100 def test_lambdas(self):101 # self.assertEqual(get_hash(lambda x: x.lower()), get_hash(lambda x: x.lower()))102 self.assertNotEqual(103 get_hash(lambda x: x.lower()), get_hash(lambda x: x.upper())104 )105 def test_files(self):106 temp1 = tempfile.NamedTemporaryFile()107 temp2 = tempfile.NamedTemporaryFile()108 with open(__file__, "r") as f:109 with open(__file__, "r") as g:110 self.assertEqual(get_hash(f), get_hash(g))111 self.assertNotEqual(get_hash(f), get_hash(temp1))112 self.assertEqual(get_hash(temp1), get_hash(temp1))113 self.assertNotEqual(get_hash(temp1), get_hash(temp2))114 def test_file_position(self):115 with open(__file__, "r") as f:116 h1 = get_hash(f)117 self.assertEqual(h1, get_hash(f))118 f.readline()119 self.assertNotEqual(h1, get_hash(f))120 f.seek(0)121 self.assertEqual(h1, get_hash(f))122 def test_magic_mock(self):123 """Test that MagicMocks never hash to the same thing."""124 # (This also tests that MagicMock can hash at all, without blowing the125 # stack due to an infinite recursion.)126 self.assertNotEqual(get_hash(MagicMock()), get_hash(MagicMock()))127class CodeHashTest(unittest.TestCase):128 def test_simple(self):129 """Test the hash of simple functions."""130 def f(x):131 return x * x132 def g(x):133 return x + x134 def h(x):135 return x * x136 self.assertNotEqual(get_hash(f), get_hash(g))137 self.assertEqual(get_hash(f), get_hash(h))138 def test_rename(self):139 """Test the hash of function with renamed variables."""140 def f(x, y):141 return x + y142 def g(x, y):143 return y + x144 def h(y, x):145 return y + x146 self.assertNotEqual(get_hash(f), get_hash(g))147 self.assertEqual(get_hash(f), get_hash(h))148 def test_value(self):149 """Test the hash of functions with values."""150 def f():151 x = 42152 return x153 def g():154 x = 12155 return x156 def h():157 y = 42158 return y159 self.assertNotEqual(get_hash(f), get_hash(g))160 self.assertEqual(get_hash(f), get_hash(h))161 def test_defaults(self):162 """Test the hash of functions with defaults."""163 def f(x=42):164 return x165 def g(x=12):166 return x167 def h(x=42):168 return x169 self.assertNotEqual(get_hash(f), get_hash(g))170 self.assertEqual(get_hash(f), get_hash(h))171 def test_referenced(self):172 """Test the hash of functions that reference values."""173 x = 42174 y = 123175 def f():176 return x177 def g():178 return y179 def h():180 return x181 self.assertNotEqual(get_hash(f), get_hash(g))182 self.assertEqual(get_hash(f), get_hash(h))183 def test_referenced_referenced(self):184 """Test that we can follow references."""185 def hash_prog_1():186 x = 12187 def g():188 return x189 def f():190 return g()191 return get_hash(f)192 def hash_prog_2():193 x = 42194 def g():195 return x196 def f():197 return g()198 return get_hash(f)199 self.assertNotEqual(hash_prog_1(), hash_prog_2())200 def test_builtins(self):201 """Tes code with builtins."""202 def code_with_print():203 print(12)204 def code_with_type():205 type(12)206 self.assertNotEqual(get_hash(code_with_print), get_hash(code_with_type))207 def test_pandas_df(self):208 """Test code that references pandas dataframes."""209 def hash_prog_1():210 df = pd.DataFrame({"foo": [12]})211 def f():212 return df213 return get_hash(f)214 def hash_prog_2():215 df = pd.DataFrame({"foo": [42]})216 def f():217 return df218 return get_hash(f)219 def hash_prog_3():220 df = pd.DataFrame({"foo": [12]})221 def f():222 return df223 return get_hash(f)224 self.assertNotEqual(hash_prog_1(), hash_prog_2())225 self.assertEqual(hash_prog_1(), hash_prog_3())226 def test_lambdas(self):227 """Test code with different lambdas produces different hashes."""228 v42 = 42229 v123 = 123230 def f1():231 lambda x: v42232 def f2():233 lambda x: v123234 self.assertNotEqual(get_hash(f1), get_hash(f2))235 def test_lambdas_calls(self):236 """Test code with lambdas that call functions."""237 def f_lower():238 lambda x: x.lower()239 def f_upper():240 lambda x: x.upper()241 def f_lower2():242 lambda x: x.lower()243 self.assertNotEqual(get_hash(f_lower), get_hash(f_upper))244 self.assertEqual(get_hash(f_lower), get_hash(f_lower2))245 def test_dict_reference(self):246 """Test code with lambdas that call a dictionary."""247 a = {"foo": 42, "bar": {"baz": 12}}248 def f():249 return a["bar"]["baz"]250 def g():251 return a["foo"]252 def h():253 return a["bar"]["baz"]254 self.assertNotEqual(get_hash(f), get_hash(g))255 self.assertEqual(get_hash(f), get_hash(h))256 def test_external_module(self):257 """Test code that references an external module."""258 def call_altair_concat():259 return alt.vegalite.v3.api.concat()260 def call_altair_layer():261 return alt.vegalite.v3.api.layer()262 self.assertNotEqual(get_hash(call_altair_concat), get_hash(call_altair_layer))263 def test_import(self):264 """Test code that imports module."""265 def f():266 import numpy267 return numpy268 def g():269 import pandas270 return pandas271 def n():272 import foobar273 return foobar274 self.assertNotEqual(get_hash(f), get_hash(g))275 self.assertNotEqual(get_hash(f), get_hash(n))276 def test_class(self):277 """Test hash for classes is we call different functions."""278 x = 12279 y = 13280 class Foo:281 def get_x(self):282 return x283 def get_y(self):284 return y285 def hash_prog_1():286 o = Foo()287 def f():288 return o.get_x()289 return get_hash(f)290 def hash_prog_2():291 o = Foo()292 def f():293 return o.get_y()294 return get_hash(f)295 def hash_prog_3():296 o = Foo()297 def f():298 return o.get_x()299 return get_hash(f)300 self.assertNotEqual(hash_prog_1(), hash_prog_2())301 self.assertEqual(hash_prog_1(), hash_prog_3())302 @pytest.mark.skipif(sys.version_info < (3,), reason="Requires Python 3.")303 def test_class_referenced(self):304 """Test hash for classes with methods that reference values."""305 def hash_prog_1():306 class Foo:307 x = 12308 def get_x(self):309 return self.x310 o = Foo()311 def f():312 return o.get_x()313 return get_hash(f)314 def hash_prog_2():315 class Foo:316 x = 42317 def get_x(self):318 return self.x319 o = Foo()320 def f():321 return o.get_x()322 return get_hash(f)323 self.assertNotEqual(hash_prog_1(), hash_prog_2())324 def test_coref(self):325 """Test code that references itself."""326 def f(x):327 return f(x)328 def g(x):329 return g(x) + 1330 def h(x):331 return h(x)332 self.assertNotEqual(get_hash(f), get_hash(g))333 self.assertEqual(get_hash(f), get_hash(h))334 def test_multiple(self):335 """Test code that references multiple objects."""336 x = 12337 y = 13338 z = 14339 def f():340 return x + z341 def g():342 return y + z343 def h():344 return x + z345 self.assertNotEqual(get_hash(f), get_hash(g))346 self.assertEqual(get_hash(f), get_hash(h))347 def test_decorated(self):348 """Test decorated functions."""349 def do(func):350 @functools.wraps(func)351 def wrapper_do(*args, **kwargs):352 return func(*args, **kwargs)353 return wrapper_do354 @do355 def f():356 return 42357 @do358 def g():359 return 12360 @do361 def h():362 return 42363 self.assertNotEqual(get_hash(f), get_hash(g))364 self.assertEqual(get_hash(f), get_hash(h))365 def test_cached(self):366 """Test decorated functions."""367 @st.cache368 def f():369 return 42370 @st.cache371 def g():372 return 12373 @st.cache374 def h():375 return 42376 self.assertNotEqual(get_hash(f), get_hash(g))377 self.assertEqual(get_hash(f), get_hash(h))378 def test_streamlit(self):379 """Test hashing streamlit functions."""380 def f():381 st.write("Hello")382 def g():383 st.write("World")384 def h():385 st.write("Hello")386 self.assertNotEqual(get_hash(f), get_hash(g))387 self.assertEqual(get_hash(f), get_hash(h))388 def test_higher_order(self):389 """Test hashing higher order functions."""390 def f(x):391 def func(v):392 return v ** x393 return func394 def g(x):395 def func(v):396 return v * x397 return func398 def h(x):399 def func(v):400 return v ** x401 return func402 self.assertNotEqual(get_hash(f), get_hash(g))403 # TODO: Enable test. f and h are not the same since the co_consts404 # contains the name of the function in the closure....

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful