How to use test_failure method in wpt

Best JavaScript code snippet using wpt

hammer_tests.py

Source:hammer_tests.py Github

copy

Full Screen

...16 cls.parser_chr = h.ch(b"\xa2")17 def test_success(self):18 self.assertEqual(self.parser_int.parse(b"\xa2"), 0xa2)19 self.assertEqual(self.parser_chr.parse(b"\xa2"), b"\xa2")20 def test_failure(self):21 self.assertEqual(self.parser_int.parse(b"\xa3"), None)22 self.assertEqual(self.parser_chr.parse(b"\xa3"), None)23class TestChRange(unittest.TestCase):24 @classmethod25 def setUpClass(cls):26 cls.parser = h.ch_range(b"a", b"c")27 def test_success(self):28 self.assertEqual(self.parser.parse(b"b"), b"b")29 def test_failure(self):30 self.assertEqual(self.parser.parse(b"d"), None)31class TestInt64(unittest.TestCase):32 @classmethod33 def setUpClass(cls):34 cls.parser = h.int64()35 def test_success(self):36 self.assertEqual(self.parser.parse(b"\xff\xff\xff\xfe\x00\x00\x00\x00"), -0x200000000)37 def test_failure(self):38 self.assertEqual(self.parser.parse(b"\xff\xff\xff\xfe\x00\x00\x00"), None)39class TestInt32(unittest.TestCase):40 @classmethod41 def setUpClass(cls):42 cls.parser = h.int32()43 def test_success(self):44 self.assertEqual(self.parser.parse(b"\xff\xfe\x00\x00"), -0x20000)45 self.assertEqual(self.parser.parse(b"\x00\x02\x00\x00"), 0x20000)46 def test_failure(self):47 self.assertEqual(self.parser.parse(b"\xff\xfe\x00"), None)48 self.assertEqual(self.parser.parse(b"\x00\x02\x00"), None)49class TestInt16(unittest.TestCase):50 @classmethod51 def setUpClass(cls):52 cls.parser = h.int16()53 def test_success(self):54 self.assertEqual(self.parser.parse(b"\xfe\x00"), -0x200)55 self.assertEqual(self.parser.parse(b"\x02\x00"), 0x200)56 def test_failure(self):57 self.assertEqual(self.parser.parse(b"\xfe"), None)58 self.assertEqual(self.parser.parse(b"\x02"), None)59class TestInt8(unittest.TestCase):60 @classmethod61 def setUpClass(cls):62 cls.parser = h.int8()63 def test_success(self):64 self.assertEqual(self.parser.parse(b"\x88"), -0x78)65 def test_failure(self):66 self.assertEqual(self.parser.parse(b""), None)67class TestUint64(unittest.TestCase):68 @classmethod69 def setUpClass(cls):70 cls.parser = h.uint64()71 def test_success(self):72 self.assertEqual(self.parser.parse(b"\x00\x00\x00\x02\x00\x00\x00\x00"), 0x200000000)73 def test_failure(self):74 self.assertEqual(self.parser.parse(b"\x00\x00\x00\x02\x00\x00\x00"), None)75class TestUint32(unittest.TestCase):76 @classmethod77 def setUpClass(cls):78 cls.parser = h.uint32()79 def test_success(self):80 self.assertEqual(self.parser.parse(b"\x00\x02\x00\x00"), 0x20000)81 def test_failure(self):82 self.assertEqual(self.parser.parse(b"\x00\x02\x00"), None)83class TestUint16(unittest.TestCase):84 @classmethod85 def setUpClass(cls):86 cls.parser = h.uint16()87 def test_success(self):88 self.assertEqual(self.parser.parse(b"\x02\x00"), 0x200)89 def test_failure(self):90 self.assertEqual(self.parser.parse(b"\x02"), None)91class TestUint8(unittest.TestCase):92 @classmethod93 def setUpClass(cls):94 cls.parser = h.uint8()95 def test_success(self):96 self.assertEqual(self.parser.parse(b"\x78"), 0x78)97 def test_failure(self):98 self.assertEqual(self.parser.parse(b""), None)99 100class TestIntRange(unittest.TestCase):101 @classmethod102 def setUpClass(cls):103 cls.parser = h.int_range(h.uint8(), 3, 10)104 def test_success(self):105 self.assertEqual(self.parser.parse(b"\x05"), 5)106 def test_failure(self):107 self.assertEqual(self.parser.parse(b"\x0b"), None)108class TestWhitespace(unittest.TestCase):109 @classmethod110 def setUpClass(cls):111 cls.parser = h.whitespace(h.ch(b"a"))112 def test_success(self):113 self.assertEqual(self.parser.parse(b"a"), b"a")114 self.assertEqual(self.parser.parse(b" a"), b"a")115 self.assertEqual(self.parser.parse(b" a"), b"a")116 self.assertEqual(self.parser.parse(b"\ta"), b"a")117 def test_failure(self):118 self.assertEqual(self.parser.parse(b"_a"), None)119class TestWhitespaceEnd(unittest.TestCase):120 @classmethod121 def setUpClass(cls):122 cls.parser = h.whitespace(h.end_p())123 def test_success(self):124 self.assertEqual(self.parser.parse(b""), None) # empty string125 self.assertEqual(self.parser.parse(b" "), None) # empty string126 def test_failure(self):127 self.assertEqual(self.parser.parse(b" x"), None)128class TestLeft(unittest.TestCase):129 @classmethod130 def setUpClass(cls):131 cls.parser = h.left(h.ch(b"a"), h.ch(b" "))132 def test_success(self):133 self.assertEqual(self.parser.parse(b"a "), b"a")134 def test_failure(self):135 self.assertEqual(self.parser.parse(b"a"), None)136 self.assertEqual(self.parser.parse(b" "), None)137 self.assertEqual(self.parser.parse(b"ab"), None)138class TestRight(unittest.TestCase):139 @classmethod140 def setUpClass(cls):141 cls.parser = h.right(h.ch(b" "), h.ch(b"a"))142 def test_success(self):143 self.assertEqual(self.parser.parse(b" a"), b"a")144 def test_failure(self):145 self.assertEqual(self.parser.parse(b"a"), None)146 self.assertEqual(self.parser.parse(b" "), None)147 self.assertEqual(self.parser.parse(b"ba"), None)148class TestMiddle(unittest.TestCase):149 @classmethod150 def setUpClass(cls):151 cls.parser = h.middle(h.ch(b" "), h.ch(b"a"), h.ch(b" "))152 def test_success(self):153 self.assertEqual(self.parser.parse(b" a "), b"a")154 def test_failure(self):155 self.assertEqual(self.parser.parse(b"a"), None)156 self.assertEqual(self.parser.parse(b" "), None)157 self.assertEqual(self.parser.parse(b" a"), None)158 self.assertEqual(self.parser.parse(b"a "), None)159 self.assertEqual(self.parser.parse(b" b "), None)160 self.assertEqual(self.parser.parse(b"ba "), None)161 self.assertEqual(self.parser.parse(b" ab"), None)162class TestAction(unittest.TestCase):163 @classmethod164 def setUpClass(cls):165 cls.parser = h.action(h.sequence(h.choice(h.ch(b"a"), h.ch(b"A")),166 h.choice(h.ch(b"b"), h.ch(b"B"))),167 lambda x: [y.upper() for y in x])168 def test_success(self):169 self.assertEqual(self.parser.parse(b"ab"), [b"A", b"B"])170 self.assertEqual(self.parser.parse(b"AB"), [b"A", b"B"])171 def test_failure(self):172 self.assertEqual(self.parser.parse(b"XX"), None)173class TestIn(unittest.TestCase):174 @classmethod175 def setUpClass(cls):176 cls.parser = h.in_(b"abc")177 def test_success(self):178 self.assertEqual(self.parser.parse(b"b"), b"b") 179 def test_failure(self):180 self.assertEqual(self.parser.parse(b"d"), None)181class TestNotIn(unittest.TestCase):182 @classmethod183 def setUpClass(cls):184 cls.parser = h.not_in(b"abc")185 def test_success(self):186 self.assertEqual(self.parser.parse(b"d"), b"d")187 def test_failure(self):188 self.assertEqual(self.parser.parse(b"a"), None)189class TestEndP(unittest.TestCase):190 @classmethod191 def setUpClass(cls):192 cls.parser = h.sequence(h.ch(b"a"), h.end_p())193 def test_success(self):194 self.assertEqual(self.parser.parse(b"a"), (b"a",))195 def test_failure(self):196 self.assertEqual(self.parser.parse(b"aa"), None)197class TestNothingP(unittest.TestCase):198 @classmethod199 def setUpClass(cls):200 cls.parser = h.nothing_p()201 def test_success(self):202 pass203 def test_failure(self):204 self.assertEqual(self.parser.parse(b"a"), None)205class TestSequence(unittest.TestCase):206 @classmethod207 def setUpClass(cls):208 cls.parser = h.sequence(h.ch(b"a"), h.ch(b"b"))209 def test_success(self):210 self.assertEqual(self.parser.parse(b"ab"), (b"a", b"b"))211 def test_failure(self):212 self.assertEqual(self.parser.parse(b"a"), None)213 self.assertEqual(self.parser.parse(b"b"), None)214class TestSequenceWhitespace(unittest.TestCase):215 @classmethod216 def setUpClass(cls):217 cls.parser = h.sequence(h.ch(b"a"), h.whitespace(h.ch(b"b")))218 def test_success(self):219 self.assertEqual(self.parser.parse(b"ab"), (b"a", b"b"))220 self.assertEqual(self.parser.parse(b"a b"), (b"a", b"b"))221 self.assertEqual(self.parser.parse(b"a b"), (b"a", b"b"))222 def test_failure(self):223 self.assertEqual(self.parser.parse(b"a c"), None)224class TestChoice(unittest.TestCase):225 @classmethod226 def setUpClass(cls):227 cls.parser = h.choice(h.ch(b"a"), h.ch(b"b"))228 def test_success(self):229 self.assertEqual(self.parser.parse(b"a"), b"a")230 self.assertEqual(self.parser.parse(b"b"), b"b")231 def test_failure(self):232 self.assertEqual(self.parser.parse(b"c"), None)233class TestButNot(unittest.TestCase):234 @classmethod235 def setUpClass(cls):236 cls.parser = h.butnot(h.ch(b"a"), h.token(b"ab"))237 def test_success(self):238 self.assertEqual(self.parser.parse(b"a"), b"a")239 self.assertEqual(self.parser.parse(b"aa"), b"a")240 def test_failure(self):241 self.assertEqual(self.parser.parse(b"ab"), None)242class TestButNotRange(unittest.TestCase):243 @classmethod244 def setUpClass(cls):245 cls.parser = h.butnot(h.ch_range(b"0", b"9"), h.ch(b"6"))246 def test_success(self):247 self.assertEqual(self.parser.parse(b"4"), b"4")248 def test_failure(self):249 self.assertEqual(self.parser.parse(b"6"), None)250class TestDifference(unittest.TestCase):251 @classmethod252 def setUpClass(cls):253 cls.parser = h.difference(h.token(b"ab"), h.ch(b"a"))254 def test_success(self):255 self.assertEqual(self.parser.parse(b"ab"), b"ab")256 def test_failure(self):257 self.assertEqual(self.parser.parse(b"a"), None)258class TestXor(unittest.TestCase):259 @classmethod260 def setUpClass(cls):261 cls.parser = h.xor(h.ch_range(b"0", b"6"), h.ch_range(b"5", b"9"))262 def test_success(self):263 self.assertEqual(self.parser.parse(b"0"), b"0")264 self.assertEqual(self.parser.parse(b"9"), b"9")265 def test_failure(self):266 self.assertEqual(self.parser.parse(b"5"), None)267 self.assertEqual(self.parser.parse(b"a"), None)268class TestMany(unittest.TestCase):269 @classmethod270 def setUpClass(cls):271 cls.parser = h.many(h.choice(h.ch(b"a"), h.ch(b"b")))272 def test_success(self):273 self.assertEqual(self.parser.parse(b""), ())274 self.assertEqual(self.parser.parse(b"a"), (b"a",))275 self.assertEqual(self.parser.parse(b"b"), (b"b",))276 self.assertEqual(self.parser.parse(b"aabbaba"), (b"a", b"a", b"b", b"b", b"a", b"b", b"a"))277 def test_failure(self):278 pass279class TestMany1(unittest.TestCase):280 @classmethod281 def setUpClass(cls):282 cls.parser = h.many1(h.choice(h.ch(b"a"), h.ch(b"b")))283 def test_success(self):284 self.assertEqual(self.parser.parse(b"a"), (b"a",))285 self.assertEqual(self.parser.parse(b"b"), (b"b",))286 self.assertEqual(self.parser.parse(b"aabbaba"), (b"a", b"a", b"b", b"b", b"a", b"b", b"a"))287 def test_failure(self):288 self.assertEqual(self.parser.parse(b""), None)289 self.assertEqual(self.parser.parse(b"daabbabadef"), None)290class TestRepeatN(unittest.TestCase):291 @classmethod292 def setUpClass(cls):293 cls.parser = h.repeat_n(h.choice(h.ch(b"a"), h.ch(b"b")), 2)294 def test_success(self):295 self.assertEqual(self.parser.parse(b"abdef"), (b"a", b"b"))296 def test_failure(self):297 self.assertEqual(self.parser.parse(b"adef"), None)298 self.assertEqual(self.parser.parse(b"dabdef"), None)299class TestOptional(unittest.TestCase):300 @classmethod301 def setUpClass(cls):302 cls.parser = h.sequence(h.ch(b"a"), h.optional(h.choice(h.ch(b"b"), h.ch(b"c"))), h.ch(b"d"))303 def test_success(self):304 self.assertEqual(self.parser.parse(b"abd"), (b"a", b"b", b"d"))305 self.assertEqual(self.parser.parse(b"acd"), (b"a", b"c", b"d"))306 self.assertEqual(self.parser.parse(b"ad"), (b"a", h.Placeholder(), b"d"))307 def test_failure(self):308 self.assertEqual(self.parser.parse(b"aed"), None)309 self.assertEqual(self.parser.parse(b"ab"), None)310 self.assertEqual(self.parser.parse(b"ac"), None)311class TestIgnore(unittest.TestCase):312 @classmethod313 def setUpClass(cls):314 cls.parser = h.sequence(h.ch(b"a"), h.ignore(h.ch(b"b")), h.ch(b"c"))315 def test_success(self):316 self.assertEqual(self.parser.parse(b"abc"), (b"a",b"c"))317 def test_failure(self):318 self.assertEqual(self.parser.parse(b"ac"), None)319class TestSepBy(unittest.TestCase):320 @classmethod321 def setUpClass(cls):322 cls.parser = h.sepBy(h.choice(h.ch(b"1"), h.ch(b"2"), h.ch(b"3")), h.ch(b","))323 def test_success(self):324 self.assertEqual(self.parser.parse(b"1,2,3"), (b"1", b"2", b"3"))325 self.assertEqual(self.parser.parse(b"1,3,2"), (b"1", b"3", b"2"))326 self.assertEqual(self.parser.parse(b"1,3"), (b"1", b"3"))327 self.assertEqual(self.parser.parse(b"3"), (b"3",))328 self.assertEqual(self.parser.parse(b""), ())329 def test_failure(self):330 pass331class TestSepBy1(unittest.TestCase):332 @classmethod333 def setUpClass(cls):334 cls.parser = h.sepBy1(h.choice(h.ch(b"1"), h.ch(b"2"), h.ch(b"3")), h.ch(b","))335 def test_success(self):336 self.assertEqual(self.parser.parse(b"1,2,3"), (b"1", b"2", b"3"))337 self.assertEqual(self.parser.parse(b"1,3,2"), (b"1", b"3", b"2"))338 self.assertEqual(self.parser.parse(b"1,3"), (b"1", b"3"))339 self.assertEqual(self.parser.parse(b"3"), (b"3",))340 def test_failure(self):341 self.assertEqual(self.parser.parse(b""), None)342class TestEpsilonP1(unittest.TestCase):343 @classmethod344 def setUpClass(cls):345 cls.parser = h.sequence(h.ch(b"a"), h.epsilon_p(), h.ch(b"b"))346 def test_success(self):347 self.assertEqual(self.parser.parse(b"ab"), (b"a", b"b"))348 def test_failure(self):349 pass350class TestEpsilonP2(unittest.TestCase):351 @classmethod352 def setUpClass(cls):353 cls.parser = h.sequence(h.epsilon_p(), h.ch(b"a"))354 def test_success(self):355 self.assertEqual(self.parser.parse(b"a"), (b"a",))356 def test_failure(self):357 pass358class TestEpsilonP3(unittest.TestCase):359 @classmethod360 def setUpClass(cls):361 cls.parser = h.sequence(h.ch(b"a"), h.epsilon_p())362 def test_success(self):363 self.assertEqual(self.parser.parse(b"a"), (b"a",))364 def test_failure(self):365 pass366class TestAttrBool(unittest.TestCase):367 @classmethod368 def setUpClass(cls):369 cls.parser = h.attr_bool(h.many1(h.choice(h.ch(b"a"), h.ch(b"b"))),370 lambda x: x[0] == x[1])371 def test_success(self):372 self.assertEqual(self.parser.parse(b"aa"), (b"a", b"a"))373 self.assertEqual(self.parser.parse(b"bb"), (b"b", b"b"))374 def test_failure(self):375 self.assertEqual(self.parser.parse(b"ab"), None)376class TestAnd1(unittest.TestCase):377 @classmethod378 def setUpClass(cls):379 cls.parser = h.sequence(h.and_(h.ch(b"0")), h.ch(b"0"))380 def test_success(self):381 self.assertEqual(self.parser.parse(b"0"), (b"0",))382 def test_failure(self):383 pass384class TestAnd2(unittest.TestCase):385 @classmethod386 def setUpClass(cls):387 cls.parser = h.sequence(h.and_(h.ch(b"0")), h.ch(b"1"))388 def test_success(self):389 pass390 def test_failure(self):391 self.assertEqual(self.parser.parse(b"0"), None)392class TestAnd3(unittest.TestCase):393 @classmethod394 def setUpClass(cls):395 cls.parser = h.sequence(h.ch(b"1"), h.and_(h.ch(b"2")))396 def test_success(self):397 self.assertEqual(self.parser.parse(b"12"), (b"1",))398 def test_failure(self):399 pass400class TestNot1(unittest.TestCase):401 @classmethod402 def setUpClass(cls):403 cls.parser = h.sequence(h.ch(b"a"),404 h.choice(h.ch(b"+"), h.token(b"++")),405 h.ch(b"b"))406 def test_success(self):407 self.assertEqual(self.parser.parse(b"a+b"), (b"a", b"+", b"b"))408 def test_failure(self):409 self.assertEqual(self.parser.parse(b"a++b"), None)410class TestNot2(unittest.TestCase):411 @classmethod412 def setUpClass(cls):413 cls.parser = h.sequence(h.ch(b"a"), h.choice(h.sequence(h.ch(b"+"), h.not_(h.ch(b"+"))),414 h.token(b"++")),415 h.ch(b"b"))416 def test_success(self):417 self.assertEqual(self.parser.parse(b"a+b"), (b"a", (b"+",), b"b"))418 self.assertEqual(self.parser.parse(b"a++b"), (b"a", b"++", b"b"))419 def test_failure(self):420 pass421# ### this is commented out for packrat in C ...422# #class TestLeftrec(unittest.TestCase):423# # @classmethod424# # def setUpClass(cls):425# # cls.parser = h.indirect()426# # a = h.ch(b"a")427# # h.bind_indirect(cls.parser, h.choice(h.sequence(cls.parser, a), a))428# # def test_success(self):429# # self.assertEqual(self.parser.parse(b"a"), b"a")430# # self.assertEqual(self.parser.parse(b"aa"), [b"a", b"a"])431# # self.assertEqual(self.parser.parse(b"aaa"), [b"a", b"a", b"a"])432# # def test_failure(self):433# # pass434class TestRightrec(unittest.TestCase):435 @classmethod436 def setUpClass(cls):437 #raise unittest.SkipTest(b"Bind doesn't work right now")438 cls.parser = h.indirect()439 a = h.ch(b"a")440 cls.parser.bind(h.choice(h.sequence(a, cls.parser),441 h.epsilon_p()))442 def test_success(self):443 self.assertEqual(self.parser.parse(b"a"), (b"a",))444 self.assertEqual(self.parser.parse(b"aa"), (b"a", (b"a",)))445 self.assertEqual(self.parser.parse(b"aaa"), (b"a", (b"a", (b"a",))))446 def test_failure(self):447 pass448# ### this is just for GLR449# #class TestAmbiguous(unittest.TestCase):450# # @classmethod451# # def setUpClass(cls):452# # cls.parser = h.indirect()453# # d = h.ch(b"d")454# # p = h.ch(b"+")455# # h.bind_indirect(cls.parser, h.choice(h.sequence(cls.parser, p, cls.parser), d))456# # # this is supposed to be flattened457# # def test_success(self):458# # self.assertEqual(self.parser.parse(b"d"), [b"d"])459# # self.assertEqual(self.parser.parse(b"d+d"), [b"d", b"+", b"d"])460# # self.assertEqual(self.parser.parse(b"d+d+d"), [b"d", b"+", b"d", b"+", b"d"])461# # def test_failure(self):...

