def databases(rtdata_module):
    """Create the necessary databases needed to run pointing code

    The SIAF database needs to be open explicitly and requires `pysiaf`.

    The engineering database is handled as a context.

    Returns
    -------
    siaf_db, metas : `set_telescope_pointing.SiafDb`, dict
        Returns the tuple of the siaf database and all exposures meta information.
    """
    with siafdb.SiafDb() as siaf_db:

        # Get the exposures' meta information
        metas_path = rtdata_module.get_data('pointing/jw00697013_metas.asdf')
        with asdf.open(metas_path) as metas_asdf:
            metas = metas_asdf['metas']

        # Setup the engineering database
        engdb_path = Path('engdb')
        engdb_path.mkdir()
        with pushdir(engdb_path):
            paths = rtdata_module.data_glob('pointing/jw00697013_engdb')
            for path in paths:
                rtdata_module.get_data(path)

        # Pass on the database info.
        with engdb_mock.EngDB_Mocker(db_path=engdb_path):
            yield siaf_db, metas
示例#2
0
def source_folder(tmp_path_factory):
    """Create a set of source associations"""
    primary_members = [
        ('sci_1.txt', 'science'),
        ('sci_2.txt', 'science'),
        ('bkg_1.txt', 'background'),
        ('imprint_1.txt', 'imprint'),
    ]

    source_folder = tmp_path_factory.mktemp('asn_gather_source')
    with pushdir(source_folder):

        # Create all the files
        for expname, exptype in primary_members:
            with open(expname, 'w') as fh:
                fh.write(expname)

        # Create the association
        primary = asn_from_list(primary_members,
                                product_name=PRIMARY_STEM,
                                with_exptype=True)
        _, serialized = primary.dump()
        with open(PRIMARY_NAME, 'w') as fh:
            fh.write(serialized)

    return source_folder
示例#3
0
def test_pusdir_fail():
    """Test for failing changing."""
    current = os.getcwd()
    with pytest.raises(Exception):
        with pushdir('Really_doesNOT-exist'):
            # Nothing should happen here. The assert should never be checked.
            assert False
    assert current == os.getcwd()
示例#4
0
def keyword_db(jail, rtdata_module):
    """Define the keyword database"""
    rt = rtdata_module

    keyword_db = Path('keyword_db')
    keyword_db.mkdir()
    with pushdir(str(keyword_db)):
        schemas = rt.data_glob(KEYWORD_DB, glob='*.json')
        for schema in schemas:
            rt.get_data(schema)

    return keyword_db
示例#5
0
def container():
    warnings.simplefilter("ignore")
    asn_file_path, asn_file_name = op.split(ASN_FILE)
    with pushdir(asn_file_path):
        with ModelContainer(asn_file_name) as c:
            for m in c:
                m.meta.observation.program_number = '0001'
                m.meta.observation.observation_number = '1'
                m.meta.observation.visit_number = '1'
                m.meta.observation.visit_group = '1'
                m.meta.observation.sequence_id = '01'
                m.meta.observation.activity_id = '1'
                m.meta.observation.exposure_number = '1'
                m.meta.instrument.name = 'NIRCAM'
                m.meta.instrument.channel = 'SHORT'
        yield c
示例#6
0
def test_pushdir():
    """Test for successful change"""
    # Retrieve what the /tmp folder really is
    current = os.getcwd()
    try:
        os.chdir('/tmp')
    except Exception:
        pytest.xfail('Cannot change to the tmp directory. Test cannot run')
    tmp_dir = os.getcwd()
    os.chdir(current)

    # Now on with the test.
    with pushdir(tmp_dir):
        assert tmp_dir == os.getcwd(
        ), 'New directory is not what was specified.'
    assert current == os.getcwd(), 'Directory was not restored'
示例#7
0
    def get_truth(self, path=None, docopy=None):
        """Copy truth data from Artifactory remote resource to the CWD/truth

        Updates self.truth and self.truth_remote on completion
        """
        if path is None:
            path = self.truth_remote
        else:
            self.truth_remote = path
        if docopy is None:
            docopy = self.docopy
        os.makedirs('truth', exist_ok=True)
        with pushdir('truth'):
            self.truth = get_bigdata(self._inputs_root,
                                     self.env,
                                     path,
                                     docopy=docopy)
            self.truth_remote = os.path.join(self._inputs_root, self.env, path)

        return self.truth
def test_against_standard(sdpdata_module, pool_path, slow):
    """Compare a generated association against a standard

    Success is when no other AssertionError occurs.
    """

    # Parse pool name
    pool = Path(pool_path).stem
    proposal, version_id = pool_regex.match(pool).group(
        'proposal', 'versionid')
    special = SPECIAL_POOLS.get(pool, SPECIAL_DEFAULT)

    if special['slow'] and not slow:
        pytest.skip(f'Pool {pool} requires "--slow" option')

    # Setup test path
    cwd = Path(pool)
    cwd.mkdir()
    with pushdir(cwd):

        # Create the generator running arguments
        output_path = Path(pool)
        output_path.mkdir()
        sdpdata_module.output = str(output_path)
        args = special['args'] + [
            '-p', sdpdata_module.output, '--version-id', version_id,
            sdpdata_module.get_data(pool_path)
        ]

        # Create the associations
        asn_generate(args)

        # Compare to the truth associations.
        truth_paths = sdpdata_module.truth_paths(pool)
        try:
            compare_asn_files(output_path.glob('*.json'), truth_paths)
        except AssertionError:
            if special['xfail']:
                pytest.xfail(special['xfail'])
            else:
                raise