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

Strip whitespace #362

Merged
merged 1 commit into from
Sep 25, 2023
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
21 changes: 14 additions & 7 deletions pyvecorg/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,23 @@ def parse_members(rows):

def coerce_member(member):
return {
'name': member.get('nickname', member.get('name')),
'role': member.get('role', 'member'),
'github': member.get('github'),
'twitter': member.get('twitter'),
'mastodon': member.get('mastodon'),
'linkedin': member.get('linkedin'),
'avatar_filename': member.get('avatar_filename'),
'name': strip_whitespace(member.get('nickname', member.get('name'))),
'role': strip_whitespace(member.get('role', 'member')),
'github': strip_whitespace(member.get('github')),
'twitter': strip_whitespace(member.get('twitter')),
'mastodon': strip_whitespace(member.get('mastodon')),
'linkedin': strip_whitespace(member.get('linkedin')),
'avatar_filename': strip_whitespace(member.get('avatar_filename')),
}


def strip_whitespace(value):
try:
return value.strip() or None
except AttributeError:
return value


def generate_yaml(data):
yaml_contents = dedent('''\
#
Expand Down
23 changes: 23 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
import requests
import jsonschema
from pyvecorg.build import coerce_member, strip_whitespace

from pyvecorg.data import (load_data, select_language,
DATA_PATH, SUPPORTED_LANGS)
Expand Down Expand Up @@ -180,3 +181,25 @@ def test_select_language_missing():
}}]}}
data_out = {'deep': {'nested': [{'key': None}]}}
assert select_language(data_in, 'en') == data_out


def test_coerce_member_name():
member = {'name': 'Jan Python', 'nickname': 'Honza P.'}

assert coerce_member(member)['name'] == 'Honza P.'


def test_coerce_member_whitespace():
member = {'mastodon': ' @[email protected] '}

assert coerce_member(member)['mastodon'] == '@[email protected]'


@pytest.mark.parametrize('value, expected', [
(None, None),
('', None),
(' ', None),
(' @pyconcz ', '@pyconcz'),
])
def test_strip_whitespace(value: str, expected: str):
assert strip_whitespace(value) == expected
Loading