How to use at_most method in Selene

Best Python code snippet using selene_python

unittests.py

Source:unittests.py Github

copy

Full Screen

1import unittest2from pdfparser.tasks import *3class TestTasks(unittest.TestCase):4 def test_simple_crit(self):5 # Simple crit6 ## If the word exist7 self.assertEqual(8 simple_crit(9 'a b c',10 {'a'},11 without=set(),12 at_least=1,13 at_most=114 ),15 True16 )17 # If it doesn't exist18 self.assertEqual(19 simple_crit(20 'a b c',21 {'d'},22 without=set(),23 at_least=1,24 at_most=125 ),26 False27 )28 # There isn't any word from the without set29 self.assertEqual(30 simple_crit(31 'a b c',32 {'a'},33 without={'d'},34 at_least=1,35 at_most=136 ),37 True38 )39 # There is a word from without set40 self.assertEqual(41 simple_crit(42 'a b c',43 {'a'},44 without={'b'},45 at_least=1,46 at_most=147 ),48 False49 )50 ## There are 3 words, at_least=351 self.assertEqual(52 simple_crit(53 'a b c d e',54 {'a', 'c', 'e'},55 without=set(),56 at_least=3,57 at_most=158 ),59 True60 )61 ## There is not enough words, at_least=362 self.assertEqual(63 simple_crit(64 'a b c d e',65 {'a', 'c', 'z'},66 without=set(),67 at_least=3,68 at_most=169 ),70 False71 )72 def test_complex_crit(self):73 # Simple crit74 ## If the word exist75 self.assertEqual(76 complex_crit(77 'a b c',78 {'a'},79 without=set(),80 at_least=1,81 at_most=1,82 similarity="embedding_cosine",83 threshold=0.984 ),85 True86 )87 # If it doesn't exist88 self.assertEqual(89 complex_crit(90 'a b c',91 {'d'},92 without=set(),93 at_least=1,94 at_most=1,95 similarity="embedding_cosine",96 threshold=0.997 ),98 False99 )100 # There isn't any word from the without set101 self.assertEqual(102 complex_crit(103 'a b c',104 {'a'},105 without={'d'},106 at_least=1,107 at_most=1,108 similarity="embedding_cosine",109 threshold=0.9110 ),111 True112 )113 # There is a word from without set114 self.assertEqual(115 complex_crit(116 'a b c',117 {'a'},118 without={'b'},119 at_least=1,120 at_most=1,121 similarity="embedding_cosine",122 threshold=0.9123 ),124 False125 )126 ## There are 3 words, at_least=3127 self.assertEqual(128 complex_crit(129 'a b c d e',130 {'a', 'c', 'e'},131 without=set(),132 at_least=3,133 at_most=1,134 similarity="embedding_cosine",135 threshold=0.9136 ),137 True138 )139 ## There is not enough words, at_least=3140 self.assertEqual(141 complex_crit(142 'a b c d e',143 {'a', 'c', 'z'},144 without=set(),145 at_least=3,146 at_most=1,147 similarity="embedding_cosine",148 threshold=0.9149 ),150 False151 )152 def complex_crit_hamming(self):153 ## If the word exist154 self.assertEqual(155 complex_crit(156 'asdf bsdf csdf',157 {'asdf'},158 without=set(),159 at_least=1,160 at_most=1,161 similarity="hamming",162 threshold=3163 ),164 True165 )166 # If it doesn't exist167 self.assertEqual(168 complex_crit(169 'asdf bsdf csdf',170 {'gggg'},171 without=set(),172 at_least=1,173 at_most=1,174 similarity="hamming",175 threshold=3176 ),177 False178 )179 # There isn't any word from the without set180 self.assertEqual(181 complex_crit(182 'asdf bsdf csdf',183 {'asdf'},184 without={'dddd'},185 at_least=1,186 at_most=1,187 similarity="hamming",188 threshold=3189 ),190 True191 )192 # There is a word from without set193 self.assertEqual(194 complex_crit(195 'asdf bsdf csdf',196 {'asdf'},197 without={'dsdf'},198 at_least=1,199 at_most=1,200 similarity="hamming",201 threshold=3202 ),203 False204 )205 ## There are 3 words, at_least=3206 self.assertEqual(207 complex_crit(208 'asdf bsdf csdf dsdf esdf',209 {'asdf', 'csdf', 'esdf'},210 without=set(),211 at_least=3,212 at_most=1,213 similarity="hamming",214 threshold=3215 ),216 True217 )218 ## There is not enough words, at_least=3219 self.assertEqual(220 complex_crit(221 'asdf bsdf csdf dsdf esdf',222 {'asdf', 'csdf', 'gggg'},223 without=set(),224 at_least=3,225 at_most=1,226 similarity="hamming",227 threshold=3228 ),229 False230 )231 def test_parser_metadata(self):232 metadata, _, _, _ = parse("pdfparser/rozp.pdf")233 self.assertEqual(metadata["title"],234 "Ustawa z dnia 31 marca 2020 r. o zmianie niektórych ustaw w zakresie systemu " \235 "ochrony zdrowia związanych z zapobieganiem, przeciwdziałaniem i zwalczaniem COVID-19")236 self.assertEqual(metadata["author"], "RCL")237 self.assertEqual(metadata["creator"], "Microsoft® Word 2010")238 self.assertEqual(metadata["producer"], "Microsoft® Word 2010; modified using iText 2.1.7 by 1T3XT")239 def test_parser_separated_text(self):240 _, separated_text, _, _ = parse("pdfparser/3_pages.pdf")241 self.assertEqual(separated_text, [['PDF with 3 pages\u2028\nText on the first one\u2029\n'], [],242 ['Text on the 3rd one\n']])243 def test_parser_empty_pages(self):244 _, _, empty_pages, _ = parse("pdfparser/3_pages.pdf")245 self.assertEqual(empty_pages, [1])246 def test_parser_all_text(self):247 _, _, _, all_text = parse("pdfparser/small.pdf")248 self.assertEqual(parsed_text,expected_text)249 def test_pdfocr_small_file(self):250 recognized_text = pdfocr("small.pdf")251 expected_text = ["Here is a small document\n" \252 "Testing how\n" \253 "PDF Parser will work"]254 self.assertEqual(recognized_text, expected_text)255 def test_pdfocr_easy_page_ocrtest_file(self):256 recognized_text = pdfocr("ocrtest.pdf", pages=[1])257 expected_text = ["This is another sample document.\n"\258 "The first page is quality.\n"\259 "\nSample random text."]260 self.assertEqual(recognized_text,expected_text)261 def test_pdfocr_hard_pages_ocrtest_file(self):262 recognized_text = pdfocr("ocrtest.pdf", pages=[2,3])263 expected_text = ["The second page contains a photo of the text.\n\n"\264 "This is text in paint.\n"\265 "Only ocr can read this."\266 ,"The last page contains\n"\267 "only text in paint."]268 self.assertEqual(recognized_text, expected_text)269if __name__ == '__main__':...

