Skip to content

Commit

Permalink
Merge b05ac61 into d895837
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch committed Oct 28, 2018
2 parents d895837 + b05ac61 commit 6315877
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build
Expand Up @@ -17,7 +17,7 @@ find . -name "*.pyc" -delete

# Run unit tests and calculate code coverage.
coverage run \
--source "$SOURCE_DIR" \
--source "$SOURCE_DIR,main.py" \
-m unittest discover

# Check that source has correct formatting.
Expand Down
5 changes: 2 additions & 3 deletions chat_unifier/history_merger.py
Expand Up @@ -20,13 +20,12 @@ def add(self, history):


def _key_for_history(history):
return '%s:%s' % (history.local_username, ','.join(
history.remote_usernames))
return '%s:%s' % (history.local_username, history.remote_username)


def _merge_histories(a, b):
messages = sorted(a.messages + b.messages, key=lambda m: m.timestamp)
return models.History(
local_username=a.local_username,
remote_usernames=a.remote_usernames,
remote_username=a.remote_username,
messages=messages)
2 changes: 1 addition & 1 deletion chat_unifier/json_serializer.py
Expand Up @@ -24,7 +24,7 @@ def _history_list_to_list_of_dicts(history_list):
def _history_to_dict(history):
return {
'localUsername': history.local_username,
'remoteUsernames': history.remote_usernames,
'remoteUsername': history.remote_username,
'messages': _messages_to_list_of_dicts(history.messages)
}

Expand Down
2 changes: 1 addition & 1 deletion chat_unifier/models.py
Expand Up @@ -4,4 +4,4 @@
'Message', field_names=['sender', 'timestamp', 'contents'])

History = collections.namedtuple(
'History', field_names=['local_username', 'remote_usernames', 'messages'])
'History', field_names=['local_username', 'remote_username', 'messages'])
6 changes: 3 additions & 3 deletions chat_unifier/parsers/trillian/parser.py
Expand Up @@ -9,13 +9,13 @@ class Parser(object):
def parse(self, log_contents):
messages = []
local_username = None
remote_usernames = set()
remote_username = None
lines = [x for x in log_contents.split('\n') if x]
for line in lines:
parsed_line = line_parser.parse(line)
if _is_session_start_line(parsed_line):
local_username = parsed_line.local_username
remote_usernames.add(parsed_line.remote_username)
remote_username = parsed_line.remote_username
elif _is_message_line(parsed_line):
messages.append(
models.Message(
Expand All @@ -24,7 +24,7 @@ def parse(self, log_contents):
contents=parsed_line.contents))
return models.History(
local_username=local_username,
remote_usernames=list(remote_usernames),
remote_username=remote_username,
messages=messages)


Expand Down
2 changes: 1 addition & 1 deletion tests/parsers/trillian/test_parser.py
Expand Up @@ -17,7 +17,7 @@ def test_parse_log_with_one_simple_conversation(self):
""".lstrip()),
models.History(
local_username='LocalUser456',
remote_usernames=['RemoteBuddy123'],
remote_username='RemoteBuddy123',
messages=[
models.Message(
sender=u'RemoteBuddy123',
Expand Down
10 changes: 5 additions & 5 deletions tests/test_history_merger.py
Expand Up @@ -12,7 +12,7 @@ def test_merges_histories_from_same_remote_user(self):
merger.add(
models.History(
local_username='dummy_local123',
remote_usernames=['dummy_remote345'],
remote_username='dummy_remote345',
messages=[
models.Message(
sender='dummy_remote345',
Expand All @@ -26,7 +26,7 @@ def test_merges_histories_from_same_remote_user(self):
merger.add(
models.History(
local_username='dummy_local123',
remote_usernames=['dummy_remote345'],
remote_username='dummy_remote345',
messages=[
models.Message(
sender='dummy_remote345',
Expand All @@ -44,7 +44,7 @@ def test_merges_histories_from_same_remote_user(self):
merged_history,
models.History(
local_username='dummy_local123',
remote_usernames=['dummy_remote345'],
remote_username='dummy_remote345',
messages=[
models.Message(
sender='dummy_remote345',
Expand All @@ -69,7 +69,7 @@ def test_does_not_merge_histories_from_different_remote_users(self):
merger.add(
models.History(
local_username='dummy_local123',
remote_usernames=['dummy_remote345'],
remote_username='dummy_remote345',
messages=[
models.Message(
sender='dummy_remote345',
Expand All @@ -83,7 +83,7 @@ def test_does_not_merge_histories_from_different_remote_users(self):
merger.add(
models.History(
local_username='dummy_local123',
remote_usernames=['dummy_remote999'],
remote_username='dummy_remote999',
messages=[
models.Message(
sender='dummy_remote999',
Expand Down
12 changes: 4 additions & 8 deletions tests/test_json_serializer.py
Expand Up @@ -24,9 +24,7 @@ def test_serializes_simple_history(self):
"timestamp": "2018-10-18T18:27:05Z"
}
],
"remoteUsernames": [
"dummy_remote345"
]
"remoteUsername": "dummy_remote345"
},
{
"localUsername": "dummy_local123",
Expand All @@ -37,17 +35,15 @@ def test_serializes_simple_history(self):
"timestamp": "2018-10-20T04:15:43Z"
}
],
"remoteUsernames": [
"dummy_remote456"
]
"remoteUsername": "dummy_remote456"
}
]
""".strip(),
json.dumps(
[
models.History(
local_username='dummy_local123',
remote_usernames=['dummy_remote345'],
remote_username='dummy_remote345',
messages=[
models.Message(
sender='dummy_local123',
Expand All @@ -57,7 +53,7 @@ def test_serializes_simple_history(self):
]),
models.History(
local_username='dummy_local123',
remote_usernames=['dummy_remote456'],
remote_username='dummy_remote456',
messages=[
models.Message(
sender='dummy_remote456',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models.py
Expand Up @@ -57,7 +57,7 @@ def test_identical_histories_are_equal(self):
self.assertEqual(
models.History(
local_username='dummy_local123',
remote_usernames=['dummy_remote345'],
remote_username='dummy_remote345',
messages=[
models.Message(
sender='dummy_sender',
Expand All @@ -66,7 +66,7 @@ def test_identical_histories_are_equal(self):
]),
models.History(
local_username='dummy_local123',
remote_usernames=['dummy_remote345'],
remote_username='dummy_remote345',
messages=[
models.Message(
sender='dummy_sender',
Expand Down

0 comments on commit 6315877

Please sign in to comment.