# Path: f8a_worker/data_normalizer/python.py
# class PythonDataNormalizer(AbstractDataNormalizer):
#     """Python data normalizer.
# 
#     This normalizer handles data extracted from setup.py files by mercator-go.
#     """
# 
#     _key_map = (
#         ('url', 'homepage'),
#         ('install_requires', 'dependencies'), ('name',),
#         ('description',), ('version',)
#     )
# 
#     def __init__(self, mercator_json):
#         """Initialize function."""
#         if 'error' in mercator_json:
#             # mercator by default (MERCATOR_INTERPRET_SETUP_PY=false) doesn't interpret setup.py
#             mercator_json = {}
#         super().__init__(mercator_json)
# 
#     def normalize(self):
#         """Normalize output from Mercator for setup.py (Python)."""
#         if not self._raw_data:
#             return {}
# 
#         self._data['declared_licenses'] = self._split_keywords(
#             self._raw_data.get('license'), separator=','
#         )
#         self._data['author'] = self._join_name_email(self._raw_data, 'author', 'author_email')
#         self._data['code_repository'] = (
#                 self._identify_gh_repo(self._raw_data.get('url')) or
#                 self._identify_gh_repo(self._raw_data.get('download_url'))
#         )
#         self._data['keywords'] = self._split_keywords(self._raw_data.get('keywords'))
#         return self._data


import pytest
from f8a_worker.data_normalizer import PythonDataNormalizer
    ({'author': 'me', 'version': '0.1.2'}, (('author',),), {'author': 'me'}),
    # pick one key which IS NOT there
    ({'author-name': 'me', 'version': '0.1.2'}, (('author',),),
     {'author': None}),
    # pick & and rename one key which IS there
    ({'author-name': 'me'}, (('author-name', 'author',),),
     {'author': 'me'}),
    # pick & and rename one key which IS NOT there
    ({'authors': 'they'}, (('author-name', 'author',),),
     {'author': None}),
    # pick one of keys
    ({'license': 'MIT'}, ((('license', 'licenses',), ),),
     {'license': 'MIT'}),
    # pick one of keys
    ({'licenses': ['MIT', 'BSD']}, ((('license', 'licenses',),),),
     {'licenses': ['MIT', 'BSD']}),
    # pick one of keys and rename it
    ({'license': 'MIT'}, ((('license', 'licenses',), 'declared_licenses'),),
     {'declared_licenses': 'MIT'}),
])
def test_constructor(data, keymap, expected):
    """Test PythonDataNormalizer constructor."""
    dn = PythonDataNormalizer(data)
    assert dn is not None
    assert keymap
    assert expected


def test_constructor_error_input():
    """Test PythonDataNormalizer constructor for error input."""

# Path: f8a_worker/data_normalizer/python.py
# class PythonDataNormalizer(AbstractDataNormalizer):
#     """Python data normalizer.
# 
#     This normalizer handles data extracted from setup.py files by mercator-go.
#     """
# 
#     _key_map = (
#         ('url', 'homepage'),
#         ('install_requires', 'dependencies'), ('name',),
#         ('description',), ('version',)
#     )
# 
#     def __init__(self, mercator_json):
#         """Initialize function."""
#         if 'error' in mercator_json:
#             # mercator by default (MERCATOR_INTERPRET_SETUP_PY=false) doesn't interpret setup.py
#             mercator_json = {}
#         super().__init__(mercator_json)
# 
#     def normalize(self):
#         """Normalize output from Mercator for setup.py (Python)."""
#         if not self._raw_data:
#             return {}
# 
#         self._data['declared_licenses'] = self._split_keywords(
#             self._raw_data.get('license'), separator=','
#         )
#         self._data['author'] = self._join_name_email(self._raw_data, 'author', 'author_email')
#         self._data['code_repository'] = (
#                 self._identify_gh_repo(self._raw_data.get('url')) or
#                 self._identify_gh_repo(self._raw_data.get('download_url'))
#         )
#         self._data['keywords'] = self._split_keywords(self._raw_data.get('keywords'))
#         return self._data


# Path: tests/data_normalizer/test_python.py
import pytest
from f8a_worker.data_normalizer import PythonDataNormalizer

    ({'author': 'me', 'version': '0.1.2'}, (('author',),), {'author': 'me'}),
    # pick one key which IS NOT there
    ({'author-name': 'me', 'version': '0.1.2'}, (('author',),),
     {'author': None}),
    # pick & and rename one key which IS there
    ({'author-name': 'me'}, (('author-name', 'author',),),
     {'author': 'me'}),
    # pick & and rename one key which IS NOT there
    ({'authors': 'they'}, (('author-name', 'author',),),
     {'author': None}),
    # pick one of keys
    ({'license': 'MIT'}, ((('license', 'licenses',), ),),
     {'license': 'MIT'}),
    # pick one of keys
    ({'licenses': ['MIT', 'BSD']}, ((('license', 'licenses',),),),
     {'licenses': ['MIT', 'BSD']}),
    # pick one of keys and rename it
    ({'license': 'MIT'}, ((('license', 'licenses',), 'declared_licenses'),),
     {'declared_licenses': 'MIT'}),
])
def test_constructor(data, keymap, expected):
    """Test PythonDataNormalizer constructor."""
    dn = PythonDataNormalizer(data)
    assert dn is not None
    assert keymap
    assert expected


def test_constructor_error_input():
    """Test PythonDataNormalizer constructor for error input."""

    dn = PythonDataNormalizer("error")