From a7e86ae7455c182c942790eca94d6c95838a5df5 Mon Sep 17 00:00:00 2001 From: Nigel Horne Date: Mon, 23 Sep 2024 09:53:04 -0400 Subject: [PATCH] combine some osm tests --- Makefile.PL | 15 ++++++++++++--- t/eof.t | 13 ++++--------- t/eol.t | 11 +++-------- t/osm.t | 34 ++++++++++++++++++---------------- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 7c128ab..93dc80c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -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, @@ -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 }, @@ -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 }, @@ -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', diff --git a/t/eof.t b/t/eof.t index f61ae39..b30f021 100644 --- a/t/eof.t +++ b/t/eof.t @@ -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(); diff --git a/t/eol.t b/t/eol.t index 4a4d26c..2465d3c 100644 --- a/t/eol.t +++ b/t/eol.t @@ -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 }); diff --git a/t/osm.t b/t/osm.t index 3c61312..e2d46f6 100644 --- a/t/osm.t +++ b/t/osm.t @@ -40,25 +40,16 @@ 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); @@ -66,17 +57,16 @@ OSM: { 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); @@ -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 +}