How to use fake_view method in pytest-django

Best Python code snippet using pytest-django_python

test_AxisItem.py

Source:test_AxisItem.py Github

copy

Full Screen

1import pyqtgraph as pg2app = pg.mkQApp()3def test_AxisItem_stopAxisAtTick(monkeypatch):4 def test_bottom(p, axisSpec, tickSpecs, textSpecs):5 assert view.mapToView(axisSpec[1]).x() == 0.256 assert view.mapToView(axisSpec[2]).x() == 0.757 def test_left(p, axisSpec, tickSpecs, textSpecs):8 assert view.mapToView(axisSpec[1]).y() == 0.8759 assert view.mapToView(axisSpec[2]).y() == 0.12510 plot = pg.PlotWidget()11 view = plot.plotItem.getViewBox()12 bottom = plot.getAxis("bottom")13 bottom.setRange(0, 1)14 bticks = [(0.25, "a"), (0.6, "b"), (0.75, "c")]15 bottom.setTicks([bticks, bticks])16 bottom.setStyle(stopAxisAtTick=(True, True))17 monkeypatch.setattr(bottom, "drawPicture", test_bottom)18 left = plot.getAxis("left")19 lticks = [(0.125, "a"), (0.55, "b"), (0.875, "c")]20 left.setTicks([lticks, lticks])21 left.setRange(0, 1)22 left.setStyle(stopAxisAtTick=(True, True))23 monkeypatch.setattr(left, "drawPicture", test_left)24 plot.show()25 app.processEvents()26 plot.close()27def test_AxisItem_viewUnlink():28 plot = pg.PlotWidget()29 view = plot.plotItem.getViewBox()30 axis = plot.getAxis("bottom")31 assert axis.linkedView() == view32 axis.unlinkFromView()33 assert axis.linkedView() is None34class FakeSignal:35 def __init__(self):36 self.calls = []37 def connect(self, *args, **kwargs):38 self.calls.append('connect')39 def disconnect(self, *args, **kwargs):40 self.calls.append('disconnect')41class FakeView:42 def __init__(self):43 self.sigYRangeChanged = FakeSignal()44 self.sigXRangeChanged = FakeSignal()45 self.sigResized = FakeSignal()46def test_AxisItem_bottomRelink():47 axis = pg.AxisItem('bottom')48 fake_view = FakeView()49 axis.linkToView(fake_view)50 assert axis.linkedView() == fake_view51 assert fake_view.sigYRangeChanged.calls == []52 assert fake_view.sigXRangeChanged.calls == ['connect']53 assert fake_view.sigResized.calls == ['connect']54 axis.unlinkFromView()55 assert fake_view.sigYRangeChanged.calls == []56 assert fake_view.sigXRangeChanged.calls == ['connect', 'disconnect']57 assert fake_view.sigResized.calls == ['connect', 'disconnect']58def test_AxisItem_leftRelink():59 axis = pg.AxisItem('left')60 fake_view = FakeView()61 axis.linkToView(fake_view)62 assert axis.linkedView() == fake_view63 assert fake_view.sigYRangeChanged.calls == ['connect']64 assert fake_view.sigXRangeChanged.calls == []65 assert fake_view.sigResized.calls == ['connect']66 axis.unlinkFromView()67 assert fake_view.sigYRangeChanged.calls == ['connect', 'disconnect']68 assert fake_view.sigXRangeChanged.calls == []...

Full Screen

Full Screen

test_urls.py

Source:test_urls.py Github

copy

Full Screen

...16def test_urls_cache_is_cleared(testdir):17 testdir.makepyfile(18 myurls="""19 from django.conf.urls import url20 def fake_view(request):21 pass22 urlpatterns = [url(r'first/$', fake_view, name='first')]23 """24 )25 testdir.makepyfile(26 """27 try:28 from django.urls import reverse, NoReverseMatch29 except ImportError: # Django < 2.030 from django.core.urlresolvers import reverse, NoReverseMatch31 import pytest32 @pytest.mark.urls('myurls')33 def test_something():34 reverse('first')35 def test_something_else():36 with pytest.raises(NoReverseMatch):37 reverse('first')38 """39 )40 result = testdir.runpytest_subprocess()41 assert result.ret == 042def test_urls_cache_is_cleared_and_new_urls_can_be_assigned(testdir):43 testdir.makepyfile(44 myurls="""45 from django.conf.urls import url46 def fake_view(request):47 pass48 urlpatterns = [url(r'first/$', fake_view, name='first')]49 """50 )51 testdir.makepyfile(52 myurls2="""53 from django.conf.urls import url54 def fake_view(request):55 pass56 urlpatterns = [url(r'second/$', fake_view, name='second')]57 """58 )59 testdir.makepyfile(60 """61 try:62 from django.urls import reverse, NoReverseMatch63 except ImportError: # Django < 2.064 from django.core.urlresolvers import reverse, NoReverseMatch65 import pytest66 @pytest.mark.urls('myurls')67 def test_something():68 reverse('first')...

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 pytest-django 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