Skip to content

Commit

Permalink
Fix tests to run as submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
dh3968mlq committed Dec 31, 2023
1 parent afc4f11 commit 26de184
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
12 changes: 10 additions & 2 deletions tests/test_hdtimeline.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import sys
import glob
sys.path.insert(0,".") # For Github
sys.path.insert(0,"./hdtimelines") # in case this is run when a submodule

from hdtimelines import hdtimeline

def test_hdtimeline():
# Find test data path
if glob.glob('./hdtimelines/test_data/'):
path = './hdtimelines/test_data'
else:
path = './test_data'

hd = hdtimeline.hdTimeLine("Test timeline")
hd.add_topic_csv('Monarchs extract','./test_data/British Monarchs_extract_ok.csv')
hd.add_topic_csv('Monarchs extract',f'{path}/British Monarchs_extract_ok.csv')
daterange = hd.get_date_range()

assert hd.title == "Test timeline"
Expand All @@ -21,7 +29,7 @@ def test_hdtimeline():
'url': 'https://en.wikipedia.org/wiki/William_the_Conqueror'}
assert hd.topics[0].events[0] == dtest

hd.add_topic_csv('Playwrights extract','./test_data/Playwrights_extract_ok.csv')
hd.add_topic_csv('Playwrights extract',f'{path}/Playwrights_extract_ok.csv')
hd.move_topic(id=1, indexshift=1) # Move Monarchs down
assert [topic.id for topic in hd.topics] == [2, 1]

Expand Down
1 change: 1 addition & 0 deletions tests/test_pltimeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
sys.path.insert(0,".") # For Github
sys.path.insert(0,"./hdtimelines") # in case this is run when a submodule

from hdtimelines import pltimeline
from historicaldate import hdateutils
Expand Down
14 changes: 11 additions & 3 deletions tests/test_pltutils.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import sys
sys.path.insert(0,".") # For Github
sys.path.insert(0,"./hdtimelines") # in case this is run when a submodule

import glob
from hdtimelines import pltutils
import pandas as pd

def test_check_dataframe():
df = pd.read_csv('./test_data/Playwrights_extract_ok.csv', na_filter=False)
# Find test data path
if glob.glob('./hdtimelines/test_data/'):
path = './hdtimelines/test_data'
else:
path = './test_data'

df = pd.read_csv(f'{path}/Playwrights_extract_ok.csv', na_filter=False)
result, message = pltutils.check_dataframe(df)
assert result

df = pd.read_csv('./test_data/British Monarchs_extract_ok.csv', na_filter=False)
df = pd.read_csv(f'{path}/British Monarchs_extract_ok.csv', na_filter=False)
result, message = pltutils.check_dataframe(df)
assert result

assert pltutils.check_dataframe(df)
df = pd.read_csv('./test_data/British Monarchs_extract_notok_no_label.csv', na_filter=False)
df = pd.read_csv(f'{path}/British Monarchs_extract_notok_no_label.csv', na_filter=False)
result, message = pltutils.check_dataframe(df)
assert not result
assert message == "Error: KeyError('label')"
Expand Down

0 comments on commit 26de184

Please sign in to comment.