Skip to content

Commit

Permalink
fix: fix comparison of True and None for NoneFilter (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
M0r13n authored Jan 20, 2024
1 parent 6ec596b commit 06bd464
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
pyais CHANGELOG
====================
-------------------------------------------------------------------------------
Version 2.5.9 26 Nov 2023
Version 2.6.1 20 Jan 2024
-------------------------------------------------------------------------------
* fixes a logic bug in `NoneFilter`
* https://github.com/M0r13n/pyais/issues/128
-------------------------------------------------------------------------------
Version 2.6.0 28 Dec 2023
-------------------------------------------------------------------------------
* Initial release of the AIS Filters system.
* Basic filtering classes: `NoneFilter`, `MessageTypeFilter`, and `DistanceFilter`.
Expand Down
2 changes: 1 addition & 1 deletion pyais/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pyais.tracker import AISTracker, AISTrack

__license__ = 'MIT'
__version__ = '2.6.0'
__version__ = '2.6.1'
__author__ = 'Leon Morten Richter'

__all__ = (
Expand Down
2 changes: 1 addition & 1 deletion pyais/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def filter_data(self, data: AIS_STREAM) -> AIS_STREAM:
AIS_STREAM: The filtered data stream.
"""
for msg in data:
if all(getattr(msg, attr, False) is not None for attr in self.attrs):
if all(getattr(msg, attr, None) is not None for attr in self.attrs):
yield msg


Expand Down
6 changes: 3 additions & 3 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def test_filtering_none_attributes(self):
self.assertEqual(len(filtered_data), 1) # Only one message should pass through the filter

def test_filtering_missing_attributes(self):
# Setup
attrs = ['lat', 'lon', 'foo'] # foo is never an attribute
# Setup - foo is never an attribute
attrs = ['foo']
filter = NoneFilter(*attrs)

# Create mock data with varying attributes: some missing, some None, some with value
Expand All @@ -39,7 +39,7 @@ def test_filtering_missing_attributes(self):
filtered_data = list(filter.filter_data(mock_data))

# Assert
self.assertEqual(len(filtered_data), 1) # Only one message with all attributes should pass through
self.assertEqual(len(filtered_data), 0)


class TestMessageTypeFilter(unittest.TestCase):
Expand Down

0 comments on commit 06bd464

Please sign in to comment.