How to use test_environment method in localstack

Best Python code snippet using localstack_python

context_stack_test_utils_test.py

Source:context_stack_test_utils_test.py Github

copy

Full Screen

...28 context_stack_test_utils.TestContext(),29 []),30 ('context_and_1_environment',31 context_stack_test_utils.TestContext(),32 [context_stack_test_utils.test_environment()]),33 ('context_and_3_environment',34 context_stack_test_utils.TestContext(),35 [36 context_stack_test_utils.test_environment(),37 context_stack_test_utils.test_environment(),38 context_stack_test_utils.test_environment(),39 ]),40 )41 # pyformat: enable42 def test_with_context_fn_no_arg(self, context, environments):43 context_fn = lambda: context44 environment_fn = None if environments is None else lambda: environments45 @context_stack_test_utils.with_context(context_fn, environment_fn)46 def _foo():47 self.assertEqual(context_stack_impl.context_stack.current, context)48 with mock.patch.object(contextlib.ExitStack,49 'enter_context') as mock_enter_context:50 # Assert that the context is installed.51 self.assertNotEqual(context_stack_impl.context_stack.current, context)52 _foo()53 self.assertNotEqual(context_stack_impl.context_stack.current, context)54 # Assert that `enter_context` is called with the expected environment.55 if environments is not None:56 calls = [mock.call(e) for e in environments]57 self.assertLen(mock_enter_context.mock_calls, len(calls))58 mock_enter_context.assert_has_calls(calls)59 # pyformat: disable60 @parameterized.named_parameters(61 ('context_and_no_environment',62 context_stack_test_utils.TestContext(),63 None),64 ('context_and_empty_environment',65 context_stack_test_utils.TestContext(),66 []),67 ('context_and_1_environment',68 context_stack_test_utils.TestContext(),69 [context_stack_test_utils.test_environment()]),70 ('context_and_3_environment',71 context_stack_test_utils.TestContext(),72 [73 context_stack_test_utils.test_environment(),74 context_stack_test_utils.test_environment(),75 context_stack_test_utils.test_environment(),76 ]),77 )78 # pyformat: enable79 def test_with_context_fn_args(self, context, environments):80 context_fn = lambda: context81 environment_fn = None if environments is None else lambda: environments82 @context_stack_test_utils.with_context(context_fn, environment_fn)83 def _foo(x):84 del x # Unused.85 self.assertEqual(context_stack_impl.context_stack.current, context)86 with mock.patch.object(contextlib.ExitStack,87 'enter_context') as mock_enter_context:88 # Assert that the context is installed.89 self.assertNotEqual(context_stack_impl.context_stack.current, context)90 _foo(1)91 self.assertNotEqual(context_stack_impl.context_stack.current, context)92 # Assert that `enter_context` is called with the expected environment.93 if environments is not None:94 calls = [mock.call(e) for e in environments]95 self.assertLen(mock_enter_context.mock_calls, len(calls))96 mock_enter_context.assert_has_calls(calls)97 # pyformat: disable98 @parameterized.named_parameters(99 ('context_and_no_environment',100 context_stack_test_utils.TestContext(),101 None),102 ('context_and_empty_environment',103 context_stack_test_utils.TestContext(),104 []),105 ('context_and_1_environment',106 context_stack_test_utils.TestContext(),107 [context_stack_test_utils.test_environment()]),108 ('context_and_3_environment',109 context_stack_test_utils.TestContext(),110 [111 context_stack_test_utils.test_environment(),112 context_stack_test_utils.test_environment(),113 context_stack_test_utils.test_environment(),114 ]),115 )116 # pyformat: enable117 def test_with_context_fn_kwargs(self, context, environments):118 context_fn = lambda: context119 environment_fn = None if environments is None else lambda: environments120 @context_stack_test_utils.with_context(context_fn, environment_fn)121 def _foo(x):122 del x # Unused.123 self.assertEqual(context_stack_impl.context_stack.current, context)124 with mock.patch.object(contextlib.ExitStack,125 'enter_context') as mock_enter_context:126 # Assert that the context is installed.127 self.assertNotEqual(context_stack_impl.context_stack.current, context)128 _foo(x=1)129 self.assertNotEqual(context_stack_impl.context_stack.current, context)130 # Assert that `enter_context` is called with the expected environment.131 if environments is not None:132 calls = [mock.call(e) for e in environments]133 self.assertLen(mock_enter_context.mock_calls, len(calls))134 mock_enter_context.assert_has_calls(calls)135 # pyformat: disable136 @parameterized.named_parameters(137 ('context_and_no_environment',138 context_stack_test_utils.TestContext(),139 None),140 ('context_and_empty_environment',141 context_stack_test_utils.TestContext(),142 []),143 ('context_and_1_environment',144 context_stack_test_utils.TestContext(),145 [context_stack_test_utils.test_environment()]),146 ('context_and_3_environment',147 context_stack_test_utils.TestContext(),148 [149 context_stack_test_utils.test_environment(),150 context_stack_test_utils.test_environment(),151 context_stack_test_utils.test_environment(),152 ]),153 )154 # pyformat: enable155 def test_with_context_fn_return(self, context, environments):156 context_fn = lambda: context157 environment_fn = None if environments is None else lambda: environments158 @context_stack_test_utils.with_context(context_fn, environment_fn)159 def _foo(x):160 self.assertEqual(context_stack_impl.context_stack.current, context)161 return x162 with mock.patch.object(contextlib.ExitStack,163 'enter_context') as mock_enter_context:164 # Assert that the context is installed.165 self.assertNotEqual(context_stack_impl.context_stack.current, context)166 x = _foo(1)167 self.assertNotEqual(context_stack_impl.context_stack.current, context)168 # Assert that `enter_context` is called with the expected environment.169 if environments is not None:170 calls = [mock.call(e) for e in environments]171 self.assertLen(mock_enter_context.mock_calls, len(calls))172 mock_enter_context.assert_has_calls(calls)173 # Assert that the return value is returned by the decorator.174 self.assertEqual(x, 1)175 # pyformat: disable176 @parameterized.named_parameters(177 ('context_and_no_environment',178 context_stack_test_utils.TestContext(),179 None),180 ('context_and_empty_environment',181 context_stack_test_utils.TestContext(),182 []),183 ('context_and_1_environment',184 context_stack_test_utils.TestContext(),185 [context_stack_test_utils.test_environment()]),186 ('context_and_3_environments',187 context_stack_test_utils.TestContext(),188 [189 context_stack_test_utils.test_environment(),190 context_stack_test_utils.test_environment(),191 context_stack_test_utils.test_environment(),192 ]),193 )194 # pyformat: enable195 def test_with_context_test(self, context, environments):196 context_fn = lambda: context197 environment_fn = None if environments is None else lambda: environments198 class _FooTest(absltest.TestCase):199 @context_stack_test_utils.with_context(context_fn, environment_fn)200 def test_foo(self):201 self.assertEqual(context_stack_impl.context_stack.current, context)202 def test_bar(self):203 self.assertNotEqual(context_stack_impl.context_stack.current, context)204 with mock.patch.object(contextlib.ExitStack,205 'enter_context') as mock_enter_context:206 # Assert that the context is installed.207 self.assertNotEqual(context_stack_impl.context_stack.current, context)208 suite = unittest.defaultTestLoader.loadTestsFromTestCase(_FooTest)209 runner = unittest.TextTestRunner()210 result = runner.run(suite)211 self.assertNotEqual(context_stack_impl.context_stack.current, context)212 # Assert that `enter_context` is called with the expected environment.213 if environments is not None:214 calls = [mock.call(e) for e in environments]215 self.assertLen(mock_enter_context.mock_calls, len(calls))216 mock_enter_context.assert_has_calls(calls)217 # Assert that the test passes with the expected number of test cases.218 self.assertEqual(suite.countTestCases(), 2)219 self.assertEqual(result.testsRun, 2)220 self.assertTrue(result.wasSuccessful())221class WithContextsTest(parameterized.TestCase):222 def test_with_contexts(self):223 # context = context_stack_test_utils.TestContext()224 # context_fn = lambda: context225 # environments = [226 # context_stack_test_utils.test_environment(),227 # context_stack_test_utils.test_environment(),228 # context_stack_test_utils.test_environment(),229 # ]230 # environment_fn = lambda: environments231 def _context_fn():232 return context_stack_test_utils.TestContext()233 def _environment_fn():234 return [235 context_stack_test_utils.test_environment(),236 context_stack_test_utils.test_environment(),237 context_stack_test_utils.test_environment(),238 ]239 named_contexts = [240 ('1', _context_fn, _environment_fn),241 ('2', _context_fn, _environment_fn),242 ('3', _context_fn, _environment_fn),243 ]244 class _FooTest(parameterized.TestCase):245 @context_stack_test_utils.with_contexts(*named_contexts)246 def test_foo(self):247 pass248 def test_bar(self):249 pass250 with mock.patch.object(context_stack_test_utils,251 'with_context') as mock_with_context:...

