Astro-DSS-JPEG

 view release on metacpan or  search on metacpan

t/simple.t  view on Meta::CPAN

        },
        {%$default, ra => 0, dec => 0, epoch => 2000},
        'Epoch 2000 coord'
    );
    my %processed = Astro::DSS::JPEG::_process_options(
        ra    => 0,
        dec   => 0,
        epoch => 2021
    );
    $processed{$_} = sprintf("%.4f",$processed{$_}) foreach qw/ra dec/;
    is(
        [@processed{qw/ra dec/}],
        [23.9821, -0.1169],
        'Correctly precessed to 2021'
    );
    is({
            Astro::DSS::JPEG::_process_options(
                angular_size => '0x0',
                pixel_size   => '0x0'
            )
        },
        $default,
        'Default options'
    );
    is(
        { Astro::DSS::JPEG::_process_options(angular_size => '30x60', %$_) },
        { %$default, angular_size_y => 60, pixel_size_y => 2000 },
        'x,y sizes'
    ) for {pixel_size => '1000,2000'}, {pixel_size => '1000'};
    is(
        {
            Astro::DSS::JPEG::_process_options(
                angular_size => '120,60',
                pixel_size   => '12000,6000'
            )
        },
        {
            angular_size   => 120,
            angular_size_y => 60,
            pixel_size     => 4096,
            pixel_size_y   => 3600
        },
        'Limit pixel size'
    );

};

eval { $dss->get_image(target => 'M1') };
like( $@, qr/Could not access SIMBAD/, "Tried to access SIMBAD" );

eval { $dss->get_image(target => 'M1', ra => 1) };
like( $@, qr/Could not access SIMBAD/, "Tried to access SIMBAD" );

eval { $dss->get_image(target => 'M1', ra => 1, dec => 1) };
like( $@, qr/Could not access DSS/, "Tried to access DSS" );

$dss = Astro::DSS::JPEG->new();

my $mock_result = Test::MockObject->new();
$mock_result->set_true( 'is_success' );
$mock_result->set_true( 'decoded_content' );
my $mock = Test2::Mock->new(
    class => 'LWP::UserAgent',
    override => [
        get => sub { $mock_result },
    ],
);

eval { $dss->_get_simbad(target => 'M1') };
like( $@, qr/Could not parse SIMBAD/, "Tried to parse SIMBAD" );

my $SIMBAD = '
Coordinates(ICRS,ep=J2000,eq=2000): 06 43 14.6852097640  +65 40 38.949836611 (Opt ) C [1.5736 2.7083 90] 2018yCat.1345....0G
Coordinates(FK4,ep=B1950,eq=1950): 06 38 15.3137510911  +65 43 36.219401450
';

$mock_result->mock( 'decoded_content', sub { $SIMBAD } );
is(
    $dss->_get_simbad( target => 'M1' ),
    { ra => '06 43 14.6852097640', dec => '+65 40 38.949836611', target => 'M1' },
    'Parsed SIMBAD coordinates'
);

$SIMBAD .= 'Angular size: 0.417 0.317  30 (NIR )  C 2006AJ....131.1163S';
my $sim_result = { ra => '06 43 14.6852097640', dec => '+65 40 38.949836611', angular_size => 0.417*1.5, target => 'M1' };
$mock_result->mock( 'decoded_content', sub { $SIMBAD } );
is(
    $dss->_get_simbad( target => 'M1' ),
    $sim_result,
    'Parsed SIMBAD coordinates'
);

my $mock2 = Test2::Mock->new(
    class => 'Astro::DSS::JPEG',
    override => [
        _get_simbad => sub { $sim_result },
    ],
);

$mock_result->mock( 'decoded_content', sub { 'data' } );
my $img = $dss->get_image(target => 'M1', ra => 1);
is($img, 'data', 'Got image from decoded_content');
my $file = 'M1.jpg';
my $res = $dss->get_image(ra => 1, dec => 1, filename => $file);
is($res->is_success, T(), 'Got HTTP response');
unlink ($file) if -f $file;

# For Devel::Cover
$mock = Test2::Mock->new(
    class => 'LWP::UserAgent',
    override => [
        new => sub { undef },
    ],
);
$dss = Astro::DSS::JPEG->new();

done_testing;



( run in 1.457 second using v1.01-cache-2.11-cpan-f56aa216473 )