Skip to content

Commit

Permalink
fixing test imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ampledata committed Feb 3, 2025
1 parent a883b8b commit f982cae
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 52 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AISCOT is a software solution designed to monitor and analyze maritime surveilla
- Compatibility with ATAK, WinTAK, iTAK, TAK Server & TAKX
- Support for RF AIS transmissions, local NMEA, and Internet AIS aggregators
- Display of AIS data with icons, attitude, type, track, bearing, speed, callsign, and more
- Support
- Support for [United States Department of Transportation (US DOT) SeaVision](https://seavision.volpe.dot.gov/)

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion src/aiscot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
DEFAULT_SHIP_DB_FILE,
)

from .functions import create_tasks, cot_to_xml # NOQA
from .functions import create_tasks, cot_to_xml, ais_to_cot # NOQA

from .ais_functions import get_known_craft # NOQA

Expand Down
54 changes: 21 additions & 33 deletions tests/test_ais_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2023 Greg Albrecht <[email protected]>
# Copyright Sensors & Signals LLC https://www.snstac.com/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,21 +20,7 @@

import pytest

from aiscot.constants import DEFAULT_MID_DB_FILE, DEFAULT_SHIP_DB_FILE

from aiscot.ais_functions import (
get_aton,
get_mid,
get_known_craft,
get_sar,
get_crs,
get_shipname,
)


__author__ = "Greg Albrecht <[email protected]>"
__copyright__ = "Copyright 2023 Greg Albrecht"
__license__ = "Apache License, Version 2.0"
import aiscot


@pytest.fixture
Expand Down Expand Up @@ -121,38 +107,40 @@ def sample_aton():
def test_get_mid(sample_data_pyAISm):
"""Test that git_mid returns the country MID corresponding for a given MMSI."""
mmsi = sample_data_pyAISm.get("mmsi")
country = get_mid(mmsi)
country = aiscot.ais_functions.get_mid(mmsi)
assert country == "United States of America"


def test_get_known_craft():
"""Test reading know craft CSV with `get_known_craft()`."""
known_craft = get_known_craft("tests/data/test_known_craft.csv")
"""Test reading know craft CSV with `aiscot.ais_functions.get_known_craft()`."""
known_craft = aiscot.ais_functions.get_known_craft(
"tests/data/test_known_craft.csv"
)
assert known_craft[0].get("MMSI") == "366892000"


def test_get_aton(sample_aton):
"""Test Aid to Naviation vessels with `get_aton()`."""
"""Test Aid to Naviation vessels with `aiscot.ais_functions.get_aton()`."""
mmsi = sample_aton.get("mmsi")
assert get_aton(mmsi) is True
assert aiscot.ais_functions.get_aton(mmsi) is True


def test_get_crs():
"""Test CRS vessels with `get_crs()`."""
assert get_crs("3669123") is True
assert get_crs("003369000") is True
assert get_crs("938852000") is False
"""Test CRS vessels with `aiscot.ais_functions.get_crs()`."""
assert aiscot.ais_functions.get_crs("3669123") is True
assert aiscot.ais_functions.get_crs("003369000") is True
assert aiscot.ais_functions.get_crs("938852000") is False


def test_get_sar():
"""Test SAR vessels with `get_sar()`."""
assert get_sar("111892000") is True
assert get_sar("303862000") is True
assert get_sar("338852000") is True
assert get_sar("938852000") is False
"""Test SAR vessels with `aiscot.ais_functions.get_sar()`."""
assert aiscot.ais_functions.get_sar("111892000") is True
assert aiscot.ais_functions.get_sar("303862000") is True
assert aiscot.ais_functions.get_sar("338852000") is True
assert aiscot.ais_functions.get_sar("938852000") is False


def test_get_shipname():
"""Test getting shipname from db using `get_shipname()`."""
assert get_shipname("303990000") == "USCG EAGLE"
assert get_shipname("938852000") == ""
"""Test getting shipname from db using `aiscot.ais_functions.get_shipname()`."""
assert aiscot.ais_functions.get_shipname("303990000") == "USCG EAGLE"
assert aiscot.ais_functions.get_shipname("938852000") == ""
32 changes: 15 additions & 17 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@

import pytest

from aiscot.ais_functions import read_known_craft_fd
from aiscot.constants import DEFAULT_MID_DB_FILE, DEFAULT_SHIP_DB_FILE
from aiscot.functions import ais_to_cot, cot_to_xml
import aiscot


