~ubuntu-branches/ubuntu/utopic/spamassassin/utopic-proposed

« back to all changes in this revision

Viewing changes to t/bayessql.t

  • Committer: Bazaar Package Importer
  • Author(s): Noah Meyerhans
  • Date: 2010-01-26 22:53:12 UTC
  • mfrom: (1.1.13 upstream) (5.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100126225312-wkftb10idc1kz2aq
Tags: 3.3.0-1
* New upstream version.
* Switch to dpkg-source 3.0 (quilt) format

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
 
61
61
ok($sa);
62
62
 
63
 
ok($sa->{bayes_scanner});
64
 
 
65
 
ok($sa->{bayes_scanner}->{store}->tie_db_writable());
 
63
sub getimpl {
 
64
  return $sa->call_plugins("learner_get_implementation");
 
65
}
 
66
 
 
67
ok($sa->{bayes_scanner} && getimpl);
 
68
 
 
69
ok(getimpl->{store}->tie_db_writable());
66
70
 
67
71
# This bit breaks abstraction a bit, the userid is an implementation detail,
68
72
# but is necessary to perform some of the tests.  Perhaps in the future we
69
73
# can add some sort of official API for this sort of thing.
70
 
my $testuserid = $sa->{bayes_scanner}->{store}->{_userid};
 
74
my $testuserid = getimpl->{store}->{_userid};
71
75
ok(defined($testuserid));
72
76
 
73
 
ok($sa->{bayes_scanner}->{store}->clear_database());
 
77
ok(getimpl->{store}->clear_database());
74
78
 
75
79
ok(database_clear_p($testuser, $testuserid));
76
80
 
95
99
 
96
100
ok($sa->{bayes_scanner});
97
101
 
98
 
ok(!$sa->{bayes_scanner}->{store}->tie_db_writable());
 
102
ok(!getimpl->{store}->tie_db_writable());
99
103
 
100
104
$sa->finish_learner();
101
105
 
138
142
 
139
143
ok($mail);
140
144
 
141
 
my $body = $sa->{bayes_scanner}->get_body_from_msg($mail);
 
145
my $body = getimpl->get_body_from_msg($mail);
142
146
 
143
147
ok($body);
144
148
 
145
 
my $toks = $sa->{bayes_scanner}->tokenize($mail, $body);
 
149
my $toks = getimpl->tokenize($mail, $body);
146
150
 
147
151
ok(scalar(keys %{$toks}) > 0);
148
152
 
149
 
my($msgid,$msgid_hdr) = $sa->{bayes_scanner}->get_msgid($mail);
 
153
my($msgid,$msgid_hdr) = getimpl->get_msgid($mail);
150
154
 
151
155
# $msgid is the generated hash messageid
152
156
# $msgid_hdr is the Message-Id header
153
157
ok($msgid eq 'ce33e4a8bc5798c65428d6018380bae346c7c126@sa_generated');
154
158
ok($msgid_hdr eq '9PS291LhupY');
155
159
 
156
 
ok($sa->{bayes_scanner}->{store}->tie_db_writable());
157
 
 
158
 
ok(!$sa->{bayes_scanner}->{store}->seen_get($msgid));
159
 
 
160
 
$sa->{bayes_scanner}->{store}->untie_db();
 
160
ok(getimpl->{store}->tie_db_writable());
 
161
 
 
162
ok(!getimpl->{store}->seen_get($msgid));
 
163
 
 
164
getimpl->{store}->untie_db();
161
165
 
162
166
ok($sa->{bayes_scanner}->learn(1, $mail));
163
167
 
164
168
ok(!$sa->{bayes_scanner}->learn(1, $mail));
165
169
 
166
 
ok($sa->{bayes_scanner}->{store}->tie_db_writable());
167
 
 
168
 
ok($sa->{bayes_scanner}->{store}->seen_get($msgid) eq 's');
169
 
 
170
 
$sa->{bayes_scanner}->{store}->untie_db();
171
 
 
172
 
ok($sa->{bayes_scanner}->{store}->tie_db_writable());
 
170
ok(getimpl->{store}->tie_db_writable());
 
171
 
 
172
ok(getimpl->{store}->seen_get($msgid) eq 's');
 
173
 
 
174
getimpl->{store}->untie_db();
 
175
 
 
176
ok(getimpl->{store}->tie_db_writable());
173
177
 
174
178
my $tokerror = 0;
175
179
foreach my $tok (keys %{$toks}) {
176
 
  my ($spam, $ham, $atime) = $sa->{bayes_scanner}->{store}->tok_get($tok);
 
180
  my ($spam, $ham, $atime) = getimpl->{store}->tok_get($tok);
177
181
  if ($spam == 0 || $ham > 0) {
178
182
    $tokerror = 1;
179
183
  }
180
184
}
181
185
ok(!$tokerror);
182
186
 
183
 
my $tokens = $sa->{bayes_scanner}->{store}->tok_get_all(keys %{$toks});
 
187
my $tokens = getimpl->{store}->tok_get_all(keys %{$toks});
184
188
 
185
189
ok($tokens);
186
190
 
194
198
 
195
199
ok(!$tokerror);
196
200
 
197
 
$sa->{bayes_scanner}->{store}->untie_db();
 
201
getimpl->{store}->untie_db();
198
202
 
199
203
ok($sa->{bayes_scanner}->learn(0, $mail));
200
204
 
201
 
ok($sa->{bayes_scanner}->{store}->tie_db_writable());
202
 
 
203
 
ok($sa->{bayes_scanner}->{store}->seen_get($msgid) eq 'h');
204
 
 
205
 
$sa->{bayes_scanner}->{store}->untie_db();
206
 
 
207
 
ok($sa->{bayes_scanner}->{store}->tie_db_writable());
 
205
ok(getimpl->{store}->tie_db_writable());
 
206
 
 
207
ok(getimpl->{store}->seen_get($msgid) eq 'h');
 
208
 
 
209
getimpl->{store}->untie_db();
 
210
 
 
211
ok(getimpl->{store}->tie_db_writable());
208
212
 
209
213
$tokerror = 0;
210
214
foreach my $tok (keys %{$toks}) {
211
 
  my ($spam, $ham, $atime) = $sa->{bayes_scanner}->{store}->tok_get($tok);
 
215
  my ($spam, $ham, $atime) = getimpl->{store}->tok_get($tok);
212
216
  if ($spam  > 0 || $ham == 0) {
213
217
    $tokerror = 1;
214
218
  }
215
219
}
216
220
ok(!$tokerror);
217
221
 
218
 
$sa->{bayes_scanner}->{store}->untie_db();
 
222
getimpl->{store}->untie_db();
219
223
 
220
224
ok($sa->{bayes_scanner}->forget($mail));
221
225
 
222
 
ok($sa->{bayes_scanner}->{store}->tie_db_writable());
223
 
 
224
 
ok(!$sa->{bayes_scanner}->{store}->seen_get($msgid));
225
 
 
226
 
$sa->{bayes_scanner}->{store}->untie_db();
 
226
ok(getimpl->{store}->tie_db_writable());
 
227
 
 
228
ok(!getimpl->{store}->seen_get($msgid));
 
229
 
 
230
getimpl->{store}->untie_db();
227
231
 
228
232
# This bit breaks abstraction a bit, the userid is an implementation detail,
229
233
# but is necessary to perform some of the tests.  Perhaps in the future we
230
234
# can add some sort of official API for this sort of thing.
231
 
$testuserid = $sa->{bayes_scanner}->{store}->{_userid};
 
235
$testuserid = getimpl->{store}->{_userid};
232
236
ok(defined($testuserid));
233
237
 
234
 
ok($sa->{bayes_scanner}->{store}->clear_database());
 
238
ok(getimpl->{store}->clear_database());
235
239
 
236
240
ok(database_clear_p($testuser, $testuserid));
237
241
 
293
297
 
294
298
$mail = $sa->parse( \@msg );
295
299
 
296
 
$body = $sa->{bayes_scanner}->get_body_from_msg($mail);
 
300
$body = getimpl->get_body_from_msg($mail);
297
301
 
298
302
my $msgstatus = Mail::SpamAssassin::PerMsgStatus->new($sa, $mail);
299
303
 
300
304
ok($msgstatus);
301
305
 
302
 
my $score = $sa->{bayes_scanner}->scan($msgstatus, $mail, $body);
 
306
my $score = getimpl->scan($msgstatus, $mail, $body);
303
307
 
304
308
# Pretty much we can't count on the data returned with such little training
305
309
# so just make sure that the score wasn't equal to .5 which is the default
324
328
 
325
329
$mail = $sa->parse( \@msg );
326
330
 
327
 
$body = $sa->{bayes_scanner}->get_body_from_msg($mail);
 
331
$body = getimpl->get_body_from_msg($mail);
328
332
 
329
333
$msgstatus = Mail::SpamAssassin::PerMsgStatus->new($sa, $mail);
330
334
 
331
 
$score = $sa->{bayes_scanner}->scan($msgstatus, $mail, $body);
 
335
$score = getimpl->scan($msgstatus, $mail, $body);
332
336
 
333
337
# Pretty much we can't count on the data returned with such little training
334
338
# so just make sure that the score wasn't equal to .5 which is the default
340
344
# This bit breaks abstraction a bit, the userid is an implementation detail,
341
345
# but is necessary to perform some of the tests.  Perhaps in the future we
342
346
# can add some sort of official API for this sort of thing.
343
 
$testuserid = $sa->{bayes_scanner}->{store}->{_userid};
 
347
$testuserid = getimpl->{store}->{_userid};
344
348
ok(defined($testuserid));
345
349
 
346
 
ok($sa->{bayes_scanner}->{store}->clear_database());
 
350
ok(getimpl->{store}->clear_database());
347
351
 
348
352
ok(database_clear_p($testuser, $testuserid));
349
353