How to use test_get_image method in tempest

Best Python code snippet using tempest_python

test_image_source.py

Source:test_image_source.py Github

copy

Full Screen

2import os3import unittest4from unittest.mock import patch, Mock5class LocalImageTest(unittest.TestCase):6 def test_get_image(self):7 from lgtm.image_source import LocalImage8 path = os.path.dirname(__file__) + '/data/test_image.jpg'9 with LocalImage(path).get_image() as f:10 actual = f.read()11 with open(path, 'rb') as f:12 expected = f.read()13 self.assertEqual(expected, actual)14class RemoteImageTest(unittest.TestCase):15 def test_get_image(self):16 from lgtm.image_source import RemoteImage17 url = 'https://raw.githubusercontent.com/rhoboro/lgtm/master/tests/data/test_image.jpg'18 with RemoteImage(url).get_image() as f:19 actual = f.read()20 path = os.path.dirname(__file__) + '/data/test_image.jpg'21 with open(path, 'rb') as f:22 expected = f.read()23 self.assertEqual(expected, actual)24class KeywordImageTest(unittest.TestCase):25 def test_get_image(self):26 from lgtm.image_source import KeywordImage27 with patch('lgtm.image_source.requests.get') as mock:28 path = os.path.dirname(__file__) + '/data/test_image.jpg'29 with open(path, 'rb') as f:30 expected = f.read()31 response = Mock()32 response.content = expected33 mock.return_value = response34 with KeywordImage('dog').get_image() as f:35 actual = f.read()36 self.assertEqual(expected, actual)37 # 意図通りの URL を参照していることを確認38 mock.assert_called_once_with('https://loremflickr.com/800/600/dog')39class ImageSourceTest(unittest.TestCase):40 def test_http(self):41 from lgtm.image_source import ImageSource, RemoteImage42 # RemoteImage が意図通りに動くことを確認43 actual = ImageSource('http://www.example.com')44 self.assertEqual(RemoteImage, type(actual))45 def test_https(self):46 from lgtm.image_source import ImageSource, RemoteImage47 # RemoteImage が意図通りに動くことを確認48 actual = ImageSource('https://www.example.com')49 self.assertEqual(RemoteImage, type(actual))50 def test_localpath(self):51 from lgtm.image_source import ImageSource, LocalImage52 # LocalImage が意図通りに動くことを確認53 path = os.path.dirname(__file__) + '/data/test_image.jpg'54 actual = ImageSource(path)55 self.assertEqual(LocalImage, type(actual))56 def test_keyword(self):57 from lgtm.image_source import ImageSource, KeywordImage58 # KeywordImage が意図通り動くことを確認59 actual = ImageSource('dog')60 self.assertEqual(KeywordImage, type(actual))61class GetImageTest(unittest.TestCase):62 def test_get_image(self):63 from lgtm.image_source import get_image64 # get_image が一度の呼び出しで一度のみ動作していることの確認65 with patch('lgtm.image_source.ImageSource') as mock:66 get_image('dog')...

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