示例#1
0
def test_pool_as_parameter(full_pool_rules):
    """Test passing the pool as an object"""
    pool, rules, pool_fname = full_pool_rules

    full = Main([pool_fname, '--dry-run'])
    full_as_param = Main(['--dry-run'], pool=pool)
    assert len(full.associations) == len(full_as_param.associations)
示例#2
0
def test_asn_candidates(full_pool_rules):
    """Test basic candidate selection"""
    pool, rules, pool_fname = full_pool_rules

    generated = Main([pool_fname, '--dry-run', '-i', 'o001'])
    assert len(generated.associations) == 1
    generated = Main([pool_fname, '--dry-run', '-i', 'o001', 'o002'])
    assert len(generated.associations) == 2
示例#3
0
def test_version_id(full_pool_rules):
    """Test that version id is properly included"""
    pool, rules, pool_fname = full_pool_rules

    generated = Main([pool_fname, '--dry-run', '-i', 'o001', '--version-id'])
    regex = re.compile(r'\d{3}t\d{6}')
    for asn in generated.associations:
        assert regex.search(asn.asn_name)

    version_id = 'mytestid'
    generated = Main([pool_fname, '--dry-run', '-i', 'o001', '--version-id', version_id])
    for asn in generated.associations:
        assert version_id in asn.asn_name
示例#4
0
def test_script(full_pool_rules):
    """Test full run of the script code"""
    pool, rules, pool_fname = full_pool_rules

    ref_rule_set = {
        'candidate_Asn_Coron', 'discover_Asn_TSO', 'candidate_Asn_Lv2NRSFSS',
        'candidate_Asn_SpectralTarget', 'candidate_Asn_TSO',
        'candidate_Asn_WFSCMB', 'candidate_Asn_Lv2SpecSpecial',
        'candidate_Asn_Image', 'candidate_Asn_IFU', 'candidate_Asn_Lv2NRSMSA',
        'candidate_Asn_Lv2Image', 'candidate_Asn_Lv2Spec', 'discover_Asn_AMI',
        'candidate_Asn_AMI', 'candidate_Asn_Lv2ImageSpecial',
        'candidate_Asn_Lv2SpecTSO', 'candidate_Asn_SpectralSource',
        'candidate_Asn_Lv2WFSS', 'discover_Asn_Coron',
        'candidate_Asn_WFSS_NIS', 'discover_Asn_IFU', 'candidate_Asn_Lv2WFSC',
        'candidate_Asn_Lv2ImageNonScience', 'discover_Asn_SpectralTarget',
        'candidate_Asn_Lv2ImageTSO', 'discover_Asn_SpectralSource',
        'discover_Asn_Image', 'candidate_Asn_Lv2FGS'
    }

    generated = Main([pool_fname, '--dry-run'])
    asns = generated.associations
    assert len(asns) == 442
    assert len(generated.orphaned) == 61
    found_rules = set(asn['asn_rule'] for asn in asns)
    assert ref_rule_set == found_rules
    def test_against_standard(self, standard_pars):
        """Compare a generated association against a standard
        Success is when no other AssertionError occurs.
        """
        if standard_pars.xfail is not None:
            pytest.xfail(reason=standard_pars.xfail)

        # Create the associations
        generated_path = Path('generate')
        generated_path.mkdir()
        version_id = standard_pars.pool_root.replace('_', '-')
        args = standard_pars.main_args + [
            '-p',
            str(generated_path),
            '--version-id',
            version_id,
        ]
        pool = combine_pools(
            [t_path(Path('data') / (standard_pars.pool_root + '.csv'))])
        Main(args, pool=pool)

        # Retrieve the truth files
        truth_paths = [
            self.get_data(truth_path) for truth_path in self.data_glob(
                *self.ref_loc, glob='*_' + version_id + '_*.json')
        ]

        # Compare the association sets.
        try:
            compare_asn_files(generated_path.glob('*.json'), truth_paths)
        except AssertionError:
            if standard_pars.xfail:
                pytest.xfail(standard_pars.xfail)
            else:
                raise
示例#6
0
def make_asns(pool, request):
    asn_format = request.param
    with TemporaryDirectory() as path:
        generated = Main([
            '-p', path, '-i', 'o001', '--save-orphans', '--format', asn_format
        ],
                         pool=pool)
        yield generated, path, asn_format
示例#7
0
def test_generate_version_id(version_id, expected, pool):
    """Check that an association has been given the appropriate version id"""
    regex = re.compile(expected)
    args = ['--dry-run', '-i', 'o001', '--version-id']
    if version_id:
        args.append(version_id)
    generated = Main(args, pool=pool)
    for asn in generated.associations:
        assert regex.search(asn.asn_name)
示例#8
0
def make_asns(request, full_pool_rules):
    asn_format = request.param
    pool, rules, pool_fname = full_pool_rules
    with TemporaryDirectory() as path:
        generated = Main([
            pool_fname,
            '-p', path,
            '--save-orphans',
            '--format', asn_format
        ])
        yield generated, path, asn_format
示例#9
0
def test_asn_candidates(pool, all_candidates, case):
    """Test candidate selection option"""
    args, n_expected = case

    if args:
        generated = Main(['--dry-run'] + args, pool=pool)
        n_actual = len(generated.associations)
    else:
        n_actual = len(all_candidates.associations)

    assert n_actual == n_expected
def test_candidate_observation(partial_args, n_asns):
    with mkstemp_pool_file(
            t_path('data/pool_001_candidates.csv')) as pool_path:
        cmd_args = [
            pool_path,
            '--dry-run',
            '-r',
            level3_rule_path(),
            '--ignore-default',
        ]
        cmd_args.extend(partial_args)
        generated = Main(cmd_args)
        assert len(generated.associations) == n_asns
示例#11
0
def test_candidate_observation_caseagnostic(partial_args, n_asns):
    """Use the extensive candidate test as a test for case"""
    with mkstemp_pool_file(
            t_path('data/pool_001_candidates_lower.csv')
    ) as pool_path:
        cmd_args = [
            pool_path,
            '--dry-run',
            '-r', level3_rule_path(),
            '--ignore-default',
        ]
        cmd_args.extend(partial_args)
        generated = Main(cmd_args)
        assert len(generated.associations) == n_asns
示例#12
0
def test_duplicate_main():
    """Test the same but with Main
    """
    cmd_args = [
        t_path('data/pool_duplicate.csv'), '--dry-run', '-r',
        level3_rule_path(), '--ignore-default'
    ]

    generated = Main(cmd_args)
    asns = generated.associations
    assert len(asns) == 2
    asn_types = set([asn['asn_type'] for asn in asns])
    assert len(asn_types) == 1
    assert 'image3' in asn_types
    asn_ids = set([asn['asn_id'] for asn in asns])
    assert asn_ids == set(('a3001', 'o029'))
示例#13
0
def cmd_from_pool(pool_path, args):
    """Run commandline on pool

    Parameters
    ---------
    pool_path: str
        The pool to run on.

    args: [arg(, ...)]
        Additional command line arguments in the form `sys.argv`
    """
    full_args = [
        '--dry-run', '-D', '-r',
        t_path('../lib/rules_level2b.py'), '--ignore-default'
    ]
    full_args.extend(args)
    result = Main(full_args, pool=pool_path)
    return result
示例#14
0
def test_exposerr():
    pool = combine_pools(t_path('data/pool_008_exposerr.csv'))
    generated = Main([
        '--dry-run',
        '-i',
        'o001',
    ], pool=pool)
    asns = generated.associations
    assert len(asns) > 1
    for asn in asns:
        any_degraded = False
        for product in asn['products']:
            any_degraded = any_degraded or any([
                member['exposerr'] not in _EMPTY
                for member in product['members']
            ])
        if any_degraded:
            assert asn['degraded_status'] == _DEGRADED_STATUS_NOTOK
        else:
            assert asn['degraded_status'] == _DEGRADED_STATUS_OK
示例#15
0
def test_niriss_wfss():
    """Test association properties for NIRISS WFSS"""

    pool = AssociationPool.read(
        t_path(path.join('data', 'jw87800_20180412T163456_pool.csv'))
    )
    cmd_args = [
        '--dry-run',
        '--D'
    ]
    results = Main(
        cmd_args,
        pool=pool
    )
    asns = results.associations

    # Need 4 associations: image2, spec2, image3, spec3
    assert len(asns) == 12
    asn_types = [
        asn['asn_type']
        for asn in asns
    ]
    assert REQUIRED_ASN_TYPES == set(asn_types)

    # Arrange associations by type
    asn_by_type = {
        asn['asn_type']: asn
        for asn in asns
    }

    # Ensure catalog and segmentation map names are correct in the spec2 associations
    l3name = asn_by_type['image3']['products'][0]['name']
    source_cat = l3name + '_cat.ecsv'
    segmap = l3name + '_segm.fits'
    for product in asn_by_type['spec2']['products']:
        members_by_type = {
            member['exptype']: member
            for member in product['members']
        }
        assert members_by_type['sourcecat']['expname'] == source_cat
        assert members_by_type['segmap']['expname'] == segmap
示例#16
0
def test_toomanyoptions(args):
    """Test argument parsing for failures"""
    pool = AssociationPool()

    with pytest.raises(SystemExit):
        Main(args, pool=pool)
示例#17
0
def all_candidates(pool):
    """"Retrieve the all exposure pool"""
    all_candidates = Main(['--dry-run', '--all-candidates'], pool=pool)
    return all_candidates