Skip to content

Commit

Permalink
added osti tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grantbuster committed Nov 3, 2023
1 parent 38c6dc7 commit 772c665
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions elm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from elm.summary import Summary
from elm.tree import DecisionTree
from elm.wizard import EnergyWizard
from elm.osti import OstiRecord, OstiList

__author__ = """Grant Buster"""
__email__ = "Grant.Buster@nrel.gov"
Expand Down
36 changes: 36 additions & 0 deletions tests/test_osti.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
"""
Test
"""
import os
import tempfile
from elm import OstiList


def test_osti_from_url():
"""Test osti list, make sure we can find LA100 documents"""
url = ('https://www.osti.gov/api/v1/records?'
'research_org=NREL'
'&sort=publication_date%20desc'
'&product_type=Technical%20Report'
'&has_fulltext=true'
'&publication_date_start=03/01/2021'
'&publication_date_end=03/01/2021')
osti = OstiList(url, n_pages=1e6)
docs = [orec.title for orec in osti if 'la100' in orec.title.lower()]
assert len(docs) == 12


def test_osti_from_oids():
"""Test osti list, make sure we can find specific oids from storage futures
study"""
oids = ['1832215', '1811650', 1785959, '1785688', 1763974]
osti = OstiList.from_osti_ids(oids)
assert len(osti) == len(oids)
with tempfile.TemporaryDirectory() as td:
out_dir = os.path.join(td, 'out')
osti.download(out_dir)

fps = os.listdir(out_dir)
assert len(fps) == len(oids)
assert all(fp.endswith('.pdf') for fp in fps)

0 comments on commit 772c665

Please sign in to comment.