Skip to content

Commit

Permalink
Merge pull request #62 from navigating-stories/fix-tests
Browse files Browse the repository at this point in the history
Fix tests and CI
  • Loading branch information
stefsmeets committed Jun 12, 2024
2 parents e0a90c6 + 42819a2 commit 2577d93
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 180 deletions.
20 changes: 0 additions & 20 deletions .coveragerc

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,3 @@ jobs:
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

publish-to-test_pypi:
name: Publish distribution to Test PyPI
needs: [build]
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push'
environment:
name: testpypi
url: https://test.pypi.org/p/storynavigator
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download the distribution packages
uses: actions/download-artifact@v3
with:
name: artifact
path: dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
49 changes: 0 additions & 49 deletions .github/workflows/publish-to-testpypi.yml

This file was deleted.

59 changes: 35 additions & 24 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,46 @@ on:
pull_request:
branches:
- master
types:
- opened
- reopened
- synchronize
- ready_for_review
workflow_dispatch:

jobs:
build:
test:
if: github.event.pull_request.draft == false
name: Run Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 tox
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# - name: Lint with flake8
# run: |
# # stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with Tox
run: |
tox -vv
env:
QT_QPA_PLATFORM: offscreen
- uses: actions/checkout@v3
with:
submodules: 'true'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v3
id: cache-virtualenv
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('setup.cfg') }}

- name: Install dependencies
if: steps.cache-virtualenv.outputs.cache-hit != 'true'
run: |
python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
python -m pip install -e .[dev]
- name: Test with pytest
run: |
pytest
env:
QT_QPA_PLATFORM: offscreen
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ flenv/
.venv/

data/
workflows/

navigator.code-workspace

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,18 @@ Steps to build and test from source:

The Orange3 application should shortly start up with a splash screen

## Testing

Run tests with `pytest`.

For coverage:

```python
coverage run -m pytest
coverage report
# or
coverage html
```

## Collaborators
The Story Navigator is maintained by the [Netherlands eScience Center](https://www.esciencecenter.nl/) in collaboration with the [Faculty of Behavioural, Management and Social Sciences (BMS)](https://www.utwente.nl/en/bms/) at the [University of Twente](https://www.utwente.nl/en/).
14 changes: 8 additions & 6 deletions orangecontrib/storynavigation/modules/actoranalysis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Modules required for Actor Analysis widget in Story Navigator.
"""

from __future__ import annotations


import os
import pandas as pd
import numpy as np
Expand Down Expand Up @@ -191,7 +194,7 @@ def __postag_sents(
return self.html_result

def postag_text(
self, text, nouns, subjs, custom, selected_prominence_metric, prominence_score_min, story_elements_df
self, text, nouns: bool, subjs: bool, custom: bool, selected_prominence_metric: float, prominence_score_min: int, story_elements_df: pd.DataFrame | None
):
"""POS-tags story text and returns HTML string which encodes the the tagged text, ready for rendering in the UI
Expand All @@ -201,19 +204,18 @@ def postag_text(
subjs (boolean): whether subject tokens should be tagged
custom (boolean): whether custom tags should be highlighted or not
selected_prominence_metric (float): the selected metric by which to calculate the word prominence score
prominence_score_min (float): the minimum prominence score for an entity which qualifies it to be tagged
prominence_score_min (int): the minimum prominence score for an entity which qualifies it to be tagged
story_elements_df (pandas.DataFrame): a dataframe with all required nlp tagging information
Returns:
string: HTML string representation of POS tagged text
"""
if story_elements_df is None or (len(story_elements_df) == 0):
sentences = util.preprocess_text(text)
return self.__print_html_no_highlighted_tokens(sentences)

sorted_df = story_elements_df.sort_values(by=['storyid', 'sentence_id'], ascending=True)
sentences = sorted_df['sentence'].unique().tolist()
# sentences = util.preprocess_text(text)

if story_elements_df is None or len(story_elements_df) == 0:
return self.__print_html_no_highlighted_tokens(sentences)

selected_storyid = story_elements_df['storyid'].unique().tolist()[0]
specific_tag_choice_html = (str(int(nouns)) + str(int(subjs)) + str(int(custom)))
Expand Down
18 changes: 9 additions & 9 deletions orangecontrib/storynavigation/widgets/OWSNActorAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ class Error(OWWidget.Error):
# currently selected agent prominence metric
agent_prominence_metric = constants.SELECTED_PROMINENCE_METRIC
# minimum possible score for agent prominence
agent_prominence_score_min = 0.0
agent_prominence_score_min = 0
# maximum possible score for agent prominence
agent_prominence_score_max = 15.0
agent_prominence_score_max = 15

word_prominence_scores = {}

Expand Down Expand Up @@ -834,13 +834,13 @@ def show_docs(self, slider_engaged=False):
if feature.name.lower() == "content" or feature.name.lower() == "text":
if len(self.story_elements_dict) > 0:
value = self.actortagger.postag_text(
value,
self.nouns,
self.subjs,
self.custom,
self.agent_prominence_metric,
self.agent_prominence_score_min,
self.story_elements_dict[str(c_index)]
text=value,
nouns=self.nouns,
subjs=self.subjs,
custom=self.custom,
selected_prominence_metric=self.agent_prominence_metric,
prominence_score_min=self.agent_prominence_score_min,
story_elements_df=self.story_elements_dict[str(c_index)]
)

if feature in self.search_features and (len(self.regexp_filter) > 0):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import unittest
import os

from storynavigation.widgets.OWSNActorAnalysis import OWSNActorAnalysis
Expand Down Expand Up @@ -37,7 +36,7 @@ def setUp(self):
def load(self):
self.logger.info("loading data...")
self.widget.corpus = Corpus.from_file(os.path.join(self.current_dir, constants.TEST_DATA_FILE_NAME))
self.send_signal(self.widget.Inputs.corpus, self.widget.corpus)
self.send_signal(self.widget.Inputs.stories, self.widget.corpus)
self.logger.info("loading completed.")

def test_tagging(self):
Expand All @@ -61,13 +60,13 @@ def test_tagging(self):

if len(value) > 0:
value = self.actortagger.postag_text(
value,
True,
True,
False,
{},
constants.SELECTED_PROMINENCE_METRIC,
0.0
text=value,
nouns=True,
subjs=True,
custom=False,
selected_prominence_metric=0,
prominence_score_min=constants.SELECTED_PROMINENCE_METRIC,
story_elements_df=None,
)
self.tagging_completed = True

Expand All @@ -89,6 +88,3 @@ def test_actor_metrics(self):
self.logger.info("metrics calculated.")
else:
self.logger.info("metrics could not be calculated.")

if __name__ == '__main__':
unittest.main()
38 changes: 0 additions & 38 deletions tox.ini

This file was deleted.

0 comments on commit 2577d93

Please sign in to comment.