Full Screen

Full Screen

test_queue.py

Source:test_queue.py Github

copy

Full Screen

...120 assert when_empty_ev.triggered121 yield when_empty_ev122 env.process(proc(env, Queue(env)))123 env.run()124def test_when_at_most(env):125 def proc(env, queue):126 for item in 'abc':127 with queue.put(item) as put_ev:128 yield put_ev129 at_most = {}130 at_most[0] = queue.when_at_most(0)131 at_most[3] = queue.when_at_most(3)132 at_most[1] = queue.when_at_most(1)133 at_most[2] = queue.when_at_most(2)134 assert not at_most[0].triggered135 assert not at_most[1].triggered136 assert not at_most[2].triggered137 assert at_most[3].triggered138 item = yield queue.get()139 assert item == 'a'140 assert not at_most[0].triggered141 assert not at_most[1].triggered142 assert at_most[2].triggered143 item = yield queue.get()144 assert item == 'b'145 assert not at_most[0].triggered146 assert at_most[1].triggered147 item = yield queue.get()...

Full Screen

Full Screen

test_atMostTwoConstraint.py

Source:test_atMostTwoConstraint.py Github

copy

Full Screen

1from unittest import TestCase2from hw2cs561s2018 import AtMostTwoConstraint3class TestAtMostTwoConstraint(TestCase):4 def test_at_most(self):5 # variables, domains, assignments6 variables = ['a', 'b', 'c', 'd', 'e']7 assignments = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}8 at_most = AtMostTwoConstraint()9 self.assertEqual(0, at_most(variables, None, assignments))10 variables = ['a', 'b', 'c', 'd', 'e']11 assignments = {'a': 1, 'b': 2, 'c': 3, 'd': 4}12 at_most = AtMostTwoConstraint()13 self.assertEqual(0, at_most(variables, None, assignments))14 variables = ['a', 'b', 'c', 'd', 'e']15 assignments = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 1}16 at_most = AtMostTwoConstraint()17 self.assertEqual(0, at_most(variables, None, assignments))18 variables = ['a', 'b', 'c', 'd', 'e']19 assignments = {'a': 1, 'b': 2, 'c': 3, 'e': 1}20 at_most = AtMostTwoConstraint()21 self.assertEqual(0, at_most(variables, None, assignments))22 variables = ['a', 'b', 'c', 'd', 'e']23 assignments = {'a': 1, 'b': 1, 'c': 3, 'd': 4, 'e': 1}24 at_most = AtMostTwoConstraint()25 self.assertEqual(1, at_most(variables, None, assignments))26 variables = ['a', 'b', 'c', 'd', 'e']27 assignments = {'a': 1, 'b': 1, 'c': 1, 'd': 4, 'e': 5}28 at_most = AtMostTwoConstraint()29 self.assertEqual(1, at_most(variables, None, assignments))30 variables = ['a', 'b', 'c', 'd', 'e']31 assignments = {'a': 1, 'b': 1, 'c': 1, 'd': 4}32 at_most = AtMostTwoConstraint()33 self.assertEqual(1, at_most(variables, None, assignments))34 variables = ['a', 'b', 'c', 'd', 'e']35 assignments = {'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1}36 at_most = AtMostTwoConstraint()37 self.assertEqual(3, at_most(variables, None, assignments))38 variables = ['a', 'b', 'c', 'd', 'e']39 assignments = {'a': 1, 'b': 1, 'c': 3, 'e': 1}40 at_most = AtMostTwoConstraint()41 self.assertEqual(1, at_most(variables, None, assignments))42 variables = ['a', 'b', 'c', 'd', 'e']43 assignments = {'a': 1, 'b': 1, 'c': 3, 'd': 4, 'e': 1}44 at_most = AtMostTwoConstraint()...

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