Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## About

PyARINC424 is a tool that parses an [ARINC-424](https://en.wikipedia.org/wiki/ARINC_424) formatted data file into a PostreSQL database. PyARINC424 supports the tables/records that are currently output in [FAA CIFP](https://www.faa.gov/air_traffic/flight_info/aeronav/digital_products/cifp/download/):
PyARINC424 is a tool that parses an [ARINC-424](https://en.wikipedia.org/wiki/ARINC_424) formatted data file into a SQLite or PostreSQL database. PyARINC424 supports the tables/records that are currently output in [FAA CIFP](https://www.faa.gov/air_traffic/flight_info/aeronav/digital_products/cifp/download/):
- Airports and heliports (PA and HA)
- Runways (PG)
- VHF Navaids (D)
Expand Down
7 changes: 7 additions & 0 deletions src/pyarinc424/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import configparser
import os


class UserConfigs:
Expand All @@ -25,6 +26,12 @@ def __init__(self, config_file: str = "config.ini"):

self.file_loc = parser["cifp_file"]["file_loc"]

# if the file_loc path is not absolute, make it absolute and relative to the config file
if not self.file_loc.startswith("/"):
self.file_loc = os.path.abspath(
os.path.join(os.path.dirname(config_file), self.file_loc)
)


def validate(parser: configparser.ConfigParser) -> None:
if not parser.has_section("postgres") and not parser.has_section("sqlite"):
Expand Down
25 changes: 25 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from unittest import mock
import configparser
import os
from pyarinc424.config import UserConfigs, validate # type: ignore


Expand Down Expand Up @@ -185,3 +186,27 @@ def test_file_not_found(self, mock_read):
FileNotFoundError, match="Configuration file missing.ini not found"
):
UserConfigs("missing.ini")


class TestUserConfigsRelativeFileLoc:
def test_relative_file_loc_conversion(self, tmp_path):
"""Test that a relative file_loc in the configuration is converted to an absolute path."""
config_content = """
[postgres]
dbname = testdb
user = testuser
password = testpass
host = localhost
port = 5432

[cifp_file]
file_loc = relative/path/to/file
"""
config_file = tmp_path / "config.ini"
config_file.write_text(config_content.strip())

user_configs = UserConfigs(str(config_file))
expected_path = os.path.abspath(
os.path.join(os.path.dirname(str(config_file)), "relative/path/to/file")
)
assert user_configs.file_loc == expected_path