Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: error accessing table count #156

Closed
bl-young opened this issue Apr 1, 2024 · 0 comments
Closed

Exception: error accessing table count #156

bl-young opened this issue Apr 1, 2024 · 0 comments
Labels

Comments

@bl-young
Copy link
Collaborator

bl-young commented Apr 1, 2024

_______________________ test_generate_inventories[2020] ________________________

table = 'C_CONFIGURATION_LEVEL_INFO', report_year = '2020'

def get_row_count(table, report_year):
    """Return number of rows from API for specific table."""
    count_url = _config['enviro_url'] + table
    if report_year != '':
        count_url += f'/REPORTING_YEAR/=/{report_year}'
    count_url += '/COUNT'
    try:
        count_request = make_url_request(count_url)
        count_xml = minidom.parseString(count_request.text)
        table_count = count_xml.getElementsByTagName('TOTALQUERYRESULTS')
      table_count = int(table_count[0].firstChild.nodeValue)

E IndexError: list index out of range

stewi/GHGRP.py:127: IndexError

The above exception was the direct cause of the following exception:

year = 2020

@pytest.mark.parametrize("year", [2020])
@pytest.mark.inventory
def test_generate_inventories(year):
    for inventory in config()['databases']:
        try:
          generate_inventory(inventory, year)

tests/test_inventory_generation.py:30:


stewi/globals.py:302: in generate_inventory
GHGRP.main(Option = 'A', Year = [year])
stewi/GHGRP.py:770: in main
ghgrp1 = download_and_parse_subpart_tables(year, m)
stewi/GHGRP.py:338: in download_and_parse_subpart_tables
table_df = import_or_download_table(filepath, subpart_emissions_table,
stewi/GHGRP.py:244: in import_or_download_table
row_count = get_row_count(table, report_year=year)


table = 'C_CONFIGURATION_LEVEL_INFO', report_year = '2020'

def get_row_count(table, report_year):
    """Return number of rows from API for specific table."""
    count_url = _config['enviro_url'] + table
    if report_year != '':
        count_url += f'/REPORTING_YEAR/=/{report_year}'
    count_url += '/COUNT'
    try:
        count_request = make_url_request(count_url)
        count_xml = minidom.parseString(count_request.text)
        table_count = count_xml.getElementsByTagName('TOTALQUERYRESULTS')
        table_count = int(table_count[0].firstChild.nodeValue)
    except IndexError as e:
      raise Exception(f'error accessing table count for {table}') from e

E Exception: error accessing table count for C_CONFIGURATION_LEVEL_INFO

stewi/GHGRP.py:129: Exception

@bl-young bl-young added the bug label Apr 1, 2024
bl-young added a commit that referenced this issue Apr 1, 2024
update xml element tag resolves #156
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant