コード例 #1
0
ファイル: test_file_stream.py プロジェクト: Aquilafire/pyais
 def test_reader(self):
     messages = [msg for msg in FileReaderStream(self.FILENAME)]
     assert len(messages) == 7
     for msg in messages:
         assert type(msg) == NMEAMessage
         assert msg.is_valid
         assert msg.decode().content is not None
コード例 #2
0
ファイル: test_file_stream.py プロジェクト: marinetech/pyais
    def test_marine_traffic_sample(self):
        """Test some messages from https://help.marinetraffic.com/hc/en-us
        /articles/215626187-I-am-an-AIS-data-contributor-Can-you-share-more-data-with-me-"""

        par_dir = pathlib.Path(__file__).parent.absolute()
        nmea_file = par_dir.joinpath("nmea_data_sample.txt")

        with FileReaderStream(nmea_file) as stream:
            for msg in stream:
                assert msg.decode()
コード例 #3
0
ファイル: test_file_stream.py プロジェクト: marinetech/pyais
 def test_large_file(self):
     # The ais sample data is downloaded from https://www.aishub.net/ais-dispatcher
     par_dir = pathlib.Path(__file__).parent.absolute()
     large_file = par_dir.joinpath("nmea-sample")
     for msg in FileReaderStream(large_file):
         msg.decode()
コード例 #4
0
ファイル: test_file_stream.py プロジェクト: marinetech/pyais
 def test_invalid_filename(self):
     with self.assertRaises(FileNotFoundError):
         FileReaderStream("doesnotexist")
コード例 #5
0
ファイル: test_file_stream.py プロジェクト: marinetech/pyais
 def test_reader_with_open(self):
     with FileReaderStream(self.FILENAME) as stream:
         msg = next(stream)
         assert type(msg) == NMEAMessage
         assert msg.is_valid
         assert msg.decode().content is not None
コード例 #6
0
ファイル: test_file_stream.py プロジェクト: sean-foley/pyais
 def test_mixed_content(self):
     """Test that the file reader handles mixed content. That means, that is is able to handle
     text files, that contain both AIS messages and non AIS messages."""
     par_dir = pathlib.Path(__file__).parent.absolute()
     mixed_content_file = par_dir.joinpath("messages.ais")
     self.assertEqual(len(list(iter(FileReaderStream(mixed_content_file)))), 6)
コード例 #7
0
from pyais.stream import FileReaderStream

filename = "sample.ais"

for msg in FileReaderStream(filename):
    decoded_message = msg.decode()
    ais_content = decoded_message.content
    # Do something with the ais message