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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
|
# -*- Encoding: UTF-8 -*-
###
# Copyright (c) 2008-2009, Elián Hanisch
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###
from common import now
import sys, os, re
from supybot.test import *
import supybot.ircmsgs as ircmsgs
import supybot.irclib as irclib
# Sometimes I test this plugin in a directory with a name other than 'Factos' (think a branch)
# unfortunately loadPluginModule('Factos') will load Factos hence screwing up all the tests
# I have to use this hack for detect which plugin I should load while testing.
modules = [ m for m in sys.argv[1:] if m in os.listdir('.') ]
if len(modules) != 1:
print 'Test Factos alone without other plugins'
sys.exit(-1)
ourPlugin= modules[0]
Fconf = conf.supybot.plugins.Factos
class CommonReplies:
"""Because I don't like typing the same thing too many times."""
notFound = 'El facto @%s no existe.'
created = 'Facto @%s creado.'
edit = 'Facto @%s actualizado.'
maxlen = 'Me diste un facto de %s carácteres. El máximo es 400.'
dup = '@%s ya existe. Si desea editarlo utilise @no.'
locked = '@%s está protegido contra cambios.'
forbidden = '@%s está bloqueado.'
deleted = 'Facto @%s borrado.'
repeat = 'Dije @%s hace un rato, mirá más arriba.'
alias_repeat = '@%s es lo mismo que @%s, ya lo dije hace un rato, mirá más arriba.'
nouser = 'No veo a nadie llamado %s.'
def __call__(self, name, *args):
s = getattr(self, name)
return s % args
reply = CommonReplies()
class FactosTestCase(ChannelPluginTestCase):
plugins = (ourPlugin, )
def botrestart(self):
for cb in self.irc.callbacks:
if cb.name() == 'Factos':
break
cb.db.indexes = {} # clear dicts, like in a bot restart
cb.db.tables = {}
cb.db.users = {}
try:
del cb.db.db
except:
pass
def assertMatchRegexp(self, string, regexp, flags=re.I):
self.failUnless(re.search(regexp, string, flags),
'%r does not match %r' % (string, regexp))
return string
def setUp(self):
super(FactosTestCase, self).setUp()
self.irc.state.channels[self.channel].addUser('user')
self.irc.state.channels[self.channel].addUser('user2')
self.irc.state.channels['#test1'] = irclib.ChannelState()
self.irc.state.channels['#test1'].addUser('user')
self.prefix = 'test!user@factos.net'
Fconf.repeatProtection.setValue(False)
Fconf.repeatProtection.collision.setValue(False)
def testFact(self):
self.assertResponse('foobar', reply('notFound', 'foobar'))
self.assertResponse('foobar es una prueba', reply('created', 'foobar'))
self.assertResponse('foobar', 'foobar es una prueba')
self.assertResponse('foobar: ...', reply('dup', 'foobar'))
self.assertResponse('foo: bar', reply('created', 'foo'))
self.assertResponse('foo', 'bar')
#charlimits
s = 'a' * 401
self.assertResponse('longfact:%s' % s , reply('maxlen', len(s)))
s = 'a' * 26
self.assertRegexp('%s:asd' % s, '^El nombre del facto tiene 26 carácteres.')
# invalid facts
#self.assertError('test : ')
#self.assertError(' : test ') # gets ignored
#self.assertError('test es ')
#self.assertError(' es test ')
# add a disabled fact
self.assertNotError('borrar foo')
self.assertResponse('foo es otro foo', reply('created', 'foo'))
self.assertResponse('foo', 'foo es otro foo')
def testFactSpecialTests(self):
self.assertNotError('foo es bar')
# don't save users that just call facts
self.prefix = 'nosave!user@factos.net'
try:
self.assertNotError('foo')
self.assertRegexp('editor nosave!*@*', r'^No encontré ningún usuario.*$', private=True)
finally:
self.prefix = 'test!user@factos.net'
# add a fact with quotes
#conf.supybot.commands.quotes.set('')
self.assertResponse('comillas es "dobles" y \'simples\'', reply('created', 'comillas'))
self.assertResponse('comillas', 'comillas es "dobles" y \'simples\'')
# channels that end with 'es'
self.assertNotError('bar#test-es es un facto.')
self.assertResponse('bar#test-es', 'bar es un facto.')
# a fact 'no' shouldn't conflic with editing
self.assertResponse('no es no!', reply('created', 'no'))
self.assertResponse('no', 'no es no!')
self.assertResponse('no, user', 'user: no es no!')
self.assertResponse('no, no es si!', reply('edit', 'no'))
self.assertResponse('no', 'no es si!')
def testFactChannelPrefix(self):
# test facts with '#' on their names
self.assertResponse('#kubuntu-es es un canal de soporte', reply('created', '#kubuntu-es'))
self.assertResponse('#kubuntu-es', '#kubuntu-es es un canal de soporte')
self.assertResponse('#kubuntu-es#test es un facto', reply('created', '#kubuntu-es#test'))
self.assertResponse('#kubuntu-es', '#kubuntu-es es un facto')
self.assertResponse('#kubuntu-es#', '#kubuntu-es es un canal de soporte')
def testFactHighlight(self):
self.assertNotError('foo : bar')
self.assertResponse('foo', 'bar')
m = self.getMsg('foo>user')
self.assertEqual(m.args[0], 'user')
self.assertEqual(m.args[1], 'bar')
self.assertResponse('foo|user', 'user: bar')
self.assertResponse('foo user', 'user: bar')
self.assertResponse('foo, user', 'user: bar')
# prefix bot's nick
self.prefix = 'moo!user@factos.net'
# I don't understand why the following test fails with the nick prefixed in the expected reply
self.assertResponse('foo test', 'Yo ya se que es @foo, gracias.')
self.assertResponse('foo>test', 'Yo ya se que es @foo, gracias.')
# when our own nick should always go in private
m = self.getMsg('foo moo')
self.assertEqual(m.args[0], 'moo')
# user no present in channel
self.assertResponse('foo nouser', reply('nouser', 'nouser'))
self.assertResponse('foo>nouser', reply('nouser', 'nouser'))
# bot should refuse to redirect a fact in a query
self.assertResponse('foo user', 'Lo siento, dile @foo tu mismo.', private=True)
self.assertResponse('foo>user', 'Lo siento, dile @foo tu mismo.', private=True)
self.prefix = 'test!user@factos.net'
# using ' ' is for prefix one nick, while with '|' can be anything
self.assertResponse('foo|Did you know?', 'Did you know?: bar')
def testFactTell(self):
self.assertNotError('foo:bar')
m = self.getMsg('dile a user sobre foo')
self.assertEqual(m.args[0], 'user')
self.assertEqual(m.args[1], 'bar')
m = self.irc.takeMsg()
self.assertEqual(m.args[0], '#test')
self.assertEqual(m.args[1], 'user: por favor mira mi mensaje privado.')
# if there was an error the 'see my private msg' shouldn't be send
self.assertResponse('dile a nouser sobre foo', reply('nouser', 'nouser'))
self.assertResponse('dile a user sobre moo', reply('notFound', 'moo'))
self.assertResponse('foo', 'bar')
def testEditFact(self):
self.assertResponse('no, foo es bar', reply('notFound', 'foo'))
self.assertNotError('foo:bar')
self.assertResponse('foo', 'bar')
self.assertResponse('no, foo es bar', reply('edit', 'foo'))
self.assertResponse('foo', 'foo es bar')
self.assertResponse('no foo : bar', reply('edit', 'foo'))
self.assertResponse('foo', 'bar')
self.assertResponse('no, foo:bar', 'Pero si @foo ya dice eso.')
#charlimits
s = 'a' * 401
self.assertRegexp('no, foo:%s' % s , reply('maxlen', len(s)))
self.assertResponse('no,foo:barbar', reply('edit', 'foo'))
# test bugfix: facts that starts with 'no' aren't confused as edit cmd
self.assertResponse('normas alias foo', reply('created', 'normas→foo'))
# test bugfix:
self.assertError('no asd asd asd')
def testSubstitute(self):
self.assertNotError('foo:bar')
self.assertNotError('s/$/ bar/foo')
self.assertResponse('foo', 'bar bar')
self.assertNotError(r's/(\w)\s(\w)/\2 \1/foo')
self.assertResponse('foo', 'bab rar')
self.assertNotError('url:http://url.com/asd')
self.assertNotError('sed,http://url.com/asd,http://www.url.net/qwe, url')
self.assertResponse('url', 'http://www.url.net/qwe')
#errors
self.assertNotError('test:aaa')
self.assertRegexp('s/?/b/test', 'El patrón \'\?\' no es válido')
self.assertResponse('s/b/c/test', 'El patrón \'b\' no encontró nada para reemplazar.')
#alias
self.assertNotError('alias alias foo')
self.assertNotError('s/b/r/alias')
self.assertResponse('alias', 'rar rar')
# alternate syntax
self.assertNotError('sed foo s/$/ bar/')
def testAppendFact(self):
self.assertNotError('foo:bar')
self.assertNotError('agregar a foo AAA A')
self.assertResponse('foo', 'bar AAA A')
self.assertNotError('weird:stuff')
self.assertNotError('añadir a weird abcde áéíóúñ |@#¬{} 3424')
self.assertResponse('weird', 'stuff abcde áéíóúñ |@#¬{} 3424')
#alias
self.assertNotError('alias alias foo')
self.assertNotError('agrega a alias BBB')
self.assertResponse('alias', 'bar AAA A BBB')
def testSpecialChars(self):
self.assertNotError('ña_-a.z es válido')
self.assertResponse('ña_-a.z', 'ña_-a.z es válido')
self.assertNotError('test: %sasd %')
self.assertResponse('test', '%sasd %')
self.assertNotError('foo: « barr »')
self.assertResponse('foo', '« barr »')
def testCaseInsensible(self):
self.assertNotError('tEsT:testing...')
self.assertResponse('test', 'testing...')
self.assertResponse('TEST', 'testing...')
self.assertResponse('TEST:testing...', reply('dup', 'test'))
self.assertNotError('PrUeBA es una prueba')
self.assertResponse('prueba', 'PrUeBA es una prueba') # keeps case in reply
self.assertNotError('foo es bar')
self.assertResponse('FOO', 'foo es bar')
self.assertNotError('BAR es foo')
self.assertResponse('bar', 'BAR es foo')
# test in channel's name
self.assertResponse('foo#TEST:_', reply('created', 'foo#test'))
self.assertResponse('foo', '_')
self.assertResponse('foo1#test:_', reply('created', 'foo1#test'))
self.channel = '#TeSt'
self.assertResponse('foo', '_')
# Ñ to ñ
self.assertNotError('ÑOO es bar')
self.assertResponse('ñoo', 'ÑOO es bar')
def testChannelSpecific(self):
self.assertNotError('foo:global')
self.assertResponse('foo', 'global')
self.assertResponse('foo#test : local', reply('created', 'foo#test'))
self.assertResponse('foo', 'local')
self.assertResponse('foo#test', 'local')
self.assertResponse('foo#', 'global')
self.assertResponse('borrar foo#test', reply('deleted', 'foo#test'))
self.assertResponse('foo', 'global')
self.assertResponse('bar#test alias foo', reply('created', 'bar#test→foo'))
self.assertResponse('bar', 'global')
#self.assertResponse('bar#', reply('notFound', 'bar#')) #FIXME?
self.assertResponse('bar#', reply('notFound', 'bar'))
self.assertNotError('desborrar foo#test')
self.assertResponse('bar', 'local')
def testChannelSpecificEdit(self):
self.assertNotError('foo:global')
self.assertNotError('foo#test:local')
self.assertNotError('no, foo : local2')
self.assertResponse('foo', 'local2')
self.assertResponse('foo#test', 'local2')
self.assertResponse('foo#', 'global')
self.assertNotError('no, foo#: global2')
self.assertResponse('foo#', 'global2')
self.assertNotError('no, foo#test: local3')
self.assertResponse('foo', 'local3')
self.assertNotError('aaa:global')
self.assertNotError('aaa#test:local')
self.assertNotError('no, aaa#:global2')
self.assertResponse('aaa#','global2')
# append
self.assertNotError('agregar a foo AAA')
self.assertResponse('foo', 'local3 AAA')
self.assertNotError('agregar a foo# AAA')
self.assertResponse('foo#', 'global2 AAA')
# substitute
self.assertNotError('s/$/ AAA/foo')
self.assertResponse('foo', 'local3 AAA AAA')
self.assertNotError('s/$/ AAA/foo#')
self.assertResponse('foo#', 'global2 AAA AAA')
def testPreview(self):
self.assertNotError('foo:bar')
self.assertResponse('no, foo:bar bar --preview', 'Preview: bar bar')
self.assertResponse('foo', 'bar')
self.assertResponse('s/a/r/foo --preview', 'Preview: brr')
self.assertResponse('foo', 'bar')
self.assertResponse('añadir a foo AAA --preview', 'Preview: bar AAA')
def testRemoveFact(self):
self.assertNotError('foo:bar')
self.assertResponse('foo', 'bar')
self.assertResponse('borrar foo', reply('deleted', 'foo'))
self.assertResponse('foo', reply('notFound', 'foo'))
self.assertResponse('borrar foo', reply('notFound', 'foo'))
self.assertResponse('desborrar foo', 'Facto @foo restaurado.')
self.assertResponse('foo', 'bar')
self.assertResponse('desborrar foo', '@foo no se encuentra borrado.')
self.assertResponse('foo', 'bar')
def testLockFact(self):
self.assertNotError('foo:bar')
self.assertResponse('foo', 'bar')
self.assertResponse('proteger foo', 'Facto @foo protegido contra cambios.')
self.assertResponse('no, foo es bar', reply('locked', 'foo'))
self.assertNotError('proteger foo')
self.assertResponse('borrar foo', reply('locked', 'foo'))
self.assertResponse('desproteger foo', '@foo ahora se puede editar.')
self.assertResponse('no, foo es bar', reply('edit', 'foo'))
self.assertNotError('desproteger foo')
self.assertResponse('borrar foo', reply('deleted', 'foo'))
self.assertNotError('proteger foo')
self.assertResponse('desborrar foo', reply('forbidden', 'foo'))
self.assertResponse('foo:bar', reply('forbidden', 'foo'))
def testAlias(self):
self.assertNotError('foo:bar')
self.assertResponse('test alias foo', reply('created', 'test→foo'))
self.assertResponse('test', 'bar')
self.assertResponse('prueba alias test', reply('created', 'prueba→foo'))
self.assertResponse('prueba', 'bar')
self.assertNotError('borrar foo')
self.assertResponse('test', reply('notFound', 'test→foo'))
self.assertResponse('prueba', reply('notFound', 'prueba→foo'))
self.assertResponse('asd alias foo', reply('notFound', 'foo'))
self.assertResponse('asd alias test', reply('notFound', 'foo'))
# alias nesting
self.assertNotError('fact:a')
self.assertNotError('aliastofact alias fact')
self.assertNotError('aliastoalias alias aliastofact')
self.assertNotError('aliastoalias_2 alias aliastoalias')
self.assertResponse('aliastoalias_2', 'a')
self.assertRegexp('aliastoalias_2 --raw', 'flags:4 .* data:fact')
def testAliasEdit(self):
# create alias by editing
self.assertNotError('foo:bar')
self.assertNotError('foobar es una prueba')
self.assertNotError('no, foo alias foobar')
self.assertResponse('foo', 'foobar es una prueba')
self.assertRegexp('foo --raw', 'flags:4 .* data:foobar')
# edit an alias should edit the target fact
self.assertNotError('no, foo es bar')
self.assertResponse('foobar', 'foo es bar')
def testAliasLoops(self):
self.assertNotError('foo:bar')
self.assertResponse('test alias foo', reply('created', 'test→foo'))
self.assertResponse('test', 'bar')
self.assertError('no, foo alias test') # alias loop
def testAliasChannelSpecific(self):
self.assertNotError('foo#channel:bar in #channel')
self.assertResponse('test alias foo#channel', reply('created', 'test→foo#channel'))
self.assertResponse('test', 'bar in #channel')
self.assertNotError('foo#test:bar in #test')
self.assertResponse('test2 alias foo', reply('created', 'test2→foo'))
self.assertResponse('test3 alias foo#test', reply('created', 'test3→foo#test'))
self.assertResponse('test2', 'bar in #test')
self.assertResponse('test3', 'bar in #test')
self.assertNotError('foo#:bar')
self.assertNotError('borrar foo#test')
self.assertResponse('test2', 'bar')
self.assertResponse('test3', reply('notFound', 'test3→foo#test'))
def testCounters(self):
self.assertNotError('foo:bar')
self.assertRegexp('foo --raw', 'request_count:0')
for i in range(10):
self.assertNotError('foo')
self.assertRegexp('foo --raw', 'request_count:10')
# shoudn't update counter if isn't called from a channel
self.channel = 'scratbot'
try:
self.assertNotError('foo')
self.assertRegexp('foo --raw', 'request_count:10')
finally:
self.channel = '#test'
# counter shouldn't update if called with --info, --noreplace or --disabled (with any option)
self.assertNotError('foo --info')
self.assertRegexp('foo --raw', 'request_count:10')
self.assertNotError('foo --noreplace')
self.assertRegexp('foo --raw', 'request_count:10')
self.assertNotError('foo --disabled')
self.assertRegexp('foo --raw', 'request_count:10')
# user counters
self.assertRegexp('editor --id 0 --raw', 'facts:1', private=True)
for i in range(10):
self.assertNotError('foo%s:bar' % i)
self.assertRegexp('editor --id 0 --raw', 'facts:11 edits:0', private=True)
for i in range(10):
self.assertNotError('no, foo:bar%s' % i)
self.assertRegexp('editor --id 0 --raw', 'edits:10', private=True)
self.prefix = 'moo!user@factos.net'
try:
self.assertNotError('no, foo:bar')
self.assertRegexp('editor --id 1 --raw', 'facts:0 edits:1', private=True)
# editing with the same text shouldn't raise the counter
self.assertNotError('no, foo:bar')
self.assertRegexp('editor --id 1 --raw', 'facts:0 edits:1', private=True)
finally:
self.prefix = 'test!user@factos.net'
# alias counter
self.assertNotError('moo alias foo')
self.assertRegexp('moo --raw', 'request_count:0')
self.assertNotError('moo')
# both alias and fact counter should be increased
self.assertRegexp('moo --raw', 'request_count:1')
self.assertRegexp('foo --raw', 'request_count:11')
self.assertNotError('foo')
self.assertRegexp('moo --raw', 'request_count:1')
self.assertRegexp('foo --raw', 'request_count:12')
def testGetFactRaw(self):
self.assertNotError('foo:bar')
m = self.getMsg('foo --raw')
msgs = m.args[1].split()
regexps = r'name:foo created_by:0 created_at:\d{10} edited_by:None'\
' edited_at:None'\
' flags:0 flags_set_by:None flags_set_at:None'\
' last_request_by:None last_request_at:None'\
' request_count:0 data:bar'.split()
regiter = iter(regexps)
for s in msgs:
self.assertMatchRegexp(s, regiter.next())
def testGetFactInfo(self):
self.assertNotError('foo:bar')
self.assertNotError('bar alias foo')
self.assertRegexp('foo --info', r'El facto @foo fué creado por ' \
'test hoy a las \d\d:\d\d, no se usó y tiene \d+ carácteres\.')
self.assertRegexp('bar --info', r'@bar es un alias a \'foo\' y ' \
'fué creado por test hoy a las \d\d:\d\d, no se usó\.')
self.assertNotError('no, foo:bar1')
self.assertRegexp('foo --info', r'Editado por última vez ' \
'hoy a las \d\d:\d\d por test\.')
self.assertNotError('proteger foo')
self.assertRegexp('foo --info', r'protegido contra cambios\.')
self.assertNotError('desproteger foo')
self.assertNotError('borrar foo')
self.assertRegexp('foo --info', r'borrado\.')
self.assertNotError('proteger foo')
self.assertRegexp('foo --info', r'bloqueado\.')
self.assertNotRegexp('foo --info', r'#')
self.assertNotError('foo#test:bar')
self.assertRegexp('foo --info', r'@foo#test')
def testGetFactDisabled(self):
self.assertNotError('foo:bar')
self.assertResponse('foo', 'bar')
self.assertNotError('borrar foo')
self.assertResponse('foo', reply('notFound', 'foo'))
m = self.getMsg('foo --disabled')
self.assertEqual(m.args[0], 'test') # private
self.assertEqual(m.args[1], 'bar')
# you shouldn't be able to redirect a fact while using --disabled
m = self.getMsg('foo --disabled user')
self.assertEqual(m.args[0], 'test')
self.assertEqual(m.args[1], 'bar')
def testEditorRaw(self):
regexps = r'user_id:0 host:test!user@factos.net'\
' first_seen:\d{10} last_seen:\d{10} facts:1 edits:0'.split()
regexps.extend(r'user_id:1 host:moo!user@factos.net'\
' first_seen:\d{10} last_seen:\d{10} facts:1 edits:0'.split())
self.assertNotError('foo:bar')
m = self.getMsg('editor --id 0 --raw', private=True)
msgs = m.args[1].split()
self.prefix = 'moo!user@factos.net'
self.assertNotError('foo1:bar')
self.prefix = 'test!user@factos.net'
m = self.getMsg('editor --id 1 --raw', private=True)
msgs.extend(m.args[1].split())
regiter = iter(regexps)
for s in msgs:
self.assertMatchRegexp(s, regiter.next())
def testKeywords(self):
self.assertNotError('chan:This channel is $channel')
self.assertResponse('chan', 'This channel is #test')
self.assertResponse('chan --noreplace', 'This channel is $channel')
self.assertNotError('randword:Today I ate a $(apple|orange|banana) with $(coffe|tea|water)')
self.assertRegexp('randword', r'Today I ate a (apple|orange|banana) with (coffe|tea|water)')
self.assertNotError('wiki: http://en.wikipedia.org/wiki/Special:Search?search=${1}&go=Go')
self.assertResponse('wiki | apple',
'http://en.wikipedia.org/wiki/Special:Search?search=apple&go=Go')
self.assertNotError('slap:slaps ${*}')
self.assertResponse('slap | m4v with a fish', 'slaps m4v with a fish')
self.assertNotError('no, slap:slaps ${1} with a ${2}')
self.assertResponse('slap | m4v fish', 'slaps m4v with a fish')
def testFactSubstitute(self):
self.assertNotError('foo:bar')
self.assertNotError('moo: foo says %{foo}')
self.assertResponse('moo', 'foo says bar')
self.assertNotError('boo alias moo')
self.assertResponse('boo', 'foo says bar')
self.assertResponse('boo --noreplace', 'foo says %{foo}')
self.assertNotError('test: boo says that %{boo}')
self.assertResponse('test', 'boo says that foo says %{foo}')
# with local facts
self.assertNotError('foo#test:LOCAL')
self.assertResponse('moo', 'foo says LOCAL')
self.assertNotError('no,boo: foo says %{foo#test}')
self.assertResponse('boo', 'foo says LOCAL')
self.assertNotError('foo#test2:LOCAL2')
self.assertNotError('no,boo: foo says %{foo#test2}')
self.assertResponse('boo', 'foo says LOCAL2')
def testFactMode(self):
self.assertNotError('foo:bar')
self.assertRegexp('factmode foo', '\(none\)$')
self.assertNotError('borrar foo')
self.assertRegexp('factmode foo', 'disable$')
self.assertRegexp('factmode foo -disable', '\(none\)$')
self.assertResponse('foo', 'bar')
self.assertRegexp('factmode foo +disable +lock', '(disable, lock|lock, disable)$')
self.assertResponse('foo', reply('notFound', 'foo'))
self.assertError('factmode foo +asdas')
self.assertError('factmode foo lock')
def testFactModeSetting(self):
self.assertNotError('foo:bar')
self.assertNotError('boo alias foo')
self.assertNotError('factmode boo -alias')
self.assertResponse('boo', 'foo')
self.assertNotError('factmode boo +disable')
# test +mute
self.assertResponse('boo', reply('notFound', 'boo'))
self.assertNotError('factmode foo +mute')
self.assertNoResponse('foo')
# test +ignore
self.assertNotError('factmode foo +ignore -mute')
self.assertError('foo')
# test +noreplace
self.assertNotError('no, foo: this keyword won\'t change $channel')
self.assertNotError('factmode foo +noreplace -ignore')
self.assertResponse('foo', 'this keyword won\'t change $channel')
# test +private
m = self.getMsg('foo', frm='user!test@test.com')
self.assertEqual(m.args[0], '#test')
self.assertNotError('factmode foo +private')
m = self.getMsg('foo', frm='user!test@test.com')
self.assertEqual(m.args[0], 'user')
m = self.getMsg('foo > user2', frm='user!test@test.com')
self.assertEqual(m.args[0], 'user2')
m = self.getMsg('foo, user2', frm='user!test@test.com')
self.assertEqual(m.args[0], 'user2')
def testFactModeAlert(self):
self.assertNotError('foo:bar')
self.assertNotError('bar#test:bar')
self.assertNotError('boo alias foo')
Fconf.alertInChannels.set('#alert')
Fconf.alertInChannels.get('#test2').set('#alert2')
try:
self.assertNotError('factmode foo +alert')
self.assertNotError('factmode bar +alert')
m = self.getMsg('foo')
# XXX for some reason that I don't know, the nick is stripped for the msg, funnily it
# doesn't do it if the alert msg doesn't start with the nick.
self.assertEqual(m.args[1], 'llamó @foo en #test ()')
self.assertEqual(m.args[0], '#alert')
m = self.irc.takeMsg()
# XXX same, nick is prefixed here, for some reason...
# it's probably because, a msg object is created and send it before replying
# with irc.reply, and supybot's testcase gets confused somehow?
self.assertEqual(m.args[1], 'test: bar')
# from other channel
self.channel = '#test2'
m = self.getMsg('foo')
self.assertEqual(m.args[1], 'llamó @foo en #test2 ()')
self.assertEqual(m.args[0], '#alert2')
m = self.irc.takeMsg()
self.channel = '#test'
# argument
self.assertResponse('foo | good day', 'llamó @foo en #test (good day)')
m = self.irc.takeMsg()
self.assertEqual(m.args[1], 'test: good day: bar')
# alerts shouldn't be sent if calling it from private, or called with raw or info, or if
# directed to a query
self.assertRegexp('foo --raw', 'name:foo')
self.assertRegexp('foo --info', 'El facto @foo fué creado')
self.assertResponse('foo', 'bar', private=True)
self.assertResponse('foo>user', 'bar')
self.assertResponse('dile a user sobre foo', 'bar')
m = self.irc.takeMsg()
# should work here though
self.assertResponse('foo user', 'llamó @foo en #test (user)')
m = self.irc.takeMsg()
# if using bad nick, don't complain that is invalid!
self.assertResponse('foo no_user', 'llamó @foo en #test (no_user)')
m = self.irc.takeMsg()
# with alias
self.assertResponse('boo', 'llamó @boo en #test ()')
m = self.irc.takeMsg()
# local fact
self.assertResponse('bar', 'llamó @bar en #test ()')
m = self.irc.takeMsg()
# custom message
Fconf.alertInChannels.message.get('#ops').set(
'OMG! $nick called ${fact_name}! SEND THE OP HORDE TO $channel ASAP!')
Fconf.alertInChannels.set('#alert #ops')
self.assertResponse('foo', 'llamó @foo en #test ()')
m = self.irc.takeMsg()
self.assertEqual(m.args[1], 'OMG! test called @foo! SEND THE OP HORDE TO #test ASAP!')
m = self.irc.takeMsg()
finally:
Fconf.noticeInChannels.set('')
def testIgnore(self):
self.assertNotError('test:test')
self.assertResponse('@test', 'test')
self.assertNoResponse('@ test')
self.assertNoResponse('@ test')
self.assertNoResponse(' @test')
self.assertNoResponse('@@@@')
self.assertNoResponse('!!!!')
self.assertNoResponse('@-a')
self.assertNoResponse('-ds')
self.assertNoResponse('a'*26)
self.assertResponse('asdasd', reply('notFound', 'asdasd'))
Fconf.quiet.get('#test').setValue(True)
self.assertNoResponse('asdasd')
Fconf.quiet.get('#test').setValue(False)
def testUsers(self):
self.assertNotError('foo:bar')
self.assertRegexp('foo --raw', r'created_by:0 created_at:\d+')
self.assertRegexp('foo --raw', r'edited_by:None edited_at:None')
self.assertNotError('no, foo:newbar')
self.assertRegexp('foo --raw', r'edited_by:0 edited_at:\d+')
self.assertRegexp('foo --raw', r'flags:0 flags_set_by:None flags_set_at:None')
self.assertNotError('borrar foo')
self.assertRegexp('foo --raw', r'flags:1 flags_set_by:0 flags_set_at:\d+')
self.prefix = 'moo!user@factos.net'
self.assertNotError('desborrar foo')
self.assertRegexp('foo --raw', r'flags:0 flags_set_by:1 flags_set_at:\d+')
self.assertRegexp('foo --raw', r'last_request_by:None last_request_at:None')
self.assertNotError('foo')
self.assertRegexp('foo --raw', r'last_request_by:%s last_request_at:\d+' % self.prefix)
self.prefix = 'mooi2!user@factos.net'
self.assertNotError('proteger foo')
self.assertRegexp('foo --raw', r'flags:2 flags_set_by:2 flags_set_at:\d+')
self.prefix = 'test!user@factos.net'
def testEditor(self):
self.assertHelp('editor')
#self.assertError('editor --id 0') # private
self.assertRegexp('editor --id 0', r'No encontré ningún', private=True)
self.assertNotError('foo:bar')
self.assertRegexp('editor --id 0 --raw', r'host:test!user@factos.net', private=True)
# by host
#self.assertError('editor test!*@*') # private
self.assertRegexp('editor test!*@*', r'test!user@factos.net', private=True)
self.prefix = 'moo!user@factos.net'
self.assertNotError('no, foo:bar1')
self.assertRegexp('editor moo!*@*', r"id:1 'moo!user@factos.net'", private=True)
self.prefix = 'moa!user@factos.net'
self.assertNotError('foo1:bar1')
self.feedMsg('editor mo?!*@*', private=True)
msg = self.irc.takeMsg()
self.assertMatchRegexp(msg.args[1], r"id:1 'moo!user@factos.net'")
self.assertMatchRegexp(msg.args[1], r"id:2 'moa!user@factos.net'")
self.assertRegexp('editor foo!*@*', r'No encontré ningún', private=True)
# by nick
self.assertRegexp('editor moo', r'moo .* Agregó 0 factos y 1 ediciones')
self.prefix = 'moo!user1@factos.net'
self.assertNotError('no, foo:bar2')
self.assertNotError('foo2:bar')
self.assertRegexp('editor moo', r'moo .* Agregó 1 factos y 2 ediciones')
self.assertRegexp('editor mo?', r'moa,moo .* Agregó 2 factos y 2 ediciones')
self.assertRegexp('editor foo', r'No encontré ningún')
self.assertRegexp('editor foo!asdasd', r'identificación de usuario inválida')
# capability check
try:
world.testing = False
self.assertError('editor --id 0 --raw', private=True)
self.assertError('editor moo!*@*', private=True)
self.assertNotError('editor foo')
finally:
world.testing = True
def testDates(self):
def getTimeOf(s):
m = self.getMsg('foo --raw')
return int(re.search('%s_at:(\d+)\s' % s, m.args[1]).groups()[0])
# created date
n = now()
self.assertNotError('foo:bar')
ct = getTimeOf('created')
self.assertTrue(ct-1 <= n)
# edited date
n = now()
self.assertNotError('no, foo:newbar')
t = getTimeOf('edited')
self.assertTrue(t-1 <= n)
time.sleep(2)
self.assertNotError('no, foo:newnewbar')
nt = getTimeOf('edited')
self.assertNotEqual(t, nt)
# last_request date
n = now()
self.assertNotError('foo')
t = getTimeOf('last_request')
self.assertTrue(t-1 <= n)
time.sleep(2)
self.assertNotError('foo')
nt = getTimeOf('last_request')
self.assertNotEqual(t, nt)
# flags set date
n = now()
self.assertNotError('borrar foo')
t = getTimeOf('flags_set')
self.assertTrue(t-1 <= n)
time.sleep(2)
self.assertNotError('proteger foo')
nt = getTimeOf('flags_set')
self.assertNotEqual(t, nt)
# created date didn't change
t = getTimeOf('created')
self.assertEqual(t, ct)
def testHistory(self):
self.assertNotError('foo:bar')
self.assertResponse('deshacer foo', 'No hay cambios para deshacer en @foo.')
self.assertResponse('rehacer foo', '@foo ya está en su último cambio.')
self.assertNotError('no, foo:bar1')
self.assertNotError('no, foo:bar2')
self.assertNotError('deshacer foo')
self.assertResponse('foo', 'bar1')
self.assertNotError('deshacer foo')
self.assertResponse('foo', 'bar')
self.assertNotError('rehacer foo')
self.assertResponse('foo', 'bar1')
self.assertNotError('rehacer foo')
self.assertResponse('foo', 'bar2')
self.assertNotError('deshacer foo')
self.assertNotError('no, foo:new')
self.assertNotError('rehacer foo')
self.assertResponse('foo', 'bar2')
self.assertNotError('deshacer foo')
self.assertResponse('foo', 'new')
def testHistLocal(self):
# local facts
self.assertNotError('foo:bar')
self.assertNotError('foo#test:mar')
self.assertNotError('no, foo:mar1')
self.assertNotError('deshacer foo')
self.assertResponse('foo', 'mar')
self.assertNotError('rehacer foo')
self.assertResponse('foo', 'mar1')
def testHistAlias(self):
self.assertNotError('foo:bar')
self.assertNotError('test:testing')
self.assertNotError('no, test alias foo')
self.assertResponse('test', 'bar')
self.assertNotError('deshacer test')
self.assertResponse('test', 'testing')
self.assertNotError('rehacer test')
self.assertResponse('test', 'bar')
def testHistRestart(self):
self.assertNotError('foo:bar')
self.assertNotError('no, foo:bar1')
self.assertNotError('no, foo:bar2')
self.assertNotError('deshacer foo')
self.assertNotError('deshacer foo')
self.assertResponse('deshacer foo', 'No hay cambios para deshacer en @foo.')
self.botrestart()
self.assertResponse('foo', 'bar')
self.assertNotError('no, foo:bar1')
self.assertResponse('foo', 'bar1')
self.assertNotError('deshacer foo')
self.assertResponse('foo', 'bar')
self.botrestart()
self.assertNotError('rehacer foo')
self.assertResponse('foo', 'bar1')
self.assertRegexp('foo --history -1', 'Nº0.*foo:bar')
self.botrestart()
self.assertNotError('deshacer foo')
self.assertResponse('foo', 'bar')
def testHistRecord(self):
self.assertNotError('foo:bar')
self.assertNotError('no, foo:bar1')
self.assertNotError('no, foo:bar2')
self.assertNotError('no, foo:bar3')
self.assertNotError('moo:mar')
self.assertNotError('no, moo:mar1')
self.assertNotError('no, moo:mar2')
self.assertNotError('no, moo:mar3')
self.assertResponse('foo --history -1', "Revisión Nº2 | 'foo:bar2'")
self.assertResponse('foo --history -2', "Revisión Nº1 | 'foo:bar1'")
self.assertResponse('foo --history -3', "Revisión Nº0 | 'foo:bar'")
self.assertResponse('foo --history -4', 'Sin historial.')
self.assertResponse('moo --history -1', "Revisión Nº2 | 'moo:mar2'")
self.assertResponse('moo --history -2', "Revisión Nº1 | 'moo:mar1'")
self.assertResponse('moo --history -3', "Revisión Nº0 | 'moo:mar'")
# sanity checks
self.assertError('foo --history a')
self.assertError('foo --history')
self.assertResponse('foo --history 0', "Revisión Nº0 | 'foo:bar'") # fact when was created
self.assertResponse('boo --history -1', 'Sin historial.')
self.assertNotError('boo:bar')
self.assertResponse('boo --history -1', 'Sin historial.')
# test indexes are updated in undo
self.assertNotError('no, boo:mar')
self.assertNotError('deshacer boo')
self.assertNotError('no, boo:mar1')
self.assertResponse('boo --history -1', "Revisión Nº0 | 'boo:bar'")
# redo
self.assertResponse('boo --history 1', "Revisión (deshecha) Nº0 | 'boo:mar'")
self.assertNotError('deshacer foo')
self.assertNotError('deshacer foo')
self.assertResponse('foo --history 1', "Revisión (deshecha) Nº1 | 'foo:bar2'")
self.assertResponse('foo --history 2', "Revisión (deshecha) Nº0 | 'foo:bar3'")
def __testHistDups(self):
# XXX shouldn't store dups
# though, this is something too troublesome to fix
self.assertNotError('foo:bar')
self.assertNotError('no, foo:bar1')
self.assertNotError('no, foo:bar2')
self.assertNotError('deshacer foo')
self.assertNotError('deshacer foo')
self.assertResponse('deshacer foo', 'No hay cambios para deshacer en @foo.')
self.assertNotError('no, foo:bar1')
self.assertResponse('foo', 'bar1')
self.assertNotError('rehacer foo')
self.assertResponse('foo', 'bar2')
def testQuery(self):
self.assertResponse('foo:bar', reply('created', 'foo'), private=True)
self.assertResponse('foo', 'bar', private=True)
self.assertResponse('@bar:bar', reply('created', 'bar'), private=True)
self.assertResponse('@bar', 'bar', private=True)
def testNotices(self):
self.prefix = 'user!user@test.c'
Fconf.noticeInChannels.set('#notice')
try:
for cmds in (('foo:bar', 'user creó el facto @foo en #test (3 letras)'),
('no, foo:bar1', 'user editó el facto @foo en #test (1 letras editadas)'),
('borrar foo', 'user borró @foo en #test.'),
('desborrar foo', 'user restauró @foo en #test.'),
#('proteger foo', 'user protegió @foo en #test.'),
#('desproteger foo', 'user desprotegió @foo en #test.'),
('foo#test:bar', 'user creó el facto @foo#test en #test (3 letras)'),
('moo alias foo', 'user creó el facto @moo→foo en #test (3 letras)'),
):
# get the notice msg
self.assertNotError(cmds[0])
m = self.irc.takeMsg()
# compare
self.assertEqual(m.args[0], '#notice')
self.assertEqual(m.args[1], cmds[1])
finally:
Fconf.noticeInChannels.set('')
self.prefix = 'test!user@factos.net'
def testRestrictions(self):
try:
world.testing = False # disable test privileges
self.assertNotError('foo es bar')
self.assertError('proteger foo')
Fconf.allow.query.setValue(False)
self.assertNotError('foo1 es bar')
self.prefix = 'moo!user@factos.net' # moo isn't in any channel, should fail
#self.assertError('foo2 es bar')
self.assertError('foo2 es bar', private=True)
self.prefix = 'test!user@factos.net'
Fconf.allow.setValue(False)
self.assertError('foo2 es bar')
self.assertError('no, foo es bar2')
self.assertError('agregar foo aaa')
self.assertError('moo alias foo')
Fconf.allow.get('#test1').setValue(True)
Fconf.allow.query.get('#test1').setValue(True)
self.prefix = 'moo!user@factos.net' # moo isn't in #test1, should fail
self.feedMsg('foo3 es bar', private=True)
msg = self.irc.takeMsg()
self.assertMatchRegexp(msg.args[1], '^Error')
self.prefix = 'user!user@factos.net' # user is in #test1, should work
self.feedMsg('foo3 es bar', private=True)
msg = self.irc.takeMsg()
self.assertMatchRegexp(msg.args[1], '^Facto @foo3 creado')
finally:
self.prefix = 'test!user@factos.net'
world.testing = True
def testRepeatProtection(self):
Fconf.repeatProtection.setValue(True)
Fconf.repeatProtection.timeout.setValue(3)
Fconf.repeatProtection.msglimit.setValue(5)
try:
self.assertNotError('foo:bar')
self.assertNotError('boo:moo')
self.assertNotError('buu alias boo')
self.assertNotError('fuu alias foo')
self.assertResponse('foo', 'bar')
self.assertResponse('foo', reply('repeat', 'foo'))
self.assertNoResponse('foo')
self.assertResponse('boo', 'moo')
self.assertResponse('buu', reply('alias_repeat', 'buu', 'boo'))
self.assertResponse('foo>user', 'bar')
self.assertNoResponse('foo>user')
for i in range(5):
self.assertNotError('ping')
self.assertResponse('foo', 'bar')
self.assertResponse('foo', reply('repeat', 'foo'))
print 'Waiting 4 secs ...'
time.sleep(4)
print 'done'
self.assertResponse('foo', 'bar')
self.assertResponse('buu', 'moo')
self.assertResponse('buu', reply('repeat', 'buu'))
for i in range(5):
self.assertNotError('ping')
# test collisions
Fconf.repeatProtection.collision.setValue(True)
self.assertResponse('boo', 'moo')
self.assertNoResponse('boo user')
self.assertNoResponse('buu')
# query
self.channel = 'query'
self.assertResponse('foo', 'bar')
self.assertResponse('foo', 'bar')
finally:
Fconf.repeatProtection.setValue(False)
Fconf.repeatProtection.collision.setValue(False)
self.channel = '#test'
def testStats(self):
self.assertResponse('estadistica', 'No hay factos activos en la base.')
self.assertNotError('foo:bar')
self.assertRegexp('estadistica', '1 factos activos')
self.assertNotError('borrar foo')
self.assertResponse('estadistica', 'No hay factos activos en la base.')
self.assertNotError('desborrar foo')
self.assertNotError('moo alias foo')
self.assertRegexp('estadistica', '1 factos activos y 1 sinónimos\. .* usados son @moo\.')
self.assertNotError('foo')
self.assertRegexp('estadistica', 'usados son @foo\.')
for i in range(2): self.assertNotError('moo')
self.assertRegexp('estadistica', 'usados son @moo\.')
self.assertNotError('boo:bar')
self.assertRegexp('estadistica', 'usados son @moo, @boo\.')
def testSearch(self):
self.assertNotError('foo:bar')
self.assertNotError('foo#test:localbar')
self.assertNotError('foo#channel:other bar')
self.assertNotError('scratbot es un bot')
self.assertNotError('random:9')
self.assertRegexp('buscar bot', ': .scratbot#$')
self.assertRegexp('buscar bot rand', '^No se encontró nada')
self.assertRegexp('buscar bot rand --any', ': .random# .scratbot#')
self.assertRegexp('buscar bar', ': .foo# .foo#test$')
self.assertRegexp('buscar bar', ': .foo# .foo#channel .foo#test$', private=True)
self.assertRegexp('buscar bar --all-channels', ': .foo# .foo#channel .foo#test$')
self.assertRegexp('buscar bar local', ': .foo#test$')
self.assertNotError('borrar foo#')
self.assertRegexp('buscar bar', ': .foo#test$')
self.assertRegexp('buscar %', ': .foo#test .random# .scratbot#$')
# aliases
self.assertNotError('kubot alias scratbot')
self.assertNotError('scratbot')
self.assertRegexp('buscar bot', ': .scratbot#$')
self.assertNotError('kubot')
self.assertNotError('kubot')
self.assertRegexp('buscar bot', ': .kubot#$')
def testRestart(self):
self.assertNotError('foo:bar')
self.assertNotError('no, foo:bar1')
self.assertNotError('no, foo:bar2')
self.botrestart()
self.assertNotError('no, foo:bar3')
self.prefix = 'moo!user@factos.net'
try:
self.assertNotError('moo:bar')
self.assertRegexp('editor moo!*@*', r"id:1 'moo!user@factos.net'", private=True)
self.assertRegexp('foo --history -1', 'Nº2.*foo:bar2')
finally:
self.prefix = 'test!user@factos.net'
def __testForceLocal(self):
# TODO finish it later
Fconf.forceLocal.get('#local').setValue(True)
self.assertNotError('foo:bar')
self.assertNotError('moo:bar')
self.channel = '#local'
self.assertResponse('foo:AHAHAHAH', reply('created', 'foo#local'))
self.assertResponse('foo2#:AHAHAH', reply('created', 'foo2#local'))
self.assertResponse('foo2#somechannel:AHAHAH', reply('dup', 'foo2#local'))
self.assertResponse('foo', 'AHAHAHAH')
self.assertResponse('moo', 'bar')
self.assertResponse('no, foo:AHAHAHAH')
self.channel = '#test'
def __testSpeed(self):
now = lambda: time.time()
times = 100
repeats = 5
fd = open('test_speed.log', 'a')
database = conf.supybot.directories.data.dirize('Factos.sqlite.db')
def prnt(s):
fd.write(s + '\n')
print s
global tt
tt = 0
def run(f, repeats=repeats, times=times):
global tt
results = []
self.botrestart()
for r in range(repeats):
t1 = now()
for n in range(times):
f(r, n)
t2 = now()
results.append(t2 - t1)
m = min(results)
tt += m
return m
create_test = lambda r,n: self.assertNotError('fact_%s : test' %n)
call_test = lambda r,n: self.assertNotError('fact_%s' %n)
edit_test = lambda r,n: self.assertNotError('no, fact_%s : test%s' %(n, r))
undo_test = lambda r,n: self.assertNotError('deshacer fact_%s' %n)
sed_test = lambda r,n: self.assertNotError('sed/test/testt/fact_%s' %n)
search_test = lambda r,n: self.assertNotError('buscar fact_%s' %n)
search_test2 = lambda r,n: self.assertNotError('buscar test')
stat_test = lambda r,n: self.assertNotError('estadistica')
alias_test = lambda r,n: self.assertNotError('alias_%s alias fact_%s' %(n, n))
alias_call_test = lambda r,n: self.assertNotError('alias_%s' %n)
print
results = []
for r in range(repeats):
try:
os.remove(database)
except:
pass
results.append(run(create_test, repeats=1))
m = min(results)
tt += m
fd.write(' --- repeats:%s times:%s\n' %(repeats, times))
prnt('Creating %s facts (%s): %f' %(times, 1, run(alias_test, repeats=1)))
prnt('Creating %s aliases (%s): %f' %(times, repeats, m))
prnt('Calling %s facts (%s): %f' %(times, 1, run(call_test, repeats=1)))
prnt('Calling %s facts (%s): %f' %(times, repeats, run(call_test)))
prnt('Calling %s aliases (%s): %f' %(times, repeats, run(alias_call_test)))
prnt('Editing %s facts (%s): %f' %(times, repeats, run(edit_test)))
prnt('Undoing %s facts (%s): %f' %(times, repeats, run(undo_test)))
prnt('Sedding %s facts (%s): %f' %(times, repeats, run(sed_test)))
prnt('Searching %s facts (one match) (%s): %f' %(times, repeats, run(search_test)))
prnt('Searching %s facts (%s matches) (%s): %f' %(times, times, repeats, run(search_test2)))
prnt('Generating stats for %s facts (%s): %f' %(times, repeats, run(stat_test)))
prnt('Database size: %s' %(os.stat(database).st_size))
prnt(' --- total time: %f' %tt)
fd.close()
def __testFreenode(self):
# This test doesn't work
chanserv = 'ChanServ!ChanServ@services.'
msg1 = lambda s: ircmsgs.notice('test',
'1 %s +votsriRfAF '
'[modified 25 weeks, 6 days, 03:12:46 ago]' %s, prefix=chanserv)
msg2 = lambda s: ircmsgs.notice('test',
'2 %s +votriA (op) '
'[modified 36 weeks, 1 days, 03:12:46 ago]' %s, prefix=chanserv)
msgend = lambda s: ircmsgs.notice('test',
'End of %s FLAGS listing.' %s, prefix=chanserv)
self.assertNotError('updateaccesslist')
print self.irc.takeMsg()
self.irc.feedMsg(msg1('somebody'))
self.irc.feedMsg(msg2('otherguy'))
self.irc.feedMsg(msgend('#ŧest1'))
self.irc.feedMsg(msg2('user'))
self.irc.feedMsg(msgend('#ŧest'))
print self.irc.takeMsg()
self.assertNotError('op es ${channel_ops}')
self.assertResponse('op', 'asdas')
class FactosDocTestCase(PluginTestCase):
plugins = (ourPlugin, )
# vim:set shiftwidth=4 softtabstop=4 tabstop=4 expandtab textwidth=100:
|