script/moses-universal-testing.pl untested

filter: Statementstmt 0.0% 0 / 73 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 128 CC 1 SCAR 6.9
CC
1
Cov
0%
say
2.0
filter
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl -w
2 #
3 # Generate and call all BioMoby services (without SOAP).
4 #
5 # $Id: moses-universal-testing.pl,v 1.3 2008/02/21 00:12:55 kawas Exp $
6 # Contact: Martin Senger <martin.senger@gmail.com>
7 # -----------------------------------------------------------
8  
9 # some command-line options
10 use Getopt::Std;
11 use vars qw/ $opt_v $opt_d $opt_h /;
12 getopt;
13  
14 # usage
15 if ($opt_h) {
16 print STDOUT <<'END_OF_USAGE';
17 A testing tool for Perl-Moses developers.
18 Generate and call all BioMoby services (without using SOAP, just locally).
19 Work in progess...
20 Usage: [-vd] [authority] [service]
21  
22 It also needs to get a location of a local cache (and potentially
23 a BioMoby registry endpoint). It takes it from the
24 'moby-service.cfg' configuration file.
25  
26 authority ... do it only for services from this authority
27 Default: do it for all authorities
28 service ... do it only for this service
29  
30 -v ... verbose
31 -d ... debug
32 -h ... help
33 END_OF_USAGE
34 exit (0);
35 }
36  
37 use Carp;
38 use strict;
39  
40 use MOSES::MOBY::Base;
41 use MOSES::MOBY::Cache::Central;
42 use MOSES::MOBY::Generators::GenServices;
43 use File::Spec;
44  
45 $LOG->level ('INFO') if $opt_v;
46 $LOG->level ('DEBUG') if $opt_d;
47  
48 sub say { print @_, "\n"; }
49  
50 my $cache = new MOSES::MOBY::Cache::Central;
51 my $tmpdir = File::Spec->tmpdir();
52  
53 # create an empty XML input
54 my $empty_xml = File::Spec->catfile ($tmpdir, "empty.$$.xml");
55 open EMPTY, ">$empty_xml" or die "Cannot write to $empty_xml: $!\n";
56 print EMPTY <<'END_OF_XML';
57 <?xml version="1.0" encoding="UTF-8"?>
58 <moby:MOBY xmlns:moby="http://www.biomoby.org/moby">
59 <moby:mobyContent>
60 <moby:mobyData moby:queryID="job_0">
61 </moby:mobyData>
62 </moby:mobyContent>
63 </moby:MOBY>
64 END_OF_XML
65 close EMPTY or die "Cannot close $empty_xml: $!\n";
66  
67 # service generator
68 my $outdir = File::Spec->catfile ($tmpdir, 'generated-services');
69 MOSES::MOBY::Config->param ('generators.impl.outdir', $outdir);
70 MOSES::MOBY::Config->param ('generators.impl.package.prefix', 'Testing');
71 unshift (@INC, $MOBYCFG::GENERATORS_IMPL_OUTDIR);
72 my $generator = new MOSES::MOBY::Generators::GenServices;
73  
74 # outputs
75 my $outputs = File::Spec->catfile ($tmpdir, 'generated-outputs');
76 mkdir $outputs;
77  
78 say "Services will be generated into: $MOBYCFG::GENERATORS_IMPL_OUTDIR";
79 say "Services will be in package: ${MOBYCFG::GENERATORS_IMPL_PACKAGE_PREFIX}::<service-name>";
80 say "Services outputs will be saved in: $outputs";
81 say '----------------------------------';
82  
83 my $only_athority = $ARGV[0] || '';
84 my $only_service = $ARGV[1] || '';
85  
86 # getting a list of services
87 my %by_authorities = $cache->get_service_names;
88 foreach my $authority (sort keys (%by_authorities)) {
89 next if $only_athority and $only_athority ne $authority;
90  
91 foreach my $service (@{ $by_authorities{$authority} }) {
92 next if $only_service and $only_service ne $service;
93  
94 # check the black list
95 next if &filter ($authority, $service);
96  
97 say "Service: $authority\t$service";
98  
99 # generate service
100 $generator->generate_impl (service_names => [$service],
101 authority => $authority,
102 force_over => 1);
103 # call service
104 my $outfile = File::Spec->catfile ($outputs, $service.'-output.xml');
105 my $module = "${MOBYCFG::GENERATORS_IMPL_PACKAGE_PREFIX}::$service";
106 eval "require $module" or croak $@;
107 eval {
108 my $target = new $module;
109 my $output = $target->$service ($empty_xml);
110 open OUTPUT, ">$outfile" or die "Cannot open for writing $outfile: $!\n";
111 print OUTPUT $output;
112 close OUTPUT;
113 } or croak $@;
114 }
115 }
116  
117 unlink $empty_xml;
118  
119 # a black list of "really wrong" services
120 sub filter {
121 my ($authority, $service) = @_;
122 my %FILTERED_OUT =
123 (
124 'bioserv.rpbs.jussieu.fr/HBonds' => 1,
125 );
126 return exists $FILTERED_OUT{"$authority/$service"};
127 }
128  
129 __END__