Full Screen

Full Screen

cancellation.spec.ts

Source:cancellation.spec.ts Github

copy

Full Screen

1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT license.3import { EnvVarKeys, getEnvVars } from "./utils/testUtils";4import { EventHubConsumerClient, EventHubProducerClient } from "../../src";5import { AbortController } from "@azure/abort-controller";6import chai from "chai";7import chaiAsPromised from "chai-as-promised";8import { createMockServer } from "./utils/mockService";9import { testWithServiceTypes } from "./utils/testWithServiceTypes";10const should = chai.should();11chai.use(chaiAsPromised);12testWithServiceTypes((serviceVersion) => {13 const env = getEnvVars();14 if (serviceVersion === "mock") {15 let service: ReturnType<typeof createMockServer>;16 before("Starting mock service", () => {17 service = createMockServer();18 return service.start();19 });20 after("Stopping mock service", () => {21 return service?.stop();22 });23 }24 describe("Cancellation via AbortSignal", () => {25 const service = {26 connectionString: env[EnvVarKeys.EVENTHUB_CONNECTION_STRING],27 path: env[EnvVarKeys.EVENTHUB_NAME],28 };29 before("validate environment", () => {30 should.exist(31 env[EnvVarKeys.EVENTHUB_CONNECTION_STRING],32 "define EVENTHUB_CONNECTION_STRING in your environment before running integration tests."33 );34 should.exist(35 env[EnvVarKeys.EVENTHUB_NAME],36 "define EVENTHUB_NAME in your environment before running integration tests."37 );38 });39 const TEST_FAILURE = "Test failure";40 const cancellationCases = [41 {42 type: "pre-aborted",43 getSignal() {44 const controller = new AbortController();45 controller.abort();46 return controller.signal;47 },48 },49 {50 type: "aborted after timeout",51 getSignal() {52 const controller = new AbortController();53 setTimeout(() => {54 controller.abort();55 }, 0);56 return controller.signal;57 },58 },59 ];60 describe("EventHubConsumerClient", () => {61 let consumerClient: EventHubConsumerClient;62 beforeEach("instantiate EventHubConsumerClient", () => {63 consumerClient = new EventHubConsumerClient(64 EventHubConsumerClient.defaultConsumerGroupName,65 service.connectionString,66 service.path67 );68 });69 afterEach("close EventHubConsumerClient", () => {70 return consumerClient.close();71 });72 for (const { type: caseType, getSignal } of cancellationCases) {73 it(`getEventHubProperties supports cancellation (${caseType})`, async () => {74 const abortSignal = getSignal();75 try {76 await consumerClient.getEventHubProperties({ abortSignal });77 throw new Error(TEST_FAILURE);78 } catch (err: any) {79 should.equal(err.name, "AbortError");80 should.equal(err.message, "The operation was aborted.");81 }82 });83 it(`getPartitionIds supports cancellation (${caseType})`, async () => {84 const abortSignal = getSignal();85 try {86 await consumerClient.getPartitionIds({ abortSignal });87 throw new Error(TEST_FAILURE);88 } catch (err: any) {89 should.equal(err.name, "AbortError");90 should.equal(err.message, "The operation was aborted.");91 }92 });93 it(`getPartitionProperties supports cancellation (${caseType})`, async () => {94 const abortSignal = getSignal();95 try {96 await consumerClient.getPartitionProperties("0", { abortSignal });97 throw new Error(TEST_FAILURE);98 } catch (err: any) {99 should.equal(err.name, "AbortError");100 should.equal(err.message, "The operation was aborted.");101 }102 });103 }104 });105 describe("EventHubProducerClient", () => {106 let producerClient: EventHubProducerClient;107 beforeEach("instantiate EventHubProducerClient", () => {108 producerClient = new EventHubProducerClient(service.connectionString, service.path);109 });110 afterEach("close EventHubProducerClient", () => {111 return producerClient.close();112 });113 for (const { type: caseType, getSignal } of cancellationCases) {114 it(`getEventHubProperties supports cancellation (${caseType})`, async () => {115 const abortSignal = getSignal();116 try {117 await producerClient.getEventHubProperties({ abortSignal });118 throw new Error(TEST_FAILURE);119 } catch (err: any) {120 should.equal(err.name, "AbortError");121 should.equal(err.message, "The operation was aborted.");122 }123 });124 it(`getPartitionIds supports cancellation (${caseType})`, async () => {125 const abortSignal = getSignal();126 try {127 await producerClient.getPartitionIds({ abortSignal });128 throw new Error(TEST_FAILURE);129 } catch (err: any) {130 should.equal(err.name, "AbortError");131 should.equal(err.message, "The operation was aborted.");132 }133 });134 it(`getPartitionProperties supports cancellation (${caseType})`, async () => {135 const abortSignal = getSignal();136 try {137 await producerClient.getPartitionProperties("0", { abortSignal });138 throw new Error(TEST_FAILURE);139 } catch (err: any) {140 should.equal(err.name, "AbortError");141 should.equal(err.message, "The operation was aborted.");142 }143 });144 it(`createBatch supports cancellation (${caseType})`, async () => {145 const abortSignal = getSignal();146 try {147 await producerClient.createBatch({ abortSignal });148 throw new Error(TEST_FAILURE);149 } catch (err: any) {150 should.equal(err.name, "AbortError");151 should.equal(err.message, "The operation was aborted.");152 }153 });154 it(`sendBatch supports cancellation (${caseType})`, async () => {155 const abortSignal = getSignal();156 try {157 await producerClient.sendBatch([{ body: "unsung hero" }], { abortSignal });158 throw new Error(TEST_FAILURE);159 } catch (err: any) {160 should.equal(err.name, "AbortError");161 should.equal(err.message, "The operation was aborted.");162 }163 });164 }165 });166 });...

Full Screen

Full Screen

SELEC_test.py

Source:SELEC_test.py Github

copy

Full Screen

2import pandas as pd3#ohe_Ace unit test4class Test_oheace(unittest.TestCase):5 #We can test if the two row numbers before and after encoding are the same6 def test_failure(self):7 import SELEC8 df_battery = pd.read_csv('Battery_Dataset.csv')9 assert len(SELEC.ohe_ACE(df_battery)) == len(df_battery), 'The encoded row numbers are not identical'10 11#ohe_df unit test12class Test_ohedf(unittest.TestCase):13 #We can test if the two rows we select are the same14 def test_failure(self):15 import SELEC16 df_battery = pd.read_csv('Battery_Dataset.csv')17 assert len(SELEC.ohe_dataframe(df_battery)) == len(df_battery), 'The encoded df has different rows'18 19#Data split unit test20class Test_split(unittest.TestCase):21 #We can test if the two rows we select are the same22 def test_failure(self):23 import SELEC24 df_battery = pd.read_csv('Battery_Dataset.csv')25 train,test,X_train,y_train,X_test,y_test = SELEC.data_split(df_battery, 0.2, 'Discharge_Capacity (Ah)', 66)26 assert len(X_train) == len(df_battery) * 0.8, 'The dataset has not been splited correctly'27 28##kfolds unit test29class Test_kf(unittest.TestCase):30 #We can test if the two rows we select are the same31 def test_failure(self):32 import SELEC33 kf = SELEC.kfold(10,66)34 assert kf.random_state == 66, 'The kFolds has wrong random states'35 36##Data Scale Test37#Data scale unit test38class Test_scale(unittest.TestCase):39 #We can test if the two rows we select are the same40 def test_failure(self):41 import SELEC42 df_battery = pd.read_csv('Battery_Dataset.csv')43 train,test,X_train,y_train,X_test,y_test = SELEC.data_split(df_battery, 0.2, 'Discharge_Capacity (Ah)', 66)44 X_train_scaled, X_test_scaled = SELEC.data_scale(X_train, X_test)45 assert len(X_test_scaled) == len(df_battery) * 0.2, 'The X_test data has not been properly scaled'46 47##GridSearchCv48#Hyperparameter unit test49class Test_hp(unittest.TestCase):50 #We can test if the two rows we select are the same51 def test_failure(self):52 import SELEC53 df_battery = pd.read_csv('Battery_Dataset.csv')54 alg, n_neigh, weight = SELEC.grid_knn_hp(1, 51, df_battery, 'Discharge_Capacity (Ah)')55 alg2, n_neigh2, weight2 = SELEC.grid_knn_hp(1, 51, df_battery, 'Discharge_Capacity (Ah)')56 assert n_neigh == n_neigh2, 'Two sets of hyperparameters are not identical, try again'57##Model train58#Model unit test59class Test_ml(unittest.TestCase):60 #We can test if the two rows we select are the same61 def test_failure(self):62 import SELEC63 df_battery = pd.read_csv('Battery_Dataset.csv')64 knn_train_RMSE_avg = SELEC.knn_train(df_battery, 'Discharge_Capacity (Ah)')65 knn_train_RMSE_avg2 = SELEC.knn_train(df_battery, 'Discharge_Capacity (Ah)')66 assert knn_train_RMSE_avg == knn_train_RMSE_avg, 'We have a different accuracy'67 68##Model test69#Model test unit test70class Test_mlt(unittest.TestCase):71 #We can test if the two rows we select are the same72 def test_failure(self):73 import SELEC74 df_battery = pd.read_csv('Battery_Dataset.csv')75 knn_test_RMSE = SELEC.knn_test(df_battery, 'Discharge_Capacity (Ah)')76 knn_test_RMSE2 = SELEC.knn_test(df_battery, 'Discharge_Capacity (Ah)')77 assert knn_test_RMSE == knn_test_RMSE2, 'We have a different accuracy'78##Dataset Prepare79#X-set unit test80class Test_x(unittest.TestCase):81 #We can test if the two rows we select are the same82 def test_failure(self):83 import SELEC84 df_battery = pd.read_csv('Battery_Dataset.csv')85 X_set = SELEC.X_set_in(df_battery)86 assert X_set.columns.all != ['anode', 'cathode', 'electrolyte', 'Cycle', 'temperature', 'discharge_crate'], 'X set has different inputs'87 88#X-set encode unit test89class Test_xen(unittest.TestCase):90 #We can test if the two rows we select are the same91 def test_failure(self):92 import SELEC93 df_battery = pd.read_csv('Battery_Dataset.csv')94 X_set = SELEC.X_set_in(df_battery)95 X_set_EN = SELEC.X_set_en(df_battery)96 assert len(X_set_EN) == len(X_set), 'The encoded X set has different rows'97 98##Predictor unit test99#predictor prep unit test100class Test_pp(unittest.TestCase):101 #We can test if the two rows we select are the same102 def test_failure(self):103 import SELEC104 df_battery = pd.read_csv('Battery_Dataset.csv')105 X_bat, y_bat = SELEC.df_prep(df_battery, 'Discharge_Capacity (Ah)')106 assert len(X_bat) == len(y_bat), 'The x has different row values to y'107 108#predictor unit test109class Test_ppy(unittest.TestCase):110 #We can test if the two rows we select are the same111 def test_failure(self):112 import SELEC113 df_battery = pd.read_csv('Battery_Dataset.csv')114 y_pred = SELEC.battery_predictor(df_battery, 'Discharge_Capacity (Ah)')115 y_pred2 = SELEC.battery_predictor(df_battery, 'Discharge_Capacity (Ah)')116 assert y_pred.all() == y_pred2.all(), 'The two predictions are diffrent'117 118##Report unit test119#Report unit test120class Test_report(unittest.TestCase):121 #We can test if the two rows we select are the same122 def test_failure(self):123 import SELEC124 df_battery = pd.read_csv('Battery_Dataset.csv')125 report = SELEC.report_gen(df_battery)126 X_set = SELEC.X_set_in(df_battery)...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

...27 ... failureException = AssertionError28 ... def fail(self, line=None):29 ... raise self.failureException(line or 'Test case failed!')30 >>> d = DummyTestCase()31 >>> def test_failure(self):32 ... self.fail('This test should fail silently.')33 >>> fails(test_failure)(d)34 >>> def test_failure(self):35 ... pass36 >>> fails(test_failure)(d)37 Traceback (most recent call last):38 ...39 AssertionError: Test unexpectedly passed40 >>> def test_failure(self):41 ... raise ValueError('Errors propogate through.')42 >>> fails(test_failure)(d)43 Traceback (most recent call last):44 ...45 ValueError: Errors propogate through.46 '''#'''47 @wraps(test_function)48 def test_wrapper(test_case):49 try: test_function(test_case)50 except test_case.failureException: pass51 else: test_case.fail('Test unexpectedly passed')52 return test_wrapper53def failing(exception):54 ''' Marks a test as throwing an exception, notifying the user otherwise.55 >>> class DummyTestCase:56 ... failureException = AssertionError57 ... def fail(self, line=None):58 ... raise self.failureException(line or 'Test case failed!')59 ... @failing(ValueError)60 ... def test_failure(self):61 ... self.fail()62 ... @failing(ValueError)63 ... def test_passing(self):64 ... pass65 ... @failing(ValueError)66 ... def test_expected(self):67 ... raise ValueError('This error should be silenced.')68 ... @failing(ValueError)69 ... def test_error(self):70 ... raise UserWarning('Other errors propogate through.')71 ...72 >>> d = DummyTestCase()73 >>> d.test_failure()74 Traceback (most recent call last):75 ...76 AssertionError: Test case failed!77 >>> d.test_passing()78 Traceback (most recent call last):79 ...80 AssertionError: Test unexpectedly passed81 >>> d.test_expected()82 >>> d.test_error()83 Traceback (most recent call last):84 ...85 UserWarning: Other errors propogate through.86 '''#'''87 def decorator(test_function):...

Full Screen

Full Screen

test_world.py

Source:test_world.py Github

copy

Full Screen

...12def test_world():13 w = world.PDDLWorld(domain_file='blocks-domain-updated.pddl', problem_directory="multitower", problem_number=1)14 plan = w.find_plan()15 for action, args in plan:16 assert(w.test_failure() is False)17 w.update(action, args)18 assert(w.test_success())19 w = world.PDDLWorld(domain_file='blocks-domain-updated.pddl', problem_directory="multitower", problem_number=1)20 w.update('put', ['b0', 't1', 'tower1'])21 w.update('put', ['b5', 'b0', 'tower1'])22 assert(w.test_failure())23 w.back_track()24 plan = w.find_plan()25 for action, args in plan:26 w.update(action, args)27 assert(w.test_success())28def test_world2():29 w = world.PDDLWorld(domain_file='blocks-domain.pddl', problem_directory="tworules", problem_number=1)30 plan = w.find_plan()31 for action, args in plan:32 assert(w.test_failure() is False)33 w.update(action, args)34 assert(w.test_success())35def test_world3():36 w = world.RandomColoursWorld(domain_file='blocks-domain-updated.pddl', problem_directory="multitower", problem_number=1)37 plan = w.find_plan()38 for action, args in plan:39 assert(w.test_failure() is False)40 w.update(action, args)41 assert(w.test_success())42 w = world.PDDLWorld(domain_file='blocks-domain-updated.pddl', problem_directory="multitower", problem_number=1)43 w.update('put', ['b0', 't1', 'tower1'])44 w.update('put', ['b5', 'b0', 'tower1'])45 assert(w.test_failure())46 w.back_track()47 plan = w.find_plan()48 for action, args in plan:49 w.update(action, args)50 assert(w.test_success())51def test_failure():52 w = world.PDDLWorld(domain_file='blocks-domain-updated.pddl',53 problem_directory="multitower", problem_number=1)54 w.update('put', ['b0', 't0', 'tower0'])55 w.update('put', ['b5', 'b0', 'tower0'])56 assert(w.test_failure())57def test_unstack():58 w = world.PDDLWorld(59 domain_file='blocks-domain-unstackable.pddl',60 problem_directory='multitower', problem_number=8)61 s = copy.deepcopy(w.state)62 w.update('put', ['b0', 't0', 'tower0'])63 w.update('unstack', ['b0', 't0', 'tower0'])64 assert(s == w.state)65 w.update('put', ['b8', 't0', 'tower0'])66 w.update('put', ['b4', 'b8', 'tower0'])67 w.update('put', ['b0', 'b4', 'tower0'])...

Full Screen

Full Screen

apiMiddlewareHook.spec.js

Source:apiMiddlewareHook.spec.js Github

copy

Full Screen

1import { expect } from 'chai';2import { CALL_API } from 'redux-api-middleware';3import apiMiddlewareHook from '../apiMiddlewareHook';4const createFakeStore = () => {};5const dispatchWithStoreOf = (storeData, action) => {6 let dispatched = null;7 const dispatch = apiMiddlewareHook(createFakeStore(storeData))(8 actionAttempt => dispatched = actionAttempt9 );10 dispatch(action);11 return dispatched;12};13describe('CamelizeState Middleware', function camelizeSateMiddleware() {14 it('should stringify body', function stringifyBody() {15 expect(16 dispatchWithStoreOf({}, {17 [CALL_API]: {18 endpoint: 'http://host',19 body: { key: 'value' },20 method: 'GET',21 headers: {},22 types: ['TEST_REQUEST', 'TEST_SUCCESS', 'TEST_FAILURE']23 }24 })[CALL_API].body25 ).to.equal(JSON.stringify({ key: 'value' }));26 });27 it('should serialize form body', () => {28 expect(29 dispatchWithStoreOf({}, {30 [CALL_API]: {31 endpoint: 'http://host',32 method: 'GET',33 types: ['TEST_REQUEST', 'TEST_SUCCESS', 'TEST_FAILURE'],34 headers: { 'Content-Type': 'application/x-www-form-urlencoded' },35 body: {36 key1: 'value1',37 key2: 'value2'38 }39 }40 })[CALL_API]41 ).to.deep.equal({42 endpoint: 'http://host',43 method: 'GET',44 types: ['TEST_REQUEST', 'TEST_SUCCESS', 'TEST_FAILURE'],45 headers: { 'Content-Type': 'application/x-www-form-urlencoded' },46 body: 'key1=value1&key2=value2'47 });48 });49 it('should decamelize body', () => {50 expect(51 dispatchWithStoreOf({}, {52 [CALL_API]: {53 endpoint: 'http://host',54 method: 'GET',55 types: ['TEST_REQUEST', 'TEST_SUCCESS', 'TEST_FAILURE'],56 headers: {},57 body: { testData: 'value', }58 }59 })[CALL_API]60 ).to.deep.equal({61 endpoint: 'http://host',62 method: 'GET',63 types: ['TEST_REQUEST', 'TEST_SUCCESS', 'TEST_FAILURE'],64 headers: {},65 body: JSON.stringify({ 'test_data': 'value', })66 });67 });68 it('should not handle invalid RSSA', () => {69 expect(70 dispatchWithStoreOf({}, {71 type: 'TEST', payload: { body: { testData: 'value', } }72 })73 ).to.deep.equal({74 type: 'TEST', payload: { body: { testData: 'value', } }75 });76 });...

Full Screen

Full Screen

failure.test.ts

Source:failure.test.ts Github

copy

Full Screen

1import { createFailure, isFailureOfType } from './failure'2describe('failure', () => {3 const TEST_FAILURE = 'TEST_FAILURE'4 type TEST_FAILURE = typeof TEST_FAILURE5 const testFailure = createFailure(TEST_FAILURE)6 it('constructs failure with correct name', () => {7 expect(testFailure()).toEqual({8 name: TEST_FAILURE,9 })10 })11 it('constructs failure with message and metadata', () => {12 const message = 'message'13 const metadata = { hello: 'world' }14 expect(testFailure(message, metadata)).toEqual({15 name: TEST_FAILURE,16 message,17 metadata18 })19 })20 it('handles string error', () => {21 const error = 'error'22 expect(testFailure(error)).toEqual({23 name: TEST_FAILURE,24 message: error,25 })26 })27 it('handles error instances', () => {28 const message = 'message'29 const error = new Error(message)30 expect(testFailure(error)).toEqual({31 name: TEST_FAILURE,32 message,33 })34 })35 it('gets catched', () => {36 const message = 'message'37 const error = new Error(message)38 const failure = testFailure(error)39 try {40 throw failure41 } catch (e) {42 expect(e).toEqual(failure)43 }44 })45 describe('isFailure', () => {46 it('returns false for undefined', () => {47 expect(isFailureOfType(undefined, TEST_FAILURE)).toEqual(false)48 })49 it('returns false for string', () => {50 expect(isFailureOfType('error', TEST_FAILURE)).toEqual(false)51 })52 it('returns false for Error', () => {53 expect(isFailureOfType(new Error('error'), TEST_FAILURE)).toEqual(false)54 })55 it('returns false for object without `name` property', () => {56 expect(isFailureOfType({}, TEST_FAILURE)).toEqual(false)57 })58 it('returns false for Failure of different type', () => {59 expect(isFailureOfType(testFailure(), 'SOMETHING_ELSE')).toEqual(false)60 })61 it('returns true for Failure of correct type', () => {62 expect(isFailureOfType(testFailure(), TEST_FAILURE)).toEqual(true)63 })64 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 wpt.testStatus(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 if (data.statusCode == 200) {7 console.log(data.statusText);8 } else {9 wpt.testFailure(data.data.testId, function(err, data) {10 if (err) return console.error(err);11 console.log(data);12 });13 }14 });15});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var test = wptools.page('Barack Obama');3test.test_failure(function(err, resp, body) {4 if (err) {5 console.log(err);6 } else {7 console.log(body);8 }9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var test = new wpt('www.webpagetest.org', options.key);5 if (err) {6 console.log('Error: ' + err);7 } else {8 console.log('Test ID: ' + data.data.testId);9 console.log('Test Status: ' + data.statusText);10 test.getTestResults(data.data.testId, function (err, data) {11 if (err) {12 console.log('Error: ' + err);13 } else {14 console.log('Test Status: ' + data.statusText);15 console.log('First View: ' + data.data.average.firstView.TTFB);16 console.log('Repeat View: ' + data.data.average.repeatView.TTFB);17 }18 });19 }20});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var options = {3};4wpt.test.run(options, function(err, data) {5 if (err) {6 console.log('Error: ' + err);7 } else {8 console.log(data);9 }10});11### test.run(options, callback)12 - `runs` - Number of test runs (default: 3)13 - `firstViewOnly` - Only test the first view of the page (default: false)14 - `pollResults` - Poll for results every `n` seconds (default: 15)

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