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

[dai] Fix regex bug #37

Merged
merged 1 commit into from
Aug 25, 2020
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
2 changes: 1 addition & 1 deletion iottalkpy/dai.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def on_data(self, df_name, data):

@staticmethod
def df_func_name(df_name):
return re.sub(r'-(I|O)$', r'_\1', df_name)
return re.sub(r'-', r'_', df_name)

def _check_parameter(self):
if self.api_url is None:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_dai.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest

from iottalkpy.dai import DAI
from iottalkpy.dai import load_module
from iottalkpy.dai import parse_df_profile
from iottalkpy.dan import RegistrationError
Expand Down Expand Up @@ -33,6 +34,17 @@
('RegistrationError',)
]

'''
Each element in this list should be a tuple.
The first element in a tuple is the device feature name,
and the second element is the corresponding function name.
'''
df_name_list = [
('CO2-TI', 'CO2_TI'),
('Switch-O1', 'Switch_O1'),
('PumpWater-O', 'PumpWater_O')
]


@pytest.fixture
def dai_path(request):
Expand Down Expand Up @@ -142,3 +154,8 @@ def test_parse_df_profile_RegistrationError(sa_profile):
parse_df_profile(sa_profile, 'idf')
with pytest.raises(RegistrationError):
parse_df_profile(sa_profile, 'odf')


@pytest.mark.parametrize('df_name, df_function_name', df_name_list)
def test_dai_df_func_name(df_name, df_function_name):
assert DAI.df_func_name(df_name) == df_function_name