@pytest.fixture
Expand Down Expand Up @@ -115,11 +113,11 @@ def sample_known_craft():
366892000,TACO_01,a-f-S-T-A-C-O,
"""
csv_fd = io.StringIO(sample_csv)
return read_known_craft_fd(csv_fd)
return aiscot.ais_functions.read_known_craft_fd(csv_fd)


def test_ais_to_cot(sample_data_pyAISm):
cot = ais_to_cot(sample_data_pyAISm)
cot = aiscot.ais_to_cot(sample_data_pyAISm)
assert isinstance(cot, ET.Element)
assert cot.tag == "event"
assert cot.attrib["version"] == "2.0"
Expand Down Expand Up @@ -154,7 +152,7 @@ def test_ais_to_cot_with_known_craft(sample_data_pyAISm, sample_known_craft):
or [{}]
)[0]

cot = ais_to_cot(sample_data_pyAISm, known_craft=known_craft)
cot = aiscot.ais_to_cot(sample_data_pyAISm, known_craft=known_craft)

assert isinstance(cot, ET.Element)
assert cot.tag == "event"
Expand All @@ -181,9 +179,9 @@ def test_ais_to_cot_with_known_craft(sample_data_pyAISm, sample_known_craft):


def test_ais_to_cot_none():
"""Test that `ais_to_cot()` only renders valid input data."""
"""Test that `aiscot.ais_to_cot()` only renders valid input data."""
assert (
ais_to_cot(
aiscot.ais_to_cot(
{
"mmsi": 366892000,
"lon": 0,
Expand All @@ -193,7 +191,7 @@ def test_ais_to_cot_none():
is None
)
assert (
ais_to_cot(
aiscot.ais_to_cot(
{
"mmsi": 366892000,
"lon": -122.51208,
Expand All @@ -203,7 +201,7 @@ def test_ais_to_cot_none():
is None
)
assert (
ais_to_cot(
aiscot.ais_to_cot(
{
"mmsi": "",
"lon": -122.51208,
Expand All @@ -212,23 +210,23 @@ def test_ais_to_cot_none():
)
is None
)
assert ais_to_cot({}) is None
assert aiscot.ais_to_cot({}) is None


def test_ais_to_cot_dont_ignore_aton(sample_aton):
"""Test ignoring Aids to Naviation (ATON)."""
assert ais_to_cot(sample_aton, {"IGNORE_ATON": False}) is not None
assert aiscot.ais_to_cot(sample_aton, {"IGNORE_ATON": False}) is not None


def test_ais_to_cot_ignore_aton(sample_aton):
"""Test ignoring Aids to Naviation (ATON)."""
assert ais_to_cot(sample_aton, {"IGNORE_ATON": True}) is None
assert aiscot.ais_to_cot(sample_aton, {"IGNORE_ATON": True}) is None


def test_ais_to_cot_shipname(sample_data_pyAISm):
"""Test converting AIS to CoT with a known shipname."""
sample_data_pyAISm["mmsi"] = "303990000"
cot = ais_to_cot(sample_data_pyAISm)
cot = aiscot.ais_to_cot(sample_data_pyAISm)

detail = cot.findall("detail")
assert detail[0].tag == "detail"
Expand All @@ -240,7 +238,7 @@ def test_ais_to_cot_shipname(sample_data_pyAISm):
def test_ais_to_cot_sar(sample_data_pyAISm):
"""Test converting AIS to CoT for a SAR vessel."""
sample_data_pyAISm["mmsi"] = "303862000"
cot = ais_to_cot(sample_data_pyAISm)
cot = aiscot.ais_to_cot(sample_data_pyAISm)

assert cot.tag == "event"
assert cot.attrib["type"] == "a-f-S-X-L"
Expand All @@ -249,14 +247,14 @@ def test_ais_to_cot_sar(sample_data_pyAISm):
def test_ais_to_cot_crs(sample_data_pyAISm):
"""Test converting AIS to CoT for a CRS vessel."""
sample_data_pyAISm["mmsi"] = "3669123"
cot = ais_to_cot(sample_data_pyAISm)
cot = aiscot.ais_to_cot(sample_data_pyAISm)

assert cot.tag == "event"
assert cot.attrib["type"] == "a-f-G-I-U-T"


def test_ais_to_cot(sample_data_pyAISm):
"""Test converting AIS to CoT."""
cot: bytes = cot_to_xml(sample_data_pyAISm)
cot: bytes = aiscot.cot_to_xml(sample_data_pyAISm)
assert b"a-f-S-X-M" in cot
assert b"MMSI-366892000" in cot

0 comments on commit f982cae

Please sign in to comment.