How to use run_check method in refurb

Best Python code snippet using refurb_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...10def leestijd():11 """leestijd werkt precies zoals de voorbeelden in de opdracht"""12 with logged_check_factory("leestijd") as run_check:13 # check example 114 (run_check()15 .stdin("35")16 .stdin("50")17 .stdin("10")18 .stdin("15")19 .stdin("-1")20 .stdout("[Jj]e hebt ongeveer 9[12][\n]* pagina", "Je hebt ongeveer 91/92 pagina's gelezen."))21 # check example 222 (run_check()23 .stdin("-1")24 .stdout("[Jj]e hebt niet gelezen\.?"))25@check50.check()26def leetspeak():27 """leetspeak werkt precies zoals de voorbeelden in de opdracht"""28 with logged_check_factory("leetspeak", "1337") as run_check:29 (run_check("Waterlelie")30 .stdout("W473r131i3"))31 (run_check("Anders")32 .stdout("4nd3rs"))33 (run_check("tentamen baas!!")34 .stdout("73n74m3n"))35@check50.check()36def leetspeak2():37 """leetspeak werkt met input"""38 with logged_check_factory("leetspeak", "1337") as run_check:39 (run_check()40 .stdin("Waterlelie")41 .stdout("W473r131i3"))42 (run_check()43 .stdin("Anders")44 .stdout("4nd3rs"))45 (run_check()46 .stdin("tentamen baas!!")47 .stdout("73n74m3n b44s!!"))48@check50.check()49def carometer():50 """carometer werkt precies zoals de voorbeelden in de opdracht"""51 with logged_check_factory("carometer", "rent") as run_check:52 (run_check()53 .stdin("5")54 .stdin("500")55 .stdin("j")56 .stdout("600", "De kosten zijn EUR 600"))57 (run_check()58 .stdin("5")59 .stdin("500")60 .stdin("j")61 .stdout("600", "De kosten zijn EUR 600"))62 (run_check()63 .stdin("2")64 .stdin("100")65 .stdin("n")66 .stdout("180", "De kosten zijn EUR 180"))67 (run_check()68 .stdin("2")69 .stdin("100")70 .stdin("n")71 .stdout("180", "De kosten zijn EUR 180"))72 (run_check()73 .stdin("0")74 .stdin("400")75 .stdin("n")76 .stdout("invoer!")77 .stdin("2")78 .stdin("100")79 .stdin("n")80 .stdout("180", "De kosten zijn EUR 180"))81 (run_check()82 .stdin("5")83 .stdin("19")84 .stdin("n")85 .stdout("invoer!")86 .stdin("2")87 .stdin("100")88 .stdin("n")89 .stdout("180", "De kosten zijn EUR 180"))90 (run_check()91 .stdin("5")92 .stdin("20")93 .stdin("z")94 .stdout("invoer!")95 .stdin("2")96 .stdin("100")97 .stdin("n")98 .stdout("180", "De kosten zijn EUR 180"))99@check50.check()100def afgebroken():101 """afgebroken werkt precies zoals de voorbeelden in de opdracht"""102 with logged_check_factory("afgebroken") as run_check:103 (run_check()104 .stdin("Nederlanders worden steeds ouder, vooral door- dat ze na hun 65ste langer in leven blijven.")105 .stdout("Nederlanders worden steeds ouder, vooral doordat ze na hun 65ste langer in leven blijven."))106 (run_check()107 .stdin("Over de identiteit van de schutter zegt de po- litie: 'Als het de man is die we denken dat het is, dan is het een bekende van de politie.'")108 .stdout("Over de identiteit van de schutter zegt de politie: 'Als het de man is die we denken dat het is, dan is het een bekende van de politie.'"))109 (run_check()110 .stdin("Een 36-jarige Geldropse heeft deze week een in- breker in haar schuurtje net zo lang achtervolgd tot de politie arriveerde.")111 .stdout("Een 36-jarige Geldropse heeft deze week een inbreker in haar schuurtje net zo lang achtervolgd tot de politie arriveerde."))112@check50.check()113def validate():114 """validate werkt precies zoals de voorbeelden in de opdracht"""115 with logged_check_factory("validate", "lisp", "validatie") as run_check:116 (run_check()117 .stdin("(defun factorial (())(] (loop))))")118 .stdout("[Ii]nvalid"))119 (run_check()120 .stdin("(write (factorial 3))")121 .stdout("[Vv]alid"))122 (run_check()123 .stdin("(defun gretting ((write-line \"let it snow\"))")124 .stdout("[Ii]nvalid"))125class Stream:126 """Stream-like object that stores everything it receives"""127 def __init__(self):128 self.entries = []129 @property130 def text(self):131 return "".join(self.entries)132 def write(self, entry):133 entry = entry.replace("\r\n", "\n").replace("\r", "\n")134 self.entries.append(entry)135 def flush(self):136 pass...

Full Screen

Full Screen

test_basic.py

Source:test_basic.py Github

copy

Full Screen

