Skip to content
Open
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
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: python
python:
- "2.7"
# - "3.4"
# - "3.5"
- "3.4"
- "3.5"
# - "3.6"
#install:
# - pip install .
script: py.test
install:
- pip install .
script: nosetests
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[tool:pytest]
norecursedirs= venv
norecursedirs = venv
92 changes: 46 additions & 46 deletions test/out/testChat2_UsernameOne.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,55 @@ Root initiations: 0
Root initiation ratio: 1.00

Proportions:
avg_words
ratio -> 0.625
UsernameOne -> 2.75
UsernameTwo -> 4.4
media
total -> 1
ratio -> 1.0
UsernameTwo -> 1
UsernameOne -> 1
exclams
ratio -> 0.333333333333
UsernameOne -> 1
total -> 3
UsernameTwo -> 3
qmarks
UsernameTwo -> 1
total -> 4
ratio -> 4.0
UsernameOne -> 4
messages
ratio -> 0.8
UsernameOne -> 4
UsernameTwo -> 5
total -> 9
words
ratio -> 0.5
UsernameOne -> 11
UsernameTwo -> 22
total -> 33
chars
ratio -> 0.528
UsernameOne -> 66
UsernameTwo -> 125
total -> 191
(' ', 'avg_words')
(' ', 'ratio', '->', 0.625)
(' ', 'UsernameOne', '->', 2.75)
(' ', 'UsernameTwo', '->', 4.4)
(' ', 'media')
(' ', 'total', '->', 1)
(' ', 'ratio', '->', 1.0)
(' ', 'UsernameTwo', '->', 1)
(' ', 'UsernameOne', '->', 1)
(' ', 'exclams')
(' ', 'ratio', '->', 0.3333333333333333)
(' ', 'UsernameOne', '->', 1)
(' ', 'total', '->', 3)
(' ', 'UsernameTwo', '->', 3)
(' ', 'qmarks')
(' ', 'UsernameTwo', '->', 1)
(' ', 'total', '->', 4)
(' ', 'ratio', '->', 4.0)
(' ', 'UsernameOne', '->', 4)
(' ', 'messages')
(' ', 'ratio', '->', 0.8)
(' ', 'UsernameOne', '->', 4)
(' ', 'UsernameTwo', '->', 5)
(' ', 'total', '->', 9)
(' ', 'words')
(' ', 'ratio', '->', 0.5)
(' ', 'UsernameOne', '->', 11)
(' ', 'UsernameTwo', '->', 22)
(' ', 'total', '->', 33)
(' ', 'chars')
(' ', 'ratio', '->', 0.528)
(' ', 'UsernameOne', '->', 66)
(' ', 'UsernameTwo', '->', 125)
(' ', 'total', '->', 191)

Weekdays:
Tuesday -> 0
Friday -> 0
Thursday -> 0
Sunday -> 0
Saturday -> 0
Monday -> 1
Wednesday -> 8
('', 'Tuesday', '->', 0)
('', 'Friday', '->', 0)
('', 'Thursday', '->', 0)
('', 'Sunday', '->', 0)
('', 'Saturday', '->', 0)
('', 'Monday', '->', 1)
('', 'Wednesday', '->', 8)

Shifts:
evening -> 0
latenight -> 0
morning -> 1
afternoon -> 8
('', 'evening', '->', 0)
('', 'latenight', '->', 0)
('', 'morning', '->', 1)
('', 'afternoon', '->', 8)

Patterns:

Expand All @@ -75,4 +75,4 @@ time
hello,
media
exclam!!!
<media
<media
92 changes: 46 additions & 46 deletions test/out/testChat2_UsernameTwo.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,55 @@ Contact initiations: 0
Root initiation ratio: 1.00

