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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ PyARINC424 is a tool that parses an [ARINC-424](https://en.wikipedia.org/wiki/AR
- Grid MORA (AS)

## Config File
A `config.ini` file must be created in the application `src` directory.
By default, the program looks for a `config.ini` file in the application `src` directory.
You can specify a different config path by passing it as an argument:
```sh
python main.py /path/to/my_config.ini
```

The config can be set up for *either* PostgreSQL or SQLite.

Expand Down
8 changes: 6 additions & 2 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@


class UserConfigs:
def __init__(self):
def __init__(self, config_file: str = "config.ini"):
parser = configparser.ConfigParser()
parser.read("config.ini")
read = parser.read(config_file)

if not read:
raise FileNotFoundError(f"Configuration file {config_file} not found")

validate(parser)

if parser.has_section("postgres"):
Expand Down
6 changes: 5 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from arinc import ArincParser
from config import UserConfigs
from database import DbConfig, get_db
import sys


def main() -> None:
configs: UserConfigs = UserConfigs()
if len(sys.argv) > 1:
kwargs = {"config_file": sys.argv[1]}

configs: UserConfigs = UserConfigs(**kwargs)

db: DbConfig = get_db(configs)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,11 @@ def test_invalid_config(self, mock_read):
ValueError, match="Missing required PostgreSQL configuration"
):
UserConfigs()

@mock.patch("configparser.ConfigParser.read", return_value=[])
def test_file_not_found(self, mock_read):
"""Test __init__ fails when the config file is not found."""
with pytest.raises(
FileNotFoundError, match="Configuration file missing.ini not found"
):
UserConfigs("missing.ini")