|
| 1 | +# Copyright 2016, Google, Inc. |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | + |
| 14 | +import re |
| 15 | +from sentiment_analysis import main |
| 16 | + |
| 17 | + |
| 18 | +def test_pos(resource, capsys): |
| 19 | + main(resource('pos.txt')) |
| 20 | + out, err = capsys.readouterr() |
| 21 | + polarity = float(re.search('polarity of (.+?) with', out).group(1)) |
| 22 | + magnitude = float(re.search('magnitude of (.+?)', out).group(1)) |
| 23 | + assert polarity * magnitude > 0 |
| 24 | + |
| 25 | + |
| 26 | +def test_neg(resource, capsys): |
| 27 | + main(resource('neg.txt')) |
| 28 | + out, err = capsys.readouterr() |
| 29 | + polarity = float(re.search('polarity of (.+?) with', out).group(1)) |
| 30 | + magnitude = float(re.search('magnitude of (.+?)', out).group(1)) |
| 31 | + assert polarity * magnitude < 0 |
| 32 | + |
| 33 | + |
| 34 | +def test_mixed(resource, capsys): |
| 35 | + main(resource('mixed.txt')) |
| 36 | + out, err = capsys.readouterr() |
| 37 | + polarity = float(re.search('polarity of (.+?) with', out).group(1)) |
| 38 | + assert polarity <= 0.3 |
| 39 | + assert polarity >= -0.3 |
| 40 | + |
| 41 | + |
| 42 | +def test_neutral(resource, capsys): |
| 43 | + main(resource('neutral.txt')) |
| 44 | + out, err = capsys.readouterr() |
| 45 | + magnitude = float(re.search('magnitude of (.+?)', out).group(1)) |
| 46 | + assert magnitude <= 2.0 |
0 commit comments