Skip to content

Commit

Permalink
combine some osm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Sep 23, 2024
1 parent ae85eeb commit a7e86ae
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
15 changes: 12 additions & 3 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ if($ENV{AUTHOR_TESTING}) {

my $test_requires = {
'Test::Deep' => 0,
'Test::DescribeMe' => 0,
'Test::Most' => 0,
'Test::Needs' => 0,
'Test::NoWarnings' => 0,
Expand All @@ -47,6 +48,15 @@ if($online_tests) {
unlink('t/online.enabled');
}

my $dist = {
COMPRESS => 'gzip -9f',
SUFFIX => 'gz'
};

if($^O eq 'darwin') {
$dist->{'TAR'} = 'gtar';
}

WriteMakefile(
NAME => 'Geo::Coder::List',
AUTHOR => q{Nigel Horne <njh@bandsman.co.uk>},
Expand All @@ -63,8 +73,7 @@ WriteMakefile(
'LWP::Protocol::https' => 0,
'Time::HiRes' => 0,
'HTML::Entities' => 0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
}, dist => $dist,
clean => { FILES => 'Geo::Coder::List-*' },
META_MERGE => {
'meta-spec' => { version => 2 },
Expand All @@ -84,7 +93,7 @@ WriteMakefile(

sub are_online
{
return 0 if($ENV{'NO_NETWORK_TESTING'} || $ENV{'TRAVIS_PERL_VERSION'}) || $ENV{'AUTOMATED_TESTING'} || (!-t STDIN);
return 0 if($ENV{'NO_NETWORK_TESTING'} || $ENV{'CIRCLECI'} || $ENV{'TRAVIS_PERL_VERSION'} || $ENV{'AUTOMATED_TESTING'} || $ENV{'NONINTERACTIVE_TESTING'} || (!-t STDIN));

if(my $s = IO::Socket::INET->new(
PeerAddr => 'openstreetmap.org:443',
Expand Down
13 changes: 4 additions & 9 deletions t/eof.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

use strict;
use warnings;
use Test::DescribeMe qw(author);
use Test::Needs 'Test::EOF';
use Test::Most;

BEGIN {
if($ENV{'AUTHOR_TESTING'}) {
Test::EOF->import();
all_perl_files_ok({ minimum_newlines => 1, maximum_newlines => 4 });
done_testing();
} else {
plan(skip_all => 'Author tests not required for installation');
}
}
Test::EOF->import();
all_perl_files_ok({ minimum_newlines => 1, maximum_newlines => 4 });
done_testing();
11 changes: 3 additions & 8 deletions t/eol.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

use strict;
use warnings;
use Test::DescribeMe qw(author);
use Test::Needs 'Test::EOL';
use Test::Most;

BEGIN {
if($ENV{'AUTHOR_TESTING'}) {
Test::EOL->import();
all_perl_files_ok({ trailing_whitespace => 1 });
} else {
plan(skip_all => 'Author tests not required for installation');
}
}
Test::EOL->import();
all_perl_files_ok({ trailing_whitespace => 1 });
34 changes: 18 additions & 16 deletions t/osm.t
Original file line number Diff line number Diff line change
Expand Up @@ -40,43 +40,33 @@ OSM: {

ok(!defined($geocoderlist->geocode()));

my $location = $geocoderlist->geocode('Silver Spring, MD, USA');
ok(defined($location));
ok(ref($location) eq 'HASH');
delta_within($location->{geometry}{location}{lat}, 38.99, 1e-1);
delta_within($location->{geometry}{location}{lng}, -77.02, 1e-1);
sleep(1); # Don't get blacklisted
check($geocoderlist, 'Silver Spring, MD, USA', 38.99, -77.02);

my $ua = LWP::UserAgent::Throttled->new();
$ua->throttle({ 'nominatim.openstreetmap.org' => 1 });
$ua->env_proxy(1);
$geocoderlist->ua($ua);

$location = $geocoderlist->geocode('10 Downing St, London, UK');
ok(defined($location));
ok(ref($location) eq 'HASH');
delta_within($location->{geometry}{location}{lat}, 51.50, 1e-1);
delta_within($location->{geometry}{location}{lng}, -0.13, 1e-1);
check($geocoderlist, '10 Downing St, London, England', 51.5, -0.13);

$location = $geocoderlist->geocode('Rochester, Kent, England');
my $location = $geocoderlist->geocode('Rochester, Kent, England');
ok(defined($location));
ok(ref($location) eq 'HASH');
delta_within($location->{geometry}{location}{lat}, 51.38, 1e-1);
delta_within($location->{geometry}{location}{lng}, 0.5067, 1e-1);
ok($location->{address}{country_code} eq 'gb');
ok($location->{address}{country} eq 'United Kingdom');

$location = $geocoderlist->geocode(location => '8600 Rockville Pike, Bethesda MD, 20894 USA');
$location = $geocoderlist->geocode(location => '8600 Rockville Pike, Bethesda MD, 20894, USA');
ok(defined($location));
ok(ref($location) eq 'HASH');
delta_within($location->{geometry}{location}{lat}, 39.00, 1e-1);
delta_within($location->{geometry}{location}{lng}, -77.10, 1e-1);

like($geocoderlist->reverse_geocode('39.00,-77.10'), qr/Bethesda/i, 'test reverse geocode');

ok($location->{address}{country_code} eq 'us');
like($location->{address}{country}, qr/^United States/, 'check USA');

like($geocoderlist->reverse_geocode('39.00,-77.10'), qr/Bethesda/i, 'test reverse geocode');

my @locations = $geocoderlist->geocode('Vessels, Misc Ships at Sea or Abroad, England');
my $count = scalar(@locations);
ok($count == 0);
Expand Down Expand Up @@ -114,3 +104,15 @@ OSM: {
is($locations[0]->{'geocoder'}, 'cache', 'Verify subsequent reads are cached');
}
}

sub check
{
my($geocoderlist, $location, $lat, $long) = @_;

my $rc = $geocoderlist->geocode($location);
isnt($rc, undef, "Find $location");
ok(ref($rc) eq 'HASH');
delta_within($rc->{geometry}{location}{lat}, $lat, 1e-1);
delta_within($rc->{geometry}{location}{lng}, $long, 1e-1);
sleep(1); # Don't get blacklisted
}

0 comments on commit a7e86ae

Please sign in to comment.