Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix comparison of True and None for NoneFilter #129

Merged
merged 1 commit into from
Jan 20, 2024
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
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
Loading