|
11 | 11 | # See the License for the specific language governing permissions and |
12 | 12 | # limitations under the License. |
13 | 13 |
|
| 14 | +import os |
14 | 15 | import re |
15 | 16 |
|
16 | 17 | from sentiment_analysis import analyze |
17 | 18 |
|
| 19 | +RESOURCES = os.path.join(os.path.dirname(__file__), 'resources') |
18 | 20 |
|
19 | | -def test_pos(resource, capsys): |
20 | | - analyze(resource('pos.txt')) |
| 21 | + |
| 22 | +def test_pos(capsys): |
| 23 | + analyze(os.path.join(RESOURCES, 'pos.txt')) |
21 | 24 | out, err = capsys.readouterr() |
22 | 25 | score = float(re.search('score of (.+?) with', out).group(1)) |
23 | 26 | magnitude = float(re.search('magnitude of (.+?)', out).group(1)) |
24 | 27 | assert score * magnitude > 0 |
25 | 28 |
|
26 | 29 |
|
27 | | -def test_neg(resource, capsys): |
28 | | - analyze(resource('neg.txt')) |
| 30 | +def test_neg(capsys): |
| 31 | + analyze(os.path.join(RESOURCES, 'neg.txt')) |
29 | 32 | out, err = capsys.readouterr() |
30 | 33 | score = float(re.search('score of (.+?) with', out).group(1)) |
31 | 34 | magnitude = float(re.search('magnitude of (.+?)', out).group(1)) |
32 | 35 | assert score * magnitude < 0 |
33 | 36 |
|
34 | 37 |
|
35 | | -def test_mixed(resource, capsys): |
36 | | - analyze(resource('mixed.txt')) |
| 38 | +def test_mixed(capsys): |
| 39 | + analyze(os.path.join(RESOURCES, 'mixed.txt')) |
37 | 40 | out, err = capsys.readouterr() |
38 | 41 | score = float(re.search('score of (.+?) with', out).group(1)) |
39 | 42 | assert score <= 0.3 |
40 | 43 | assert score >= -0.3 |
41 | 44 |
|
42 | 45 |
|
43 | | -def test_neutral(resource, capsys): |
44 | | - analyze(resource('neutral.txt')) |
| 46 | +def test_neutral(capsys): |
| 47 | + analyze(os.path.join(RESOURCES, 'neutral.txt')) |
45 | 48 | out, err = capsys.readouterr() |
46 | 49 | magnitude = float(re.search('magnitude of (.+?)', out).group(1)) |
47 | 50 | assert magnitude <= 2.0 |
0 commit comments