Skip to content

Commit

Permalink
fixes to support testing, and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barbie committed Oct 15, 2009
1 parent b188318 commit 5fab355
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 16 deletions.
11 changes: 7 additions & 4 deletions lib/CPAN/Testers/WWW/Statistics/Graphs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ sub _make_graph {
my $year = substr($date,0,4);
my $month = substr($date,4,2);
my $day = substr($date,6,2);
push @dates1, ($day % 2 ? sprintf "%d", $day : '');
push @dates1, ($day == 1 || $day % 7 == 0 ? sprintf "%d", $day : "'");
push @dates2, ($MONTHS[$month][$day-1] || '');
}
}
Expand Down Expand Up @@ -269,15 +269,18 @@ sub _make_graph {
#=cut

sub _get_data {
my ($self,$file,$range) = @_;
my ($self,$filename,$range) = @_;
my ($fdate,$tdate) = split('-',$range);

my $directory = $self->{parent}->directory;
my $file = "$directory/stats/$filename";

$self->{parent}->_log("get data - range=$range, fdate=$fdate, tdate=$tdate");

my @data;
my $fh = IO::File->new($file)
#or return ();
or die "Cannot open data file [$file]: $!\n";
or return ();
#or die "Cannot open data file [$file]: $!\n";
while(<$fh>) {
s/\s*$//;
next unless($_);
Expand Down
6 changes: 4 additions & 2 deletions lib/CPAN/Testers/WWW/Statistics/Pages.pm
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ sub _write_basics {
my $templates = $self->{parent}->templates;
my $database = $self->{parent}->database;
my $results = "$directory/stats";
mkpath($results);

$self->{parent}->_log("writing basic files");

mkpath($results);

# calculate database metrics
my $mtime = (stat($database))[9];
my @ltime = localtime($mtime);
Expand Down Expand Up @@ -452,6 +451,7 @@ sub _report_cpan {

my $directory = $self->{parent}->directory;
my $results = "$directory/stats";
mkpath($results);

my $stat6 = IO::File->new("$results/stats6.txt",'w+') or die "Cannot write to file [$results/stats6.txt]: $!\n";
print $stat6 "#DATE,AUTHORS,DISTROS\n";
Expand Down Expand Up @@ -597,6 +597,7 @@ sub _build_monthly_stats_files {

my $directory = $self->{parent}->directory;
my $results = "$directory/stats";
mkpath($results);

$self->{parent}->_log("building monthly stats for graphs - 1,3");

Expand Down Expand Up @@ -803,6 +804,7 @@ sub _build_performance_stats {

my $directory = $self->{parent}->directory;
my $results = "$directory/stats";
mkpath($results);

$self->{parent}->_log("building peformance stats for graphs");

Expand Down
25 changes: 16 additions & 9 deletions t/56writes.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $|=1;
my $UPDATE_ARCHIVE = ($ARGV[0] && $ARGV[0] eq '--update-archive') ? 1 : 0;


use Test::More tests => 166;
use Test::More tests => 201;
use Test::Differences;
use File::Slurp qw( slurp );
use Archive::Zip;
Expand Down Expand Up @@ -134,6 +134,8 @@ SKIP: {

my $graph = CTWS_Testing::getGraphs();

CTWS_Testing::saveFiles($dir . '/graphs');

$obj->directory($dir . '/graphs'),
$graph->create();
check_dir_contents(
Expand All @@ -160,7 +162,9 @@ ok( CTWS_Testing::cleanDir($obj), 'directory cleaned' );
SKIP: {
skip "Can't see a network connection", 4 if(pingtest());

$obj->directory($dir . '/make_graphs'),
CTWS_Testing::saveFiles($dir . '/make_graphs');

$obj->directory($dir . '/make_graphs'),
$obj->make_graphs();
check_dir_contents(
"[make_graphs]",
Expand Down Expand Up @@ -213,8 +217,8 @@ sub check_dir_contents {
my ($diz, $dir, $expectedDir) = @_;
my @files = CTWS_Testing::listFiles( $dir );
my @expectedFiles = CTWS_Testing::listFiles( $expectedDir );
ok( scalar(@files), "got files" );
ok( scalar(@expectedFiles), "got expectedFiles" );
ok( scalar(@files), "got files [$dir]" );
ok( scalar(@expectedFiles), "got expectedFiles [$expectedDir]" );
eq_or_diff( \@files, \@expectedFiles, "$diz file listings match" );
foreach my $f ( @files ){
my $fGot = File::Spec->catfile($dir,$f);
Expand All @@ -227,11 +231,14 @@ sub check_dir_contents {
$fExpected,
"$diz diff $f",
sub {
$_[0] =~ s/^(\s*)\d+\.\d+(?:_\d+)? at \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.( Comments and design patches)/$1 ==TIMESTAMP== $2/gmi;
$_[0] =~ s/\d+(st|nd|rd|th)\s+\w+\s+\d+/==TIMESTAMP==/gmi;
$_[0] =~ s!\d{4}/\d{2}/\d{2}!==TIMESTAMP==!gmi;
$_[0] =~ s!\w+ \d{4}!==TIMESTAMP==!gmi;
$_[0] =~ s!CPAN-Testers-WWW-Statistics-0.\d{2}!==DISTRO==!gmi;
if($_[0]) {
$_[0] =~ s/^(\s*)\d+\.\d+(?:_\d+)? at \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.( Comments and design patches)/$1 ==TIMESTAMP== $2/gmi;
$_[0] =~ s/\d+(st|nd|rd|th)\s+\w+\s+\d+/==TIMESTAMP==/gmi;
$_[0] =~ s!\d{4}/\d{2}/\d{2}!==TIMESTAMP==!gmi;
$_[0] =~ s!\w+ \d{4}!==TIMESTAMP==!gmi;
$_[0] =~ s!CPAN-Testers-WWW-Statistics-0.\d{2}!==DISTRO==!gmi;
}
$_[0];
}
);
next if $ok;
Expand Down
37 changes: 36 additions & 1 deletion t/CTWS_Testing.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,45 @@ sub whackDir {
sub listFiles {
my $dir = shift;
my @files;
find({ wanted => sub { push @files, File::Spec->abs2rel($File::Find::name,$dir) if -f $_ } }, $dir);
find({ wanted => sub { push @files, File::Spec->abs2rel($File::Find::name,$dir) if -f $_ } }, $dir)
if(-d $dir);
return sort @files;
}

sub saveFiles {
my $dir = shift;

mkpath("$dir/stats");

my $fh = IO::File->new("$dir/stats/build1.txt",'w+');
print $fh "#DATE,REQUESTS,PAGES,REPORTS\n20090715,32167,4304,21943\n20090716,43144,6573,16277\n20090717,37462,5942,21923\n";
$fh->close;

$fh = IO::File->new("$dir/stats/stats1.txt",'w+');
print $fh "#DATE,UPLOADS,REPORTS,PASS,FAIL\n200810,2,0,0,0\n200811,3,4,0,4\n200812,1,2,2,0\n";
$fh->close;

$fh = IO::File->new("$dir/stats/stats2.txt",'w+');
print $fh "#DATE,TESTERS,PLATFORMS,PERLS\n200810,0,0,0\n200811,3,4,2\n200812,2,1,1\n";
$fh->close;

$fh = IO::File->new("$dir/stats/stats3.txt",'w+');
print $fh "#DATE,FAIL,NA,UNKNOWN\n200810,0,0,0\n200811,4,0,0\n200812,0,0,0\n";
$fh->close;

$fh = IO::File->new("$dir/stats/stats4.txt",'w+');
print $fh "#DATE,ALL,FIRST,LAST\n200810,0,0,0\n200811,3,2,3\n200812,2,2,1\n";
$fh->close;

$fh = IO::File->new("$dir/stats/stats6.txt",'w+');
print $fh "#DATE,AUTHORS,DISTROS\n200810,2,2\n200811,3,3\n200812,1,1\n";
$fh->close;

$fh = IO::File->new("$dir/stats/stats12.txt",'w+');
print $fh "#DATE,AUTHORS,DISTROS\n200810,0,0\n200811,1,1\n200812,0,0\n";
$fh->close;
}

1;

__DATA__
Expand Down
Binary file modified t/expected.zip
Binary file not shown.

0 comments on commit 5fab355

Please sign in to comment.