How to use get_original method in autotest

Best Python code snippet using autotest_python

utils_test.py

Source:utils_test.py Github

copy

Full Screen

...26 mock.patch('open_note_scanner.utils.debug'),27 ]28 for mocked_item in self.patches:29 mocked_item.start()30 self.patches[0].get_original()[0].path.join.side_effect = simple_join31 self.patches[0].get_original()[0].makedirs.return_value = True32 self.patches[0].get_original()[0].path.exists.return_value = True33 self.patches[0].get_original()[0].remove.return_value = True34 # Assign a different value to the utils constant35 self.patches[1].get_original()[0].return_value = self.pdf_dir36 self.patches[2].get_original()[0].return_value = self.qr_dir37 def test_create_directory(self):38 """39 Check that the `utils.create_directory` function work as expected.40 """41 obtained = utils.create_directory(self.thread_id)42 self.assertTrue(obtained, msg=f"Expected: {True}, Obtained: {obtained}")43 self.patches[3].get_original()[0].assert_called()44 def test_create_directory_abnormal(self):45 """46 Check that the `utils.create_directory` function work as expected.47 """48 # Mock all side effects and return values for the os.path module.49 self.patches[0].get_original()[0].path.exists.return_value = False50 obtained = utils.create_directory(self.thread_id)51 self.assertTrue(obtained, msg=f"Expected: {True}, Obtained: {obtained}")52 self.patches[3].get_original()[0].assert_called()53 def test_delete_images(self):54 """55 Check that the `utils.delete_images` function work as expected.56 """57 # Mock all side effects and return values for the os.path module.58 self.patches[0].get_original()[0].path.abspath.return_value = f"{self.qr_dir}/{str(self.thread_id)}"59 self.patches[0].get_original()[0].listdir.return_value = self.image_list60 utils.delete_images(self.thread_id, True)61 self.patches[0].get_original()[0].remove.assert_called()62 def test_delete_images_abnormal(self):63 """64 Check that the `utils.delete_images` function work as expected.65 """66 # Mock all side effects and return values for the os.path module.67 self.patches[0].get_original()[0].path.abspath.return_value = f"{self.qr_dir}/{str(self.thread_id)}"68 self.patches[0].get_original()[0].path.exists.return_value = False69 utils.delete_images(self.thread_id, True)70 self.patches[0].get_original()[0].remove.assert_not_called()71 def test_delete_pdfs(self):72 """73 Check that the `utils.delete_pdfs` function work as expected.74 """75 # Mock all side effects and return values for the os.path module.76 self.patches[0].get_original()[0].listdir.return_value = self.pdf_list77 self.patches[0].get_original()[0].path.abspath.return_value = f"{self.pdf_dir}/{str(self.thread_id)}"78 try:79 utils.delete_pdfs(self.thread_id, bln_delete=True)80 except Exception:81 self.fail(msg="The method `utils.delete_pdfs` should have raised an exception.")82 def test_delete_pdfs_abnormal(self):83 """84 Check that the `utils.delete_pdfs` function work as expected.85 """86 # Mock all side effects and return values for the os.path module.87 self.patches[0].get_original()[0].path.exists.return_value = False88 self.patches[0].get_original()[0].path.abspath.return_value = f"{self.pdf_dir}/{str(self.thread_id)}"89 try:90 utils.delete_pdfs(self.thread_id, bln_delete=True)91 except Exception:92 self.fail(msg="The method `utils.delete_pdfs` should have raised an exception.")93 def test_sort_alphanumeric_list(self):94 """95 Check that the `utils.sort_alphanumeric_list` function work as expected.96 """97 expected = ['aaa', 'ahola1', 'bba', 'hola', 'hola1', 'hola2']98 for unsorted_list in permutations(['hola1', 'hola2', 'ahola1', 'hola', 'aaa', 'bba']):99 obtained = utils.sort_alphanumeric_list(list(unsorted_list))...

Full Screen

Full Screen

nogevent.py

Source:nogevent.py Github

copy

Full Screen

...7from ddtrace.internal import forksafe8try:9 import gevent.monkey10except ImportError:11 def get_original(module, func):12 return getattr(__import__(module), func)13 def is_module_patched(module):14 return False15else:16 get_original = gevent.monkey.get_original17 is_module_patched = gevent.monkey.is_module_patched18sleep = get_original("time", "sleep")19try:20 # Python ≥ 3.821 threading_get_native_id = get_original("threading", "get_native_id")22except AttributeError:23 threading_get_native_id = None24start_new_thread = get_original(six.moves._thread.__name__, "start_new_thread")25thread_get_ident = get_original(six.moves._thread.__name__, "get_ident")26Thread = get_original("threading", "Thread")27Lock = get_original("threading", "Lock")28is_threading_patched = is_module_patched("threading")29if is_threading_patched:30 @attr.s31 class DoubleLock(object):32 """A lock that prevent concurrency from a gevent coroutine and from a threading.Thread at the same time."""33 # This is a gevent-patched threading.Lock (= a gevent Lock)34 _lock = attr.ib(factory=forksafe.Lock, init=False, repr=False)35 # This is a unpatched threading.Lock (= a real threading.Lock)36 _thread_lock = attr.ib(factory=lambda: forksafe.ResetObject(Lock), init=False, repr=False)37 def acquire(self):38 # type: () -> None39 # You cannot acquire a gevent-lock from another thread if it has been acquired already:40 # make sure we exclude the gevent-lock from being acquire by another thread by using a thread-lock first.41 self._thread_lock.acquire()...

Full Screen

Full Screen

controller_test.py

Source:controller_test.py Github

copy

Full Screen

...18 qr_data = 'Testing data'19 pages = 2520 pdf_route = 'crazy/route/to/pdf/great.pdf'21 # Mock the actual generation of the pdf file.22 self._patches[0].get_original()[0].return_value = mock.MagicMock()23 self._patches[0].get_original()[0].return_value.generate_pdf.return_value = pdf_route24 # Mock function calls to the os module.25 self._patches[1].get_original()[0].path.basename.return_value = pdf_route.split('/')[-1]26 self._patches[1].get_original()[0].path.dirname.return_value = '/'.join(27 pdf_route.split('/')[:-1]28 )29 # Mock the deletion of file.30 self._patches[2].get_original()[0].return_value = True31 filename, file_dir = controller.generate_pdf(size, qr_data, pages)32 self.assertEqual(33 pdf_route.split('/')[-1],34 filename,35 f"Expected: {pdf_route.split('/')[-1]}, Obtained: {filename}")36 self.assertEqual(37 '/'.join(pdf_route.split('/')[:-1]),38 file_dir,...

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 autotest 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