How to use should_not method in Selene

Best Python code snippet using selene_python

test_assertion_builder.py

Source:test_assertion_builder.py Github

copy

Full Screen

...209 assert this(d2).should.be(d1)210 assert this(d3).should_not.be(d1)211 def wrong_should():212 return this(d3).should.be(d1)213 def wrong_should_not():214 return this(d2).should_not.be(d1)215 wrong_should_not.when.called.should.throw(216 AssertionError,217 '{} should not be the same object as {}, but it is',218 )219 wrong_should.when.called.should.throw(220 AssertionError,221 '{} should be the same object as {}, but it is not',222 )223def test_have_property():224 ("this(instance).should.have.property(property_name)")225 class Person(object):226 name = "John Doe"227 def __repr__(self):...

Full Screen

Full Screen

boolean_features.py

Source:boolean_features.py Github

copy

Full Screen

1import json2import requests3category_tags = {4 'isBLM': {'should': ['Black Lives Matter', 'BLM'],5 'should_not': []},6 'isBrexit': {'should':['Brexit', 'Operation Yellowhammer'],7 'should_not': []},8 'isCovid': {'should': ['Covid', 'Coronavirus', 'Self-isolation', 'Lockdown', 'Contact tracing', 'Mers virus', 'Joint Biosecurity Centre (JBC)'],9 'should_not': []},10 'isEducation': {'should': ['Education'],11 'should_not': []},12 'isImmigration': {'should': ['Immigration'],13 'should_not': []},14 "isEconomy": {'should': ['Economy'],15 'should_not': []},16}17football_teams = {18 'isArsenal': {'should': ['http://www.bbc.co.uk/things/c4285a9a-9865-2343-af3a-8653f7b70734#id']},19 'isBournemouth': {'should': ['http://www.bbc.co.uk/things/0280e88c-26bd-b24c-882f-ae0e5f4142f2#id']},20 'isBHA': {'should': ['http://www.bbc.co.uk/things/3d814d88-1f22-d042-a9a6-87fd9216a50a#id']},21 'isChelsea': {'should': ['http://www.bbc.co.uk/things/2acacd19-6609-1840-9c2b-b0820c50d281#id']},22 'isEverton': {'should': ['http://www.bbc.co.uk/things/48287aac-b015-1d4e-9c4e-9b8abac03789#id']},23 'isManUtd': {'should': ['http://www.bbc.co.uk/things/90d9a818-850b-b64f-9474-79e15a0355b8#id']},24 'isTottenham': {'should': ['http://www.bbc.co.uk/things/edc20628-9520-044d-92c3-fdec473457be#id']},25 'isCardiff': {'should': ['http://www.bbc.co.uk/things/bef8a4b5-1ad1-4347-b665-edf581ab7350#id']},26 'isFulham': {'should': ['http://www.bbc.co.uk/things/98c3db4b-498d-7c4b-acb5-d16ffb214f0d#id']},27 'isHuddersfield': {'should': ['http://www.bbc.co.uk/things/843257c2-309c-a749-9888-615bb448f887#id']},28 'isStoke': {'should': ['http://www.bbc.co.uk/things/ff3ad258-564a-3d46-967a-cefa4e65cfea#id']},29 'isSwansea': {'should': ['http://www.bbc.co.uk/things/98105d9f-b1db-0547-b8c7-581abf30c7e9#id']},30 'isWBA': {'should': ['http://www.bbc.co.uk/things/7f6edf4a-76f6-4b49-b16b-ff1e232eeb18#id']},31 'isHull': {'should': ['http://www.bbc.co.uk/things/10786d02-d602-084f-bfb5-3198a9bebfe7#id']},32 'isMiddlesbrough': {'should': ['http://www.bbc.co.uk/things/39a9af5a-c881-a74d-bae7-226ac220df03#id']},33 'isSunderland': {'should': ['http://www.bbc.co.uk/things/d5a95ba9-efe6-aa4e-afc4-9adc5f786e58#id']},34 'isAstonVilla': {'should': ['http://www.bbc.co.uk/things/9ce8f75f-4dc0-0f46-8e1b-742513527baf#id']},35 'isNewcastle': {'should': ['http://www.bbc.co.uk/things/34032412-5e2a-324d-bb3e-d0d4b16df2d4#id']},36 'isNorwich': {'should': ['http://www.bbc.co.uk/things/a700cc4d-72eb-a84d-8d7a-73ce435f6985#id']},37 'isBurnley': {'should': ['http://www.bbc.co.uk/things/279a3dc2-9195-264d-be3e-2a52bb61d4fe#id']},38 'isQPR': {'should': ['http://www.bbc.co.uk/things/81f6a64f-def0-0d40-bc3a-36dab5472f64#id']},39 'isWolverhampton': {'should': ['http://www.bbc.co.uk/things/b68a1520-32bc-eb42-8dc0-ccc1018e8e8f#id']},40 'isLeicester': {'should': ['http://www.bbc.co.uk/things/ff55aea0-83d7-834c-afc0-d21045f561e9#id']},41 'isWatford': {'should': ['http://www.bbc.co.uk/things/7d1d29cb-dab4-a24f-8600-393be1f354fe#id']},42 'isSouthampton': {'should': ['http://www.bbc.co.uk/things/6780f83f-a17a-e641-8ec8-226c285a5dbb#id']},43 'isSheffield': {'should': ['http://www.bbc.co.uk/things/75f90667-0306-e847-966e-085a11a8f195#id']},44 'isManCity': {'should': ['http://www.bbc.co.uk/things/4bdbf21d-d1ad-7147-ab08-612cd0dc20b4#id']},45}46starfruit_api = 'http://starfruit.virt.ch.bbc.co.uk'47mango_api = 'http://api.mango-en.virt.ch.bbc.co.uk'48def end_to_end_labelling(article, category_tags, tag_type='label', use_tags=True, use_headline=True, use_summary=True, use_body=True, use_starfish=True, use_mango=True):49 """50 Orchestration of boolean labelling for a single article and category.51 args:52 article (dict): article object to be labelled53 category_tags (dict): dictionary containing a list of "should" tags, and optional "should_not" tags54 Returns:55 True if text returned from various optional locations (tags, headline, summary, body, auto-taggers) contains at least one valid category tag,56 and no invalid tags.57 """58 text = []59 if use_tags:60 text += get_tags(article)61 if use_headline:62 text += [get_headline(article)]63 if use_summary:64 text += [get_summary(article)]65 if use_body:66 text += [get_body(article)]67 if use_starfish or use_mango:68 uri = get_uri(article)69 if use_starfish:70 response = get_results_from_autotagger(uri, api='http://starfruit.virt.ch.bbc.co.uk')71 text += parse_labels_from_starfruit_response(response, tag_type)72 if use_mango:73 response = get_results_from_autotagger(uri, api='http://api.mango-en.virt.ch.bbc.co.uk')74 text += parse_labels_from_mango_response(response, tag_type)75 return check_text_for_keywords(text, category_tags)76autotagger_cache = {}77def get_results_from_autotagger(asset_uri, api=starfruit_api):78 """79 Query starfruit or mango api with article URI to return auto-generated content tags.80 """81 uri = f'{api}/topics?uri=https://www.bbc.co.uk{asset_uri}'82 cached = autotagger_cache.setdefault(uri, None)83 if cached:84 return cached85 else:86 response = requests.get(uri)87 body = response.content88 decoded = json.loads(body.decode("utf-8"))89 autotagger_cache[uri] = decoded90 return decoded91def parse_labels_from_starfruit_response(response, return_type='label'):92 """93 Extract list of auto-generated labels from starfruit api response.94 """95 all_labels = response.get('results', [])96 if return_type == 'label':97 return [l.get(return_type, {}).get('en-gb', '') for l in all_labels]98 elif return_type == 'uri':99 return [l.get('@id', '') for l in all_labels]100def parse_labels_from_mango_response(response, return_type='label'):101 """102 Extract list of auto-generated labels from mango api response.103 """104 all_labels = response.get('results', [])105 if return_type == 'label':106 return [l.get(return_type, {}) for l in all_labels]107 elif return_type == 'uri':108 for l in all_labels:109 for uri in l.get('same_as', []):110 if uri.startswith("http://www.bbc.co.uk/things/"):111 return uri + "#id"112 return ''113def get_tags(article):114 """115 Extract tags from within article json.116 """117 all_tags = article.get('metadata', {}).get('tags', {}).get('about', [])118 tag_names = [t.get('thingLabel') for t in all_tags]119 return tag_names120def get_headline(article):121 """122 Extract headline from within article json.123 """124 return article.get('promo', {}).get('headlines', {}).get('headline', '')125def get_summary(article):126 """127 Extract summary from within article json.128 """129 return article.get('promo', {}).get('summary', '')130def get_body(article):131 """132 Extract body text from within article json.133 """134 text = ''135 for t in article.get('content', {}).get('blocks', []):136 text += t.get('text', '')137 return text138def get_uri(article):139 """140 Extract uri from within article json.141 """142 return article.get('metadata', {}).get('locators', {}).get('assetUri', '')143def check_text_for_keywords(text, category_tags):144 """145 Function checks if text includes category tags, excluding invalid tags.146 Args:147 text (list): list of text segments to be searched (these may be tags, headlines, or body text)148 category_tags (dict): dictionary containing a list of "should" tags, and optional "should_not" tags149 Returns:150 True if text contains at least one valid category tag, and no invalid tags.151 """152 all_text = (' ').join([t.lower() for t in text])153 should = [t.lower() for t in category_tags.get('should', [])]154 should_not = [t.lower() for t in category_tags.get('should_not', [])]155 for s in should_not:156 if all_text.find(s) >= 0:157 return False158 for s in should:159 if all_text.find(s) >= 0:160 return True...