...4import sys5import tempfile6import unittest7class BasicTests(unittest.TestCase):8 def run_check(self, args, retval=0):9 try:10 main.main(args, allow_spam=True)11 except SystemExit, e:12 self.assertEqual(e.code, retval)13 def test_stdout_redirect(self):14 dirname = tempfile.mkdtemp()15 phrase = 'testing'16 command = "echo -n '%s'" % phrase17 self.run_check(["--command", command,18 "--restart",19 "--max-restarts=2",20 "--ensure-alive",21 "--stdout-location=%s" % dirname])22 data = []23 for i in range(0, 3):24 filename = "%s/%s.%s" % (25 dirname,26 md5.md5(command + str(os.getpid())).hexdigest(),27 i)28 data.append(open(filename).read())29 os.unlink(filename)30 os.rmdir(dirname)31 for d in data:32 self.assertEqual(d, phrase)33 def test_stderr_redirect(self):34 dirname = tempfile.mkdtemp()35 phrase = 'testing'36 command = "echo -n '%s' 1>&2" % phrase37 self.run_check(["--command", command,38 "--restart",39 "--max-restarts=2",40 "--ensure-alive",41 "--stderr-location=%s" % dirname])42 data = []43 for i in range(0, 3):44 filename = "%s/%s.%s" % (45 dirname,46 md5.md5(command + str(os.getpid()) + "err").hexdigest(),47 i)48 data.append(open(filename).read())49 os.unlink(filename)50 os.rmdir(dirname)51 for d in data:52 self.assertEqual(d, phrase)53 def test_quick_command(self):54 self.run_check(["--command", "ls >/dev/null"])55 def test_quick_command_cpu_constraint(self):56 self.run_check(["--cpu=.1", "--command", "ls >/dev/null"])57 def test_quick_command_mem_constraint(self):58 self.run_check(["--mem=10", "--command", "ls >/dev/null"])59 def test_quick_command_cpu_mem_constraint(self):60 self.run_check(["--cpu=.2", "--mem=10", "--command", "ls >/dev/null"])61 def test_slow_command(self):62 self.run_check(["--command", "ls >/dev/null; sleep .21"])63 # !FLAKY64 def _test_slow_command_cpu_constraint(self):65 self.run_check(["--cpu=.5", "--command", "ls >/dev/null; sleep .21"])66 def test_slow_command_mem_constraint(self):67 self.run_check(["--mem=10", "--command", "ls >/dev/null; sleep .21"])68 # FLAKY For some reason on slower machines69 # def test_slow_command_cpu_mem_constraint(self):70 # self.run_check(["--cpu=.9", "--mem=10",71 # "--command", "ls >/dev/null; sleep .31"])72 def test_time_constraint(self):73 self.run_check(["--time-limit=.1", "--command", "sleep .2"], 9)74 def test_time_constraint_inverse(self):75 self.run_check(["--time-limit=.5", "--command", "sleep .1"])76 def test_cpu_constraint(self):77 self.run_check(["--cpu=.5", "--command", "./spin.sh"], 9)78 def test_cpu_constraint_redirect(self):79 self.run_check(["--cpu=.1", "--command",80 "bash -c './spin.sh 2>/dev/null'"],81 9)82 def test_cpu_constraint_subprocess(self):83 self.run_check(["--cpu=.1", "--command",84 "bash -c 'bash -c \'./spin.sh\''"],85 9)86 def test_mem_constraint(self):87 self.run_check(["--mem=3", "--command", "./mem.sh"],88 9)89 def test_mem_constraint_redirect_subprocess(self):90 self.run_check(["--mem=3", "--command",91 "bash -c 'bash -c \'./mem.sh\''"],92 9)93 def test_mem_constraint_redirect(self):94 self.run_check(["--mem=3",95 "--command", "./mem.sh 2>/dev/null"], 9)96 def test_restarting(self):97 filename = tempfile.mktemp()98 self.run_check(["--cpu=.5", "--restart", "--max-restarts=2",99 "--command",100 "echo '1' >> %s ; ./spin.sh" % filename], 9)101 lines = open(filename).readlines()102 os.unlink(filename)103 self.assertEqual(3, len(lines))104 def test_ensure_alive(self):105 filename = tempfile.mktemp()106 self.run_check(["--ensure-alive", "--restart", "--max-restarts=2",107 "--command",108 "echo '1' >> %s" % filename])109 lines = open(filename).readlines()110 os.unlink(filename)111 self.assertEqual(3, len(lines))112 def test_ensure_alive_many_times(self):113 sys.setrecursionlimit(70)114 filename = tempfile.mktemp()115 self.run_check(["--ensure-alive", "--restart", "--max-restarts=71",116 "--poll-interval=0.001",117 "--command",118 "echo '1' >> %s" % filename])119 sys.setrecursionlimit(500)120 lines = open(filename).readlines()121 os.unlink(filename)...

Full Screen

Full Screen

test_gradients.py

Source:test_gradients.py Github

copy

Full Screen

1"""Python Unit testing for gradients"""2import numpy as np3from theta.model import Model4from theta.layers import ThetaUnitLayer, DiagExpectationUnitLayer, Linear, NonLinear, SoftMaxLayer5def run_check(mdl, diffepsilon=1e-5, epsilon=1e-5):6 n = 10007 data = np.random.random_sample(n).reshape(1, n)8 for p in range(len(mdl.get_parameters())):9 num, back = mdl.gradient_check(p, data, epsilon)10 assert np.abs(num - back) < diffepsilon11def test_thetaunitlayer_1():12 mdl = Model()13 mdl.add(ThetaUnitLayer(1, 1, diagonal_T=True))14 run_check(mdl)15def test_thetaunitlayer_2():16 mdl = Model()17 mdl.add(ThetaUnitLayer(1, 1, Nhidden=2, diagonal_T=True))18 run_check(mdl, 1e-2)19def test_diagexpectationunitlayer():20 mdl = Model()21 mdl.add(DiagExpectationUnitLayer(1, 1))22 run_check(mdl)23def test_linear():24 mdl = Model()25 mdl.add(Linear(1,1))26 run_check(mdl)27def test_nonlinear():28 mdl = Model()29 mdl.add(NonLinear(1,1))30 run_check(mdl)31def test_softmax():32 mdl = Model()33 mdl.add(SoftMaxLayer(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 refurb 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