Proportions:
avg_words
ratio -> 1.0
UsernameOne -> 2.75
UsernameTwo -> 4.4
media
UsernameOne -> 0
total -> 1
ratio -> 1.0
UsernameTwo -> 1
exclams
UsernameOne -> 0
ratio -> 1.0
total -> 3
UsernameTwo -> 3
qmarks
ratio -> 1.0
UsernameTwo -> 1
total -> 4
UsernameOne -> 4
messages
ratio -> 1.0
UsernameOne -> 4
UsernameTwo -> 5
total -> 9
words
ratio -> 1.0
UsernameOne -> 11
UsernameTwo -> 22
total -> 33
chars
ratio -> 1.0
UsernameOne -> 66
UsernameTwo -> 125
total -> 191
(' ', 'avg_words')
(' ', 'ratio', '->', 1.0)
(' ', 'UsernameOne', '->', 2.75)
(' ', 'UsernameTwo', '->', 4.4)
(' ', 'media')
(' ', 'UsernameOne', '->', 0)
(' ', 'total', '->', 1)
(' ', 'ratio', '->', 1.0)
(' ', 'UsernameTwo', '->', 1)
(' ', 'exclams')
(' ', 'UsernameOne', '->', 0)
(' ', 'ratio', '->', 1.0)
(' ', 'total', '->', 3)
(' ', 'UsernameTwo', '->', 3)
(' ', 'qmarks')
(' ', 'ratio', '->', 1.0)
(' ', 'UsernameTwo', '->', 1)
(' ', 'total', '->', 4)
(' ', 'UsernameOne', '->', 4)
(' ', 'messages')
(' ', 'ratio', '->', 1.0)
(' ', 'UsernameOne', '->', 4)
(' ', 'UsernameTwo', '->', 5)
(' ', 'total', '->', 9)
(' ', 'words')
(' ', 'ratio', '->', 1.0)
(' ', 'UsernameOne', '->', 11)
(' ', 'UsernameTwo', '->', 22)
(' ', 'total', '->', 33)
(' ', 'chars')
(' ', 'ratio', '->', 1.0)
(' ', 'UsernameOne', '->', 66)
(' ', 'UsernameTwo', '->', 125)
(' ', 'total', '->', 191)

Weekdays:
Tuesday -> 0
Friday -> 0
Thursday -> 0
Sunday -> 0
Saturday -> 0
Monday -> 1
Wednesday -> 8
('', 'Tuesday', '->', 0)
('', 'Friday', '->', 0)
('', 'Thursday', '->', 0)
('', 'Sunday', '->', 0)
('', 'Saturday', '->', 0)
('', 'Monday', '->', 1)
('', 'Wednesday', '->', 8)

Shifts:
evening -> 0
latenight -> 0
morning -> 1
afternoon -> 8
('', 'evening', '->', 0)
('', 'latenight', '->', 0)
('', 'morning', '->', 1)
('', 'afternoon', '->', 8)

Patterns:

Expand All @@ -75,4 +75,4 @@ time
hello,
media
exclam!!!
<media
<media
45 changes: 36 additions & 9 deletions test/test_chat.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
import os
import sys
import unittest

from wp_parser.wp_chat import main as parser

# for capturing print() output
from contextlib import contextmanager
try:
from StringIO import StringIO
except ImportError: #python3
from io import StringIO


@contextmanager
def captured_output():
new_out, new_err = StringIO(), StringIO()
old_out, old_err = sys.stdout, sys.stderr
try:
sys.stdout, sys.stderr = new_out, new_err
yield sys.stdout, sys.stderr
finally:
sys.stdout, sys.stderr = old_out, old_err


class TestChat(unittest.TestCase):
def test_chat_1(self):
# out_filename = str(tmpdir.join("abc"))
# out_filename = ""

class TestChat:
def test_chat(self, tmpdir):
out_filename = str(tmpdir.join("abc"))
for case in ['One', 'Two']:
cmd = 'python wp_parser/wp_chat.py -f test/testChat2.txt -n Username{} > {}'.format(case, out_filename)
os.system(cmd)
with open(out_filename) as fh:
result = fh.read()
# creating mock args
args = "-f test/testChat2.txt --root Username{}".format(case).split()

with captured_output() as (result, err):
parser(args)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than using os.system, better approach is to import the main package and pass args directly to it.


expected_file = 'test/out/testChat2_Username{}.out'.format(case)
with open(expected_file) as fh:
expected = fh.read()
assert result == expected

self.assertEqual(result.getvalue().strip(), expected)
Loading