-
Notifications
You must be signed in to change notification settings - Fork 38
/
test_processor.py
753 lines (583 loc) · 28 KB
/
test_processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
import os
from os import path
from textwrap import dedent
from unittest import main
from getgauge import processor
from getgauge import static_loader as loader
from getgauge.messages.messages_pb2 import *
from getgauge.messages.spec_pb2 import Parameter, ProtoExecutionResult, Span
from getgauge.parser import Parser
from getgauge.messages.spec_pb2 import ProtoStepValue
from getgauge.util import get_step_impl_dirs
from getgauge.python import data_store
from getgauge.registry import registry
from pyfakefs.fake_filesystem_unittest import TestCase
class ProcessorTests(TestCase):
def setUp(self):
self.setUpPyfakefs()
data_store.suite.clear()
data_store.spec.clear()
data_store.scenario.clear()
registry.clear()
def tearDown(self):
registry.clear()
def load_content_steps(self, content):
content = dedent(content)
pf = Parser.parse("foo.py", content)
self.assertIsNotNone(pf)
loader.load_steps(pf)
def test_Processor_suite_data_store_init_request(self):
data_store.suite['suite'] = 'value'
self.assertNotEqual(0, len(data_store.suite))
response = processor.process_suite_data_store_init_request()
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
self.assertEqual(0, response.executionResult.executionTime)
self.assertDictEqual({}, data_store.suite)
def test_Processor_spec_data_store_init_request(self):
data_store.spec['spec'] = 'value'
self.assertNotEqual(0, len(data_store.spec))
response = processor.process_spec_data_store_init_request()
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
self.assertEqual(0, response.executionResult.executionTime)
self.assertDictEqual({}, data_store.spec)
def test_Processor_scenario_data_store_init_request(self):
data_store.scenario['scenario'] = 'value'
self.assertNotEqual(0, len(data_store.scenario))
response = processor.process_scenario_data_store_init_request()
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
self.assertEqual(0, response.executionResult.executionTime)
self.assertDictEqual({}, data_store.scenario)
def test_Processor_step_names_request(self):
registry.add_step('Step <a> with <b>', 'func', '')
registry.add_step('Step 4', 'func1', '')
response = processor.process_step_names_request()
self.assertIsInstance(response, StepNamesResponse)
self.assertEqual({'Step <a> with <b>', 'Step 4'}, set(response.steps))
def test_Processor_step_name_request(self):
registry.add_step('Step <a> with <b>', 'func', '', {
'start': 1, 'startChar': 0, 'end': 3, 'endChar': 10})
registry.add_step('Step 4', 'func1', '', {
'start': 5, 'startChar': 0, 'end': 6, 'endChar': 10})
request = StepNameRequest()
request.stepValue = 'Step {} with {}'
response = processor.process_step_name_request(request)
self.assertIsInstance(response, StepNameResponse)
self.assertEqual(['Step <a> with <b>'], response.stepName)
self.assertTrue(response.isStepPresent)
request = StepNameRequest()
self.assertFalse(response.hasAlias)
request.stepValue = 'Step 4'
response = processor.process_step_name_request(request)
self.assertIsInstance(response, StepNameResponse)
self.assertEqual(['Step 4'], response.stepName)
self.assertTrue(response.isStepPresent)
self.assertFalse(response.hasAlias)
def test_Processor_step_name_request_with_aliases(self):
registry.add_step(['Step 1', 'Step 2', 'Step 3'], 'func1', '',
{'start': 5, 'startChar': 0, 'end': 6, 'endChar': 10})
request = StepNameRequest()
request.stepValue = 'Step 1'
response = processor.process_step_name_request(request)
self.assertIsInstance(response, StepNameResponse)
self.assertIn('Step 1', response.stepName)
self.assertIn('Step 2', response.stepName)
self.assertIn('Step 3', response.stepName)
self.assertTrue(response.isStepPresent)
self.assertTrue(response.hasAlias)
def test_Processor_step_name_request_with_unimplemented_step(self):
request = StepNameRequest()
request.stepValue = 'Step {} with {}'
response = processor.process_step_name_request(request)
self.assertIsInstance(response, StepNameResponse)
self.assertEqual([], response.stepName)
self.assertFalse(response.isStepPresent)
self.assertFalse(response.hasAlias)
def test_Processor_valid_step_validate_request(self):
registry.add_step('Step <a> with <b>', 'func', '')
registry.add_step('Step 4', 'func1', '')
request = StepValidateRequest()
request.stepText = 'Step {} with {}'
response = processor.process_validate_step_request(request)
self.assertIsInstance(response, StepValidateResponse)
self.assertTrue(response.isValid)
def test_Processor_invalid_step_validate_request_when_no_impl_found(self):
registry.add_step('Step <a> with <b>', 'func', '')
registry.add_step('Step 4', 'func1', '')
request = StepValidateRequest()
request.stepText = 'Step2'
request.stepValue.stepValue = 'Step2'
response = processor.process_validate_step_request(request)
self.assertIsInstance(response, StepValidateResponse)
self.assertFalse(response.isValid)
self.assertEqual(StepValidateResponse.STEP_IMPLEMENTATION_NOT_FOUND,
response.errorType)
self.assertIn('@step("")\ndef step2():\n assert False, "Add implementation code"', response.suggestion)
def test_Processor_invalid_step_validate_request_when_duplicate_impl_found(self):
registry.add_step('Step <a> with <b>', impl, '', {'start': 0})
registry.add_step('Step <a> with <b>', impl, '', {'start': 2})
response = Message()
request = StepValidateRequest()
request.stepText = 'Step {} with {}'
response = processor.process_validate_step_request(request)
self.assertIsInstance(response, StepValidateResponse)
self.assertFalse(response.isValid)
self.assertEqual(StepValidateResponse.DUPLICATE_STEP_IMPLEMENTATION,
response.errorType)
def test_Processor_execute_step_request(self):
registry.add_step('Step 4', impl1, '')
request = ExecuteStepRequest()
request.parsedStepText = 'Step 4'
response = processor.process_execute_step_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
self.assertEqual(
'', response.executionResult.errorMessage)
self.assertEqual(
'', response.executionResult.stackTrace)
def test_Processor_execute_step_request_with_param(self):
registry.add_step('Step <a> with <b>', impl, '')
registry.add_step('Step 4', 'func1', '')
request = ExecuteStepRequest()
request.parsedStepText = 'Step {} with {}'
parameter = Parameter()
parameter.value = 'param 1'
parameter1 = Parameter()
parameter1.value = 'param 2'
request.parameters.extend([parameter, parameter1])
response = processor.process_execute_step_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
self.assertEqual(
'', response.executionResult.errorMessage)
self.assertEqual(
'', response.executionResult.stackTrace)
def test_Processor_failed_execute_step_request(self):
request = ExecuteStepRequest()
response = processor.process_execute_step_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertTrue(response.executionResult.failed)
self.assertEqual(ProtoExecutionResult.ASSERTION,
response.executionResult.errorType)
self.assertNotEqual(
'', response.executionResult.errorMessage)
self.assertNotEqual(
'', response.executionResult.stackTrace)
self.assertFalse(response.executionResult.recoverableError)
def test_Processor_failed_execute_step_request_with_continue_on_failure(self):
registry.add_step('Step 4', failing_impl, '')
registry.continue_on_failure(failing_impl, [IndexError])
request = ExecuteStepRequest()
request.parsedStepText = 'Step 4'
response = processor.process_execute_step_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertTrue(response.executionResult.failed)
self.assertEqual(ProtoExecutionResult.ASSERTION,
response.executionResult.errorType)
self.assertNotEqual('', response.executionResult.errorMessage)
self.assertNotEqual('', response.executionResult.stackTrace)
self.assertTrue(response.executionResult.recoverableError)
def test_Processor_starting_execution_request(self):
registry.add_before_suite(impl1)
registry.add_before_suite(impl2)
request = ExecutionStartingRequest()
response = processor.process_execution_starting_request(request, False)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
def test_Processor_ending_execution_request(self):
registry.add_after_suite(impl1)
registry.add_after_suite(impl2)
request = ExecutionEndingRequest()
response = processor.process_execution_ending_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
def test_Processor_spec_starting_execution_request(self):
registry.add_before_spec(impl1)
registry.add_before_spec(impl2)
request = SpecExecutionEndingRequest()
response = processor.process_spec_execution_starting_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
def test_Processor_spec_ending_execution_request(self):
registry.add_after_spec(impl1)
registry.add_after_spec(impl2)
request = SpecExecutionEndingRequest()
response = processor.process_spec_execution_ending_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
def test_Processor_scenario_starting_execution_request(self):
registry.add_before_scenario(impl1)
registry.add_before_scenario(impl2)
request = ScenarioExecutionStartingRequest()
response = processor.process_scenario_execution_starting_request(
request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
def test_Processor_scenario_ending_execution_request(self):
registry.add_after_scenario(impl1)
registry.add_after_scenario(impl2)
request = ScenarioExecutionEndingRequest()
response = processor.process_scenario_execution_ending_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
def test_Processor_step_starting_execution_request(self):
registry.add_before_step(impl1)
registry.add_before_step(impl2)
request = StepExecutionStartingRequest()
response = processor.process_step_execution_starting_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
def test_Processor_step_ending_execution_request(self):
registry.add_after_step(impl1)
registry.add_after_step(impl2)
request = StepExecutionEndingRequest()
response = processor.process_step_execution_ending_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertFalse(response.executionResult.failed)
def test_Processor_failing_starting_execution_request(self):
registry.add_before_suite(failing_impl)
request = ExecutionStartingRequest()
response = processor.process_execution_starting_request(
request, False)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertTrue(response.executionResult.failed)
self.assertEqual(ProtoExecutionResult.ASSERTION,
response.executionResult.errorType)
self.assertEqual('list index out of range',
response.executionResult.errorMessage)
self.assertNotEqual('', response.executionResult.stackTrace)
def test_Processor_failing_ending_execution_request(self):
registry.add_after_suite(failing_impl)
request = ExecutionEndingRequest()
response = processor.process_execution_ending_request(request)
print(response)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertTrue(response.executionResult.failed)
self.assertEqual(ProtoExecutionResult.ASSERTION,
response.executionResult.errorType)
self.assertEqual('list index out of range',
response.executionResult.errorMessage)
self.assertNotEqual('', response.executionResult.stackTrace)
def test_Processor_failing_spec_starting_execution_request(self):
registry.add_before_spec(failing_impl)
request = SpecExecutionStartingRequest()
response = processor.process_spec_execution_starting_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertTrue(response.executionResult.failed)
self.assertEqual(ProtoExecutionResult.ASSERTION,
response.executionResult.errorType)
self.assertEqual('list index out of range',
response.executionResult.errorMessage)
self.assertNotEqual('', response.executionResult.stackTrace)
def test_Processor_failing_spec_ending_execution_request(self):
registry.add_after_spec(failing_impl)
request = SpecExecutionEndingRequest()
response = processor.process_spec_execution_ending_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertTrue(response.executionResult.failed)
self.assertEqual(ProtoExecutionResult.ASSERTION,
response.executionResult.errorType)
self.assertEqual('list index out of range',
response.executionResult.errorMessage)
self.assertNotEqual('', response.executionResult.stackTrace)
def test_Processor_failing_scenario_starting_execution_request(self):
registry.add_before_scenario(failing_impl)
request = ScenarioExecutionStartingRequest()
response = processor.process_scenario_execution_starting_request(
request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertTrue(response.executionResult.failed)
self.assertEqual(ProtoExecutionResult.ASSERTION,
response.executionResult.errorType)
self.assertEqual('list index out of range',
response.executionResult.errorMessage)
self.assertNotEqual('', response.executionResult.stackTrace)
def test_Processor_failing_scenario_ending_execution_request(self):
registry.add_after_scenario(failing_impl)
request = ScenarioExecutionEndingRequest()
response = processor.process_scenario_execution_ending_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertTrue(response.executionResult.failed)
self.assertEqual(ProtoExecutionResult.ASSERTION,
response.executionResult.errorType)
self.assertEqual('list index out of range',
response.executionResult.errorMessage)
self.assertNotEqual('', response.executionResult.stackTrace)
def test_Processor_failing_step_starting_execution_request(self):
registry.add_before_step(failing_impl)
request = StepExecutionStartingRequest()
response = processor.process_step_execution_starting_request(request)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertTrue(response.executionResult.failed)
self.assertEqual(ProtoExecutionResult.ASSERTION,
response.executionResult.errorType)
self.assertEqual('list index out of range',
response.executionResult.errorMessage)
self.assertNotEqual('', response.executionResult.stackTrace)
def test_Processor_failing_step_ending_execution_request(self):
registry.add_after_step(failing_impl)
request = StepExecutionEndingRequest()
response = processor.process_step_execution_ending_request(request,)
self.assertIsInstance(response, ExecutionStatusResponse)
self.assertTrue(response.executionResult.failed)
self.assertEqual(ProtoExecutionResult.ASSERTION,
response.executionResult.errorType)
self.assertEqual('list index out of range',
response.executionResult.errorMessage)
self.assertNotEqual('', response.executionResult.stackTrace)
def test_Processor_refactor_request_when_multiple_impl_found(self):
registry.add_step('Step <a> with <b>', 'func', '')
registry.add_step('Step <a> with <b>', 'func', '')
request = RefactorRequest()
request.oldStepValue.stepValue = 'Step {} with {}'
request.oldStepValue.parameterizedStepValue = 'Step <a> with <b>'
response = processor.process_refactor_request(request)
self.assertIsInstance(response, RefactorResponse)
self.assertFalse(response.success)
self.assertEqual(
'Reason: Multiple Implementation found for `Step <a> with <b>`', response.error)
def test_Processor_step_position_request(self):
registry.add_step('Step <a> with <b>', 'func', 'foo.py',
{'start': 0, 'startChar': 0, 'end': 3, 'endChar': 10})
registry.add_step('Step 1', 'func', 'foo.py', {
'start': 4, 'startChar': 0, 'end': 7, 'endChar': 10})
request = StepPositionsRequest()
request.filePath = 'foo.py'
response = processor.process_step_positions_request(request)
self.assertIsInstance(response, StepPositionsResponse)
self.assertEqual('', response.error)
steps = [(p.stepValue, p.span.start)
for p in response.stepPositions]
self.assertIn(('Step {} with {}', 0), steps)
self.assertIn(('Step 1', 4), steps)
def test_Processor_put_stub_impl_request(self):
request = StubImplementationCodeRequest()
codes = ["code1", "code2"]
request.implementationFilePath = ""
request.codes.extend(codes)
response = processor.process_stub_impl_request(request)
expected_output_codes = dedent('''\
from getgauge.python import step
code1
code2''')
expected_span = Span(
**{'start': 0, 'startChar': 0, 'end': 0, 'endChar': 0})
expected_text_diff = TextDiff(
**{'span': expected_span, 'content': expected_output_codes})
self.assertEqual(len(response.textDiffs), 1)
self.assertEqual(response.textDiffs[0], expected_text_diff)
self.assertEqual(path.basename(
response.filePath), "step_implementation.py")
def test_Processor_glob_pattern(self):
request = ImplementationFileGlobPatternRequest()
response = processor.process_glob_pattern_request(request)
self.assertEqual(response.globPatterns, ["step_impl/**/*.py"])
def test_Processor_cache_file_with_opened_status(self):
request = CacheFileRequest()
self.load_content_steps('''\
from getgauge.python import step
@step('foo1')
def foo():
pass
''')
request.filePath = 'foo.py'
request.content = dedent('''\
from getgauge.python import step
@step('foo <bar>')
def foo():
pass
''')
request.status = CacheFileRequest.OPENED
processor.process_cache_file_request(request)
self.assertEqual(registry.is_implemented('foo1'), False)
self.assertEqual(registry.is_implemented('foo {}'), True)
def test_Processor_cache_file_with_changed_status(self):
request = CacheFileRequest()
self.load_content_steps('''\
from getgauge.python import step
@step('foo1')
def foo():
pass
''')
request.filePath = 'foo.py'
request.content = dedent('''\
from getgauge.python import step
@step('foo <bar>')
def foo():
pass
''')
request.status = CacheFileRequest.CHANGED
processor.process_cache_file_request(request)
self.assertFalse(registry.is_implemented('foo1'))
self.assertTrue(registry.is_implemented('foo {}'))
def test_Processor_cache_file_with_create_status(self):
request = CacheFileRequest()
request.filePath = 'foo.py'
request.status = CacheFileRequest.CREATED
self.fs.create_file('foo.py', contents=dedent('''\
from getgauge.python import step
@step('foo <bar>')
def foo():
pass
'''))
processor.process_cache_file_request(request)
self.assertTrue(registry.is_implemented('foo {}'))
def test_Processor_cache_file_with_create_status_when_file_is_cached(self):
request = CacheFileRequest()
self.load_content_steps('''\
from getgauge.python import step
@step('foo <bar>')
def foo():
pass
''')
self.assertTrue(registry.is_implemented('foo {}'))
request.filePath = 'foo.py'
request.status = CacheFileRequest.CREATED
self.fs.create_file('foo.py')
processor.process_cache_file_request(request)
self.assertTrue(registry.is_implemented('foo {}'))
def test_Processor_cache_file_with_closed_status(self):
request = CacheFileRequest()
self.load_content_steps('''\
from getgauge.python import step
@step('foo1')
def foo():
pass
''')
request.filePath = 'foo.py'
request.status = CacheFileRequest.CLOSED
self.fs.create_file('foo.py', contents=dedent('''\
from getgauge.python import step
@step('foo <bar>')
def foo():
pass
'''))
processor.process_cache_file_request(request)
self.assertFalse(registry.is_implemented('foo1'))
self.assertTrue(registry.is_implemented('foo {}'))
def test_Processor_cache_file_with_delete_status(self):
request = CacheFileRequest()
self.load_content_steps('''\
from getgauge.python import step
@step('foo1')
def foo():
pass
''')
request.filePath = 'foo.py'
request.status = CacheFileRequest.DELETED
processor.process_cache_file_request(request)
self.assertFalse(registry.is_implemented('foo1'))
def test_Processor_process_impl_files_request(self):
self.fs.create_file(os.path.join(get_step_impl_dirs()[0], 'foo.py'))
res = processor.process_impl_files_request()
self.assertEqual(os.path.basename(
res.implementationFilePaths[0]), 'foo.py')
def test_Processor_process_step_names_request(self):
self.load_content_steps('''\
@step('foo')
def foo():
pass
''')
res = processor.process_step_names_request()
self.assertEqual(res.steps, ['foo'])
def test_Processor_process_step_name_request(self):
self.load_content_steps('''\
@step('foo')
def foo():
pass
''')
req = StepNameRequest(stepValue='foo')
res = processor.process_step_name_request(req)
self.assertTrue(res.isStepPresent)
self.assertEqual(res.fileName, 'foo.py')
def test_Processor_process_validate_step_request(self):
self.load_content_steps('''\
@step('foo')
def foo():
pass
''')
step_value = ProtoStepValue(
stepValue='foo', parameterizedStepValue='foo')
req = StepValidateRequest(
stepText='foo', stepValue=step_value, numberOfParameters=0)
res = processor.process_validate_step_request(req)
self.assertTrue(res.isValid)
def test_Prcessor_process_step_positions_request(self):
self.load_content_steps('''\
@step('foo')
def foo():
pass
''')
req = StepPositionsRequest(filePath='foo.py')
res = processor.process_step_positions_request(req)
self.assertEqual(res.stepPositions[0].stepValue, 'foo')
def test_Processor_process_implement_stub_request(self):
self.load_content_steps("@step('foo')\ndef foo():\n\tpass\n")
req = StubImplementationCodeRequest(
implementationFilePath='New File', codes=['add hello'])
res = processor.process_stub_impl_request(req)
self.assertEqual(os.path.basename(res.filePath),
'step_implementation.py')
self.assertEqual(
res.textDiffs[0].content, 'from getgauge.python import step\n\nadd hello')
def test_Processor_process_refactor_request(self):
content = dedent('''\
from getgauge.python import step
@step('Vowels in English language are <aeiou>.')
def foo(vowels):
print(vowels)
''')
self.fs.create_file(os.path.join(
get_step_impl_dirs()[0], 'foo.py'), contents=content)
loader.load_files(get_step_impl_dirs())
request = RefactorRequest()
request.saveChanges = False
request.oldStepValue.stepValue = 'Vowels in English language are {}.'
request.oldStepValue.parameters.append('vowels')
request.newStepValue.parameterizedStepValue = 'Vowels in English language is <vowels> <bsdfdsf>.'
request.newStepValue.stepValue = 'Vowels in English language is {} {}.'
request.newStepValue.parameters.extend(['vowels', 'bsdfdsf'])
position = ParameterPosition()
position.oldPosition = 0
position.newPosition = 0
param_position = ParameterPosition()
param_position.oldPosition = -1
param_position.newPosition = 1
request.paramPositions.extend([position, param_position])
res = processor.process_refactor_request(request)
self.assertTrue(res.success)
diff_contents = [diff.content for diff in res.fileChanges[0].diffs]
self.assertIn("vowels, arg1", diff_contents)
self.assertIn(
"'Vowels in English language is <vowels> <bsdfdsf>.'", diff_contents)
def test_Processor_process_cache_file_request(self):
self.load_content_steps('''\
from getgauge.python import step
@step('Vowels in English language are <aeiou>.')
def foo(vowels):
print(vowels)
''')
self.assertTrue(registry.is_implemented(
'Vowels in English language are {}.'))
content = dedent('''\
from getgauge.python import step
@step('get lost!')
def foo():
pass
''')
req = CacheFileRequest(
content=content, filePath='foo.py', status=CacheFileRequest.CHANGED)
processor.process_cache_file_request(req)
self.assertTrue(registry.is_implemented('get lost!'))
def impl(a, b):
pass
def impl1():
pass
def impl2(context):
pass
def failing_impl():
print([][1])
if __name__ == '__main__':
main()