Commit 84f5d067 authored by Asitha Senanayake's avatar Asitha Senanayake
Browse files

feat: add function to retrieve TRAN_AGS

TRAN_AGS is required in more one place in the code, therefore added a
new function to retrieve TRAN_AGS from AGS4 data tables. This function
can be used to replace repetitive code blocks.
parent c4f4badb
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -306,6 +306,34 @@ def get_data_summary(tables):
    return summary


def get_TRAN_AGS(tables):
    '''Get TRAN_AGS from AGS4 file.

    Parameters
    ----------
    tables : dict of dataframes
      Dictionary of Pandas dataframes (output from 'AGS4_to_dataframe()')

    Returns
    -------
    str or None
    '''

    try:
        TRAN = tables['TRAN']
        tran_ags = TRAN.loc[TRAN.HEADING.eq('DATA'), 'TRAN_AGS'].values[0]

    except KeyError:
        # TRAN table missing. AGS Format Rule 14 should catch this error.
        tran_ags = None

    except IndexError:
        # No DATA rows in TRAN table. AGS Format Rule 14 should catch this error.
        tran_ags = None

    return tran_ags


def is_ags_ascii(s):
    '''Check if character is in the "extended" ASCII set.

+8 −1
Original line number Diff line number Diff line
import os

from python_ags4 import AGS4, __version__
from python_ags4 import AGS4, check, __version__
from python_ags4.data import TEST_DATA


def test_rule_1_utf8():
@@ -775,6 +776,12 @@ def test_duplicate_groups_raises_error():
    assert error_list['Validator Process Error'][0]['desc'] == msg


def test_get_TRAN_AGS():
    tables, _ = AGS4.AGS4_to_dataframe(TEST_DATA)

    assert check.get_TRAN_AGS(tables) == '4.0.4'


def test_data_summary():
    error_list = AGS4.check_file('tests/test_files/4.1-rule2.ags', standard_AGS4_dictionary='python_ags4/Standard_dictionary_v4_1.ags')