Full Screen

Full Screen

test_process.py

Source:test_process.py Github

copy

Full Screen

1import os2import shutil3from unittest.mock import patch4import requests5from backend.corpora.common.corpora_orm import (6 ConversionStatus,7 UploadStatus,8 ValidationStatus,9)10from backend.corpora.common.entities import Dataset11from backend.corpora.dataset_processing.exceptions import (12 ProcessingFailed,13 ValidationFailed,14 ConversionFailed,15)16from backend.corpora.dataset_processing.process import main17from tests.unit.backend.fixtures.mock_aws_test_case import CorporaTestCaseUsingMockAWS18from tests.unit.backend.corpora.fixtures.environment_setup import EnvironmentSetup19class TestDatasetProcessing(CorporaTestCaseUsingMockAWS):20 """21 This test class is intended to exercise the upload pipeline processing, running within22 a "corpora-upload" (upload processing) Docker container. As the Docker container is configured23 with all necessary software dependencies, manually running this test outside of Docker24 (e.g. within an IDE when making changes to the test itself) will require you to:25 * set env vars: CORPORA_LOCAL_DEV=1;BOTO_ENDPOINT_URL=http://localhost:456626 * Locally install latest cellxgene-schema (via pip)27 * Install all the same Python dependencies at Dockerfile.processing_image:23 and Dockerfile.processing_base:1928 (R software) to ensure Seurat artifact can be generated. (These will only matter if we add test29 assertions to check these artifact's creation.)30 """31 @staticmethod32 def fixture_file_path(relative_filename):33 return os.path.abspath(os.path.join(os.path.dirname(__file__), relative_filename))34 @classmethod35 def setUpClass(cls):36 super().setUpClass()37 cls.h5ad_raw = cls.fixture_file_path("fixtures/2_0_0_raw_valid.h5ad")38 @staticmethod39 def download(url, local_filename):40 with requests.get(url, stream=True) as resp:41 resp.raise_for_status()42 with open(local_filename, "wb") as fp:43 for chunk in resp.iter_content(chunk_size=None):44 fp.write(chunk)45 @classmethod46 def tearDownClass(cls):47 super().tearDownClass()48 cls.clean_generated_files()49 @classmethod50 def clean_generated_files(cls):51 if os.path.exists("local.cxg"):52 shutil.rmtree("local.cxg")53 for f in ["local.h5ad", "local.rds"]:54 if os.path.exists(f):55 os.remove(f)56 @patch("backend.corpora.dataset_processing.process_download_validate.download_from_source_uri")57 @patch("backend.corpora.dataset_processing.remaster_cxg.process") # TODO: provide test data to properly test this.58 def test_main(self, mock_rematser_cxg_process, mock_download_from_source_uri):59 """60 Tests full pipeline for processing an uploaded H5AD file, including database updates61 generation and upload of all artifacts to S3 (localstack), but excluding the Dropbox download62 functionality. Dropbox I/O is mocked to prevent dependency on remote services (non-Dockerized).63 """64 mock_download_from_source_uri.return_value = self.h5ad_raw65 dataset = self.generate_dataset(self.session, collection_id="test_collection_id")66 test_environment = {67 "STEP_NAME": "cxg",68 "DROPBOX_URL": "https://www.dropbox.com/IGNORED",69 "ARTIFACT_BUCKET": self.corpora_config.bucket_name,70 "CELLXGENE_BUCKET": self.corpora_config.bucket_name,71 "DATASET_ID": dataset.id,72 "DEPLOYMENT_STAGE": "test",73 }74 test_environment["STEP_NAME"] = "download-validate"75 with EnvironmentSetup(test_environment):76 main()77 test_environment["STEP_NAME"] = "cxg"78 with EnvironmentSetup(test_environment):79 main()80 test_environment["STEP_NAME"] = "seurat"81 with EnvironmentSetup(test_environment):82 main()83 test_environment["STEP_NAME"] = "cxg_remaster"84 with EnvironmentSetup(test_environment):85 main()86 mock_rematser_cxg_process.assert_called()87 # TODO: add assertions. See https://app.zenhub.com/workspaces/single-cell-5e2a191dad828d52cc78b028/issues/chanzuckerberg/single-cell-data-portal/1449 # noqa: E50188 # 1. H5AD has annotation labels added and uploaded to S389 # 2. cxg, rds uploaded to s390 # 3. databases metadata updated and showing successful status91 @patch("backend.corpora.dataset_processing.process_cxg.process")92 @patch("backend.corpora.dataset_processing.process_seurat.process")93 @patch("backend.corpora.dataset_processing.process_download_validate.process")94 def test_main__Exceptions(self, mock_process_download_validate, mock_process_seurat, mock_process_cxg):95 test_environment = {96 "DROPBOX_URL": "https://www.dropbox.com/IGNORED",97 "ARTIFACT_BUCKET": self.corpora_config.bucket_name,98 "CELLXGENE_BUCKET": self.corpora_config.bucket_name,99 "DEPLOYMENT_STAGE": "test",100 }101 test_environment["STEP_NAME"] = "download-validate"102 with self.subTest("process step raises unknown exception with status dict"):103 mock_process_download_validate.side_effect = Exception(104 {"validation_status": ValidationStatus.INVALID, "validation_message": "Anndata could not open raw.h5ad"}105 )106 dataset = self.generate_dataset(self.session, collection_id="test_collection_id")107 test_environment["DATASET_ID"] = dataset.id108 with EnvironmentSetup(test_environment):109 main()110 expected_dataset = Dataset.get(self.session, test_environment["DATASET_ID"]).processing_status111 self.assertEqual(expected_dataset.validation_status, ValidationStatus.INVALID)112 self.assertEqual(expected_dataset.validation_message, "Anndata could not open raw.h5ad")113 with self.subTest("download-validate step raises unknown exception"):114 mock_process_download_validate.side_effect = Exception("unknown failure")115 dataset = self.generate_dataset(self.session, collection_id="test_collection_id")116 test_environment["DATASET_ID"] = dataset.id117 with EnvironmentSetup(test_environment):118 main()119 expected_dataset = Dataset.get(self.session, test_environment["DATASET_ID"]).processing_status120 self.assertEqual(expected_dataset.upload_status, UploadStatus.FAILED)121 self.assertEqual(expected_dataset.upload_message, "unknown failure")122 with self.subTest("download-validate step raises ValidationFailed"):123 mock_process_download_validate.side_effect = ValidationFailed(124 {"validation_status": ValidationStatus.INVALID, "validation_message": "Schema version is not supported"}125 )126 dataset = self.generate_dataset(self.session, collection_id="test_collection_id")127 test_environment["DATASET_ID"] = dataset.id128 with EnvironmentSetup(test_environment):129 main()130 expected_dataset = Dataset.get(self.session, test_environment["DATASET_ID"]).processing_status131 self.assertEqual(expected_dataset.validation_status, ValidationStatus.INVALID)132 self.assertEqual(expected_dataset.validation_message, "Schema version is not supported")133 with self.subTest("download-validate step raises ProcessingFailed"):134 mock_process_download_validate.side_effect = ProcessingFailed(135 {"upload_status": UploadStatus.FAILED, "upload_message": "Insufficient disk space"}136 )137 dataset = self.generate_dataset(self.session, collection_id="test_collection_id")138 test_environment["DATASET_ID"] = dataset.id139 with EnvironmentSetup(test_environment):140 main()141 expected_dataset = Dataset.get(self.session, test_environment["DATASET_ID"]).processing_status142 self.assertEqual(expected_dataset.upload_status, UploadStatus.FAILED)143 self.assertEqual(expected_dataset.upload_message, "Insufficient disk space")144 with self.subTest("seurat step raises unknown exception"):145 mock_process_seurat.side_effect = Exception("unknown failure")146 dataset = self.generate_dataset(self.session, collection_id="test_collection_id")147 test_environment["DATASET_ID"] = dataset.id148 test_environment["STEP_NAME"] = "seurat"149 with EnvironmentSetup(test_environment):150 main()151 expected_dataset = Dataset.get(self.session, test_environment["DATASET_ID"]).processing_status152 self.assertEqual(expected_dataset.rds_status, ConversionStatus.FAILED)153 with self.subTest("cxg step raises unknown exception"):154 mock_process_cxg.side_effect = Exception("unknown failure")155 dataset = self.generate_dataset(self.session, collection_id="test_collection_id")156 test_environment["DATASET_ID"] = dataset.id157 test_environment["STEP_NAME"] = "cxg"158 with EnvironmentSetup(test_environment):159 main()160 expected_dataset = Dataset.get(self.session, test_environment["DATASET_ID"]).processing_status161 self.assertEqual(expected_dataset.cxg_status, ConversionStatus.FAILED)162 with self.subTest("conversion step raises ConversionFailed"):163 mock_process_cxg.side_effect = ConversionFailed({"cxg_status": ConversionStatus.FAILED})164 dataset = self.generate_dataset(self.session, collection_id="test_collection_id")165 test_environment["DATASET_ID"] = dataset.id166 test_environment["STEP_NAME"] = "cxg"167 with EnvironmentSetup(test_environment):168 main()169 expected_dataset = Dataset.get(self.session, test_environment["DATASET_ID"]).processing_status...

Full Screen

Full Screen

start.py

Source:start.py Github

copy

Full Screen

1#!/usr/bin/python32# coding:utf-83import sys4sys.path.insert(0, "..")5import types6import unittest7import test_environment8import evalcache9import hashlib10class A:11 def __init__(self):12 self.i = 313 def summ(self, a, b, c, d):14 return a + b + c + d15 def __repr__(self):16 return "A" + str(self.i)17class TestLazy(unittest.TestCase):18 def tearDown(self):19 test_environment.clean()20 def test_arithmetic_full(self):21 a = test_environment.lazy(1)22 b = test_environment.lazy(2)23 c = test_environment.lazy(3)24 d = test_environment.lazy(4)25 count = (a + b + c).unlazy()26 total_objects = test_environment.count_cached_objects()27 self.assertEqual(count, 6)28 self.assertTrue(total_objects, 2) # 2 summ29 def test_arithmetic_part(self):30 a = test_environment.lazy(1)31 b = test_environment.lazy(2)32 c = test_environment.lazy(3)33 d = test_environment.lazy(4)34 count = (a + b + c + d).unlazy()35 total_objects = test_environment.count_cached_objects()36 self.assertEqual(count, 10)37 self.assertEqual(total_objects, 3) # 3 summ38 def test_twoargs(self):39 @test_environment.lazy40 def summ(a, b):41 return a + b42 summ(0, 0).unlazy()43 summ(0, 1).unlazy()44 summ(1, 1).unlazy()45 summ(1, 1).unlazy()46 summ(1, b=1).unlazy()47 summ(a=1, b=1).unlazy()48 summ(b=1, a=1).unlazy()49 total_objects = test_environment.count_cached_objects()50 self.assertEqual(total_objects, 5)51 def test_fibonachi(self):52 @test_environment.lazy53 def fib(n):54 if n < 2:55 return n56 return fib(n - 1) + fib(n - 2)57 ret = fib(9).unlazy()58 self.assertEqual(ret, 34)59 self.assertEqual(60 test_environment.count_cached_objects(), 1861 ) # range(0-9) and 8 summ62 # def test_method_strange(self):63 # A.lazy_sum = types.MethodType( test_environment.lazy(A.summ), A )64 # ret = A.lazy_sum(1,2,3,d=4)65 # self.assertEqual(ret.unlazy(), 10)66 def test_method(self):67 class Cls:68 def get_three(self):69 return 370 def __repr__(self):71 return "Cls"72 Cls.get_three = test_environment.lazy(Cls.get_three)73 a = Cls()74 self.assertEqual(a.get_three().unlazy(), 3)75 def test_getattr(self):76 lazy = evalcache.Lazy(cache={})77 class Cls:78 def __init__(self):79 self.i = 380 def __repr__(self):81 return "Cls"82 Cls = lazy(Cls)83 a = Cls()84 self.assertEqual(a.i.unlazy(), 3)85 def test_getlazyattr(self):86 lazy = evalcache.LazyHash()87 class Cls:88 def __init__(self):89 self.i = 390 def foo(self):91 return 492 Cls.foo = lazy(Cls.foo)93 Cls = lazy(Cls)94 a = Cls()95 self.assertEqual(a.i.unlazy(), 3)96 self.assertEqual(a.foo().unlazy(), 4)97class TestMemoize(unittest.TestCase):98 def tearDown(self):99 test_environment.clean_memoize()100 def test_arithmetic(self):101 @test_environment.memoize102 def maker(n):103 return n104 a = test_environment.memoize(1)105 b = test_environment.memoize(2)106 c = maker(3)107 d = maker(4)108 self.assertEqual(len(test_environment.memoize.cache), 0) # no unlazy yet109 count = a + b + c + d110 self.assertEqual(len(test_environment.memoize.cache), 5) # c, d and 3 summ111 self.assertEqual(count, 10)112 def test_fibonachi(self):113 @test_environment.memoize114 def fib(n):115 if n < 2:116 return n117 return fib(n - 1) + fib(n - 2)118 ret = fib(9)119 self.assertEqual(ret, 34)120 self.assertEqual(121 len(test_environment.memoize.cache), 19122 ) # range(0-9) and 9 summ and eq(assertEqual)123class TestOnplaceMemoize(unittest.TestCase):124 def tearDown(self):125 test_environment.clean_onplace_memoize()126 def test_arithmetic(self):127 @test_environment.onplace_memoize128 def maker(n):129 return n130 a = test_environment.onplace_memoize(1)131 b = test_environment.onplace_memoize(2)132 c = maker(3)133 d = maker(4)134 self.assertEqual(len(test_environment.onplace_memoize.cache), 2) # c, d135 count = a + b + c + d136 self.assertEqual(len(test_environment.onplace_memoize.cache), 3) # c, d and a+b137 self.assertEqual(count, 10)138 def test_fibonachi(self):139 @test_environment.onplace_memoize140 def fib(n):141 if n < 2:142 return n143 return fib(n - 1) + fib(n - 2)144 self.assertEqual(fib(9), 34)145 self.assertEqual(len(test_environment.onplace_memoize.cache), 10) # range(0-9)146class TestOptions(unittest.TestCase):147 def tearDown(self):148 test_environment.clean_onplace_memoize()149 def test_function_dump(self):150 nlazy = evalcache.Lazy(151 cache=evalcache.DirCache(test_environment.dircache_path),152 function_dump=False,153 onplace=True,154 )155 flazy = evalcache.Lazy(156 cache=evalcache.DirCache(test_environment.dircache_path),157 function_dump=True,158 onplace=True,159 )160 lmb_1 = lambda: 1161 lmb_2 = lambda: 2162 nlazy_11 = nlazy(lmb_1, hint="a")()163 nlazy_12 = nlazy(lmb_2, hint="b")()164 nlazy_21 = nlazy(lmb_1)()165 nlazy_22 = nlazy(lmb_2)()166 flazy_11 = flazy(lmb_1, hint="a")()167 flazy_12 = flazy(lmb_2, hint="b")()168 flazy_21 = flazy(lmb_1)()169 flazy_22 = flazy(lmb_2)()170 self.assertNotEqual(nlazy_11, nlazy_12)171 self.assertEqual(nlazy_21, nlazy_22)172 self.assertNotEqual(flazy_11, flazy_12)173 self.assertNotEqual(flazy_21, flazy_22)174class TestAtackStability(unittest.TestCase):175 def tearDown(self):176 test_environment.clean_onplace_memoize()177 def test_function_dump(self):178 nlazy = evalcache.Lazy(179 cache=evalcache.DirCache(test_environment.dircache_path),180 function_dump=False,181 onplace=True,182 )183 184 self.assertNotEqual(185 nlazy((1,10)).__lazyhash__,186 nlazy("<class 'tuple'><splitter>01<splitter>110").__lazyhash__187 )188 self.assertNotEqual(189 nlazy(("<splitter>01<splitter>210,",)).__lazyhash__,190 nlazy((1,10)).__lazyhash__191 )192class TestUnpacking(unittest.TestCase):193 def tearDown(self):194 test_environment.clean_onplace_memoize()195 def test_aaa(self):196 nlazy = evalcache.Lazy(197 cache=evalcache.DirCache(test_environment.dircache_path),198 encache=False,199 )200 class Cls:201 def get_three(self):202 return 3203 def __repr__(self):204 return "Cls"205 def __getitem__(self, i):206 return i207 def __len__(self):208 return 2209 @nlazy210 def foo():211 return Cls()212 a, b = foo()213class TestCachedOperations(unittest.TestCase):214 def tearDown(self):215 test_environment.clean()216 def test_cached_operations(self):217 nlazy = evalcache.Lazy(218 cache=evalcache.DirCache(test_environment.dircache_path),219 )220 i = nlazy(3)221 print(float(i))222 self.assertEqual(i, 3)223 #self.assertEqual(i, 3)224class TestDirCacheClean(unittest.TestCase):225 def tearDown(self):226 test_environment.clean()227 test_environment.full_clean()228 def test_cached_operations(self):229 nlazy = evalcache.Lazy(230 cache=evalcache.DirCache_v2(test_environment.dircache_path2),231 )232def cont_test():233 nlazy = evalcache.Memoize(algo = hashlib.sha512)234 s = {}235 for i in range(0,100):236 for j in range(0,100):237 h = nlazy((i,j)).__lazyhash__238 if h in s:239 print("FAULT:", (i,j), "equal", s[h])240 return241 s[h] = (i,j)242if __name__ == "__main__":243 test_environment.clean()244 cont_test()...

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