Full Screen

Full Screen

intents_test.py

Source:intents_test.py Github

copy

Full Screen

1from __future__ import absolute_import2import unittest3from .. import intents4import mock5import minion.core.components.exceptions6import sure # though lint complains that it's never used this is needed7class IntentExistsPreprocessorConfiguration(unittest.TestCase):8 def test_no_key(self):9 """ Should raise if no key passed """10 intents.IntentExists.when.called_with({}).should.throw(minion.core.components.exceptions.ImproperlyConfigured)11 def test_ok(self):12 """ Should not raise if all ok """13 intents.IntentExists.when.called_with({'key': 'blop'}).should_not.throw(minion.core.components.exceptions.ImproperlyConfigured)14class IntentEqualsPreprocessorConfiguration(unittest.TestCase):15 def test_no_key(self):16 """ Should raise if no key passed """17 intents.IntentEquals.when.called_with({}).should.throw(minion.core.components.exceptions.ImproperlyConfigured)18 def test_no_value(self):19 """ Should raise if no value passed """20 intents.IntentEquals.when.called_with({'key': 'lala'}).should.throw(minion.core.components.exceptions.ImproperlyConfigured)21 def test_ok(self):22 """ Should not raise if all ok """23 intents.IntentEquals.when.called_with({'key': 'blop', 'value': 10}).should_not.throw(minion.core.components.exceptions.ImproperlyConfigured)24class FakeRedisClient(object):25 """ Helper class """26 def __init__(self, value):27 self.value = value28 def get(self, key):29 return self.value30class IntentExistsTestMethod(unittest.TestCase):31 """ Test actual checks"""32 @mock.patch.object(intents.BaseIntent, '_setup_redis_client', return_value=FakeRedisClient(None))33 def test_does_not_exist(self, mock_redis_client):34 """ Should return false if getting returns none """35 pp = intents.IntentExists({'key': 'blop'})36 pp._test().should_not.be.ok37 @mock.patch.object(intents.BaseIntent, '_setup_redis_client', return_value=FakeRedisClient(1))38 def test_does_exists(self, mock_redis_client):39 """ Should return true if getting returns something """40 pp = intents.IntentExists({'key': 'blop'})41 pp._test().should.be.ok42class IntentDoesNotExistTestMethod(unittest.TestCase):43 """ Test actual checks"""44 @mock.patch.object(intents.BaseIntent, '_setup_redis_client', return_value=FakeRedisClient(None))45 def test_does_not_exist(self, mock_redis_client):46 """ Should return true if getting returns none """47 pp = intents.IntentDoesNotExist({'key': 'blop'})48 pp._test().should.be.ok49 @mock.patch.object(intents.BaseIntent, '_setup_redis_client', return_value=FakeRedisClient(1))50 def test_does_exists(self, mock_redis_client):51 """ Should return false if getting returns something """52 pp = intents.IntentDoesNotExist({'key': 'blop'})53 pp._test().should_not.be.ok54class IntentEqualsTestMethod(unittest.TestCase):55 """ Test actual checks"""56 @mock.patch.object(intents.BaseIntent, '_setup_redis_client', return_value=FakeRedisClient(None))57 def test_does_not_exist(self, mock_redis_client):58 """ Should return false if getting returns none """59 pp = intents.IntentEquals({'key': 'blop', 'value': '1'})60 pp._test().should_not.be.ok61 @mock.patch.object(intents.BaseIntent, '_setup_redis_client', return_value=FakeRedisClient('2'))62 def test_wrong_value(self, mock_redis_client):63 """ Should return false if getting returns something else """64 pp = intents.IntentEquals({'key': 'blop', 'value': '1'})65 pp._test().should_not.be.ok66 @mock.patch.object(intents.BaseIntent, '_setup_redis_client', return_value=FakeRedisClient('1'))67 def test_does_exists(self, mock_redis_client):68 """ Should return true if getting returns the same value """69 pp = intents.IntentEquals({'key': 'blop', 'value': '1'})...

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