diff options
Diffstat (limited to 'backend/tests')
| -rw-r--r-- | backend/tests/common.py | 4 | ||||
| -rw-r--r-- | backend/tests/enwiki/test_download_img_license_info.py | 6 | ||||
| -rw-r--r-- | backend/tests/enwiki/test_download_imgs.py | 4 | ||||
| -rw-r--r-- | backend/tests/enwiki/test_gen_desc_data.py | 4 | ||||
| -rw-r--r-- | backend/tests/enwiki/test_gen_dump_index_db.py | 7 | ||||
| -rw-r--r-- | backend/tests/enwiki/test_gen_img_data.py | 7 | ||||
| -rw-r--r-- | backend/tests/enwiki/test_gen_pageview_data.py | 6 | ||||
| -rw-r--r-- | backend/tests/test_cal.py | 9 | ||||
| -rw-r--r-- | backend/tests/test_gen_desc_data.py | 5 | ||||
| -rw-r--r-- | backend/tests/test_gen_disp_data.py | 5 | ||||
| -rw-r--r-- | backend/tests/test_gen_events_data.py | 16 | ||||
| -rw-r--r-- | backend/tests/test_gen_imgs.py | 9 | ||||
| -rw-r--r-- | backend/tests/test_gen_picked_data.py | 10 | ||||
| -rw-r--r-- | backend/tests/test_gen_pop_data.py | 6 | ||||
| -rw-r--r-- | backend/tests/test_histplorer.py | 7 | ||||
| -rw-r--r-- | backend/tests/test_reduce_event_data.py | 141 |
16 files changed, 89 insertions, 157 deletions
diff --git a/backend/tests/common.py b/backend/tests/common.py index cb455e4..abfa471 100644 --- a/backend/tests/common.py +++ b/backend/tests/common.py @@ -3,7 +3,9 @@ Utilities for testing """ from typing import Any -import bz2, gzip, sqlite3 +import bz2 +import gzip +import sqlite3 def createTestFile(filename: str, content: str) -> None: """ Creates a file with the given name and contents """ diff --git a/backend/tests/enwiki/test_download_img_license_info.py b/backend/tests/enwiki/test_download_img_license_info.py index f285d55..ad6fa52 100644 --- a/backend/tests/enwiki/test_download_img_license_info.py +++ b/backend/tests/enwiki/test_download_img_license_info.py @@ -1,6 +1,7 @@ import unittest from unittest.mock import Mock, patch -import tempfile, os +import tempfile +import os from tests.common import createTestDbTable, readTestDbTable from hist_data.enwiki.download_img_license_info import downloadInfo @@ -53,6 +54,7 @@ TEST_RESPONSE1 = { } } } + TEST_RESPONSE2 = { 'batchcomplete': '', 'query': { @@ -152,6 +154,7 @@ class TestDownloadInfo(unittest.TestCase): (1, 'Octopus2.jpg'), } ) + # Run downloadInfo(imgDb) # Check @@ -162,6 +165,7 @@ class TestDownloadInfo(unittest.TestCase): 'https://upload.wikimedia.org/wikipedia/commons/5/57/Octopus2.jpg'), } ) + # Run with updated image-data db createTestDbTable( imgDb, diff --git a/backend/tests/enwiki/test_download_imgs.py b/backend/tests/enwiki/test_download_imgs.py index 823ac37..949d885 100644 --- a/backend/tests/enwiki/test_download_imgs.py +++ b/backend/tests/enwiki/test_download_imgs.py @@ -1,6 +1,7 @@ import unittest from unittest.mock import Mock, patch -import tempfile, os +import tempfile +import os from tests.common import readTestFile, createTestDbTable from hist_data.enwiki.download_imgs import downloadImgs @@ -40,6 +41,7 @@ class TestDownloadInfo(unittest.TestCase): (16, 'six','cc-by','','fred','','https://upload.wikimedia.org/6.png'), } ) + # Create temp output directory with tempfile.TemporaryDirectory() as outDir: # Run diff --git a/backend/tests/enwiki/test_gen_desc_data.py b/backend/tests/enwiki/test_gen_desc_data.py index f6d4250..e777a6a 100644 --- a/backend/tests/enwiki/test_gen_desc_data.py +++ b/backend/tests/enwiki/test_gen_desc_data.py @@ -1,5 +1,6 @@ import unittest -import os, tempfile +import os +import tempfile from tests.common import readTestDbTable from hist_data.enwiki.gen_desc_data import genData @@ -12,6 +13,7 @@ class TestGenData(unittest.TestCase): # Run dbFile = os.path.join(tempDir, 'descData.db') genData(TEST_DUMP_FILE, dbFile) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT id, title FROM pages'), diff --git a/backend/tests/enwiki/test_gen_dump_index_db.py b/backend/tests/enwiki/test_gen_dump_index_db.py index 64053c4..5281911 100644 --- a/backend/tests/enwiki/test_gen_dump_index_db.py +++ b/backend/tests/enwiki/test_gen_dump_index_db.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestBz2, readTestDbTable from hist_data.enwiki.gen_dump_index_db import genData @@ -10,15 +11,18 @@ def runGenData(indexFileContents: str): # Create temp index file indexFile = os.path.join(tempDir, 'index.txt.bz2') createTestBz2(indexFile, indexFileContents) + # Run dbFile = os.path.join(tempDir, 'data.db') genData(indexFile, dbFile) + # Read db return readTestDbTable(dbFile, 'SELECT title, id, offset, next_offset FROM offsets') class TestGenData(unittest.TestCase): def setUp(self): self.maxDiff = None # Remove output-diff size limit + def test_index_file(self): indexFileContents = ( '100:10:apple\n' @@ -33,6 +37,7 @@ class TestGenData(unittest.TestCase): ('banana ice-cream', 99, 300, 1000), ('Custard!', 2030, 1000, -1), }) + def test_emp_index(self): offsetsMap = runGenData('') self.assertEqual(offsetsMap, set()) diff --git a/backend/tests/enwiki/test_gen_img_data.py b/backend/tests/enwiki/test_gen_img_data.py index d18dddf..91ba481 100644 --- a/backend/tests/enwiki/test_gen_img_data.py +++ b/backend/tests/enwiki/test_gen_img_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestDbTable, readTestDbTable from hist_data.enwiki.gen_img_data import getInputPageIdsFromDb, genData @@ -24,6 +25,7 @@ class TestGetInputPageIdsFromDb(unittest.TestCase): (5, 'Marie Curie', 2403277, None, 2427622, None, 1, 'human'), } ) + # Create temp dump-index db indexDb = os.path.join(tempDir, 'dump_index.db') createTestDbTable( @@ -38,6 +40,7 @@ class TestGetInputPageIdsFromDb(unittest.TestCase): ('Autism',25,0,-1), } ) + # Run pageIds = getInputPageIdsFromDb(dbFile, indexDb) # Check @@ -58,6 +61,7 @@ class TestGenData(unittest.TestCase): ('Autism',25,0,-1), } ) + # Run imgDb = os.path.join(tempDir, 'imgData.db') genData({10, 25}, TEST_DUMP_FILE, indexDb, imgDb) @@ -69,6 +73,7 @@ class TestGenData(unittest.TestCase): (25, 'Autism', 'Autism-stacking-cans 2nd edit.jpg'), } ) + # Run with updated page-ids set genData({13, 10}, TEST_DUMP_FILE, indexDb, imgDb) # Check diff --git a/backend/tests/enwiki/test_gen_pageview_data.py b/backend/tests/enwiki/test_gen_pageview_data.py index 154953e..3209cce 100644 --- a/backend/tests/enwiki/test_gen_pageview_data.py +++ b/backend/tests/enwiki/test_gen_pageview_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestBz2, createTestDbTable, readTestDbTable from hist_data.enwiki.gen_pageview_data import genData @@ -18,6 +19,7 @@ class TestGenData(unittest.TestCase): 'fr.wikipedia Four null desktop 12 T6U6\n' 'en.wikipedia Three null desktop 10 E4G5Z61\n' )) + # Create temp dump-index db dumpIndexDb = os.path.join(tempDir, 'dump_index.db') createTestDbTable( @@ -31,9 +33,11 @@ class TestGenData(unittest.TestCase): ('Four', 4, 0, -1), } ) + # Run dbFile = os.path.join(tempDir, 'data.db') genData(pageviewFiles, dumpIndexDb, dbFile) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT title, id, views from views'), diff --git a/backend/tests/test_cal.py b/backend/tests/test_cal.py index 78b2c8b..9d481e7 100644 --- a/backend/tests/test_cal.py +++ b/backend/tests/test_cal.py @@ -10,30 +10,37 @@ class TestCal(unittest.TestCase): self.assertEqual(gregorianToJdn(2010, 11, 3), 2455504) self.assertEqual(gregorianToJdn(-4714, 11, 24), 0) self.assertEqual(gregorianToJdn(-1, 1, 1), 1721060) + def test_julian_to_jdn(self): self.assertEqual(julianToJdn(2010, 11, 3), 2455517) self.assertEqual(julianToJdn(-4713, 1, 1), 0) self.assertEqual(julianToJdn(-1, 1, 1), 1721058) + def test_jdn_to_gregorian(self): self.assertEqual(jdnToGregorian(2455504), (2010, 11, 3)) self.assertEqual(jdnToGregorian(0), (-4714, 11, 24)) self.assertEqual(jdnToGregorian(1721060), (-1, 1, 1)) + def test_jdn_to_julian(self): self.assertEqual(jdnToJulian(2455517), (2010, 11, 3)) self.assertEqual(jdnToJulian(0), (-4713, 1, 1)) self.assertEqual(jdnToJulian(1721058), (-1, 1, 1)) + def test_gregorian_to_julian(self): self.assertEqual(gregorianToJulian(2022, 9, 30), (2022, 9, 17)) self.assertEqual(gregorianToJulian(1616, 5, 3), (1616, 4, 23)) + def test_julian_to_gregorian(self): self.assertEqual(julianToGregorian(2022, 9, 17), (2022, 9, 30)) self.assertEqual(julianToGregorian(1616, 4, 23), (1616, 5, 3)) + def test_db_to_hist_date(self): - self.assertEqual(dbDateToHistDate(2001, 0), HistDate(True, 2001, 1, 1)) + self.assertEqual(dbDateToHistDate(2001, 0), HistDate(None, 2001, 1, 1)) self.assertEqual(dbDateToHistDate(1356438, 1), HistDate(True, -1000, 9, 13)) self.assertEqual(dbDateToHistDate(1721455, 2), HistDate(False, 1, 2, 1)) self.assertEqual(dbDateToHistDate(2268942, 3, False), HistDate(False, 1500, 1, 10)) self.assertEqual(dbDateToHistDate(2268933, 3, True), HistDate(True, 1500, 1, 10)) + def test_date_to_unit(self): self.assertEqual(dateToUnit(HistDate(None, 1914, 1, 1), 10), 191) self.assertEqual(dateToUnit(HistDate(True, 1500, 10, 5), MONTH_SCALE), 2269197) diff --git a/backend/tests/test_gen_desc_data.py b/backend/tests/test_gen_desc_data.py index 4c902ad..8fb6ce0 100644 --- a/backend/tests/test_gen_desc_data.py +++ b/backend/tests/test_gen_desc_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestDbTable, readTestDbTable from hist_data.gen_desc_data import genData @@ -39,6 +40,7 @@ class TestGenData(unittest.TestCase): (5, 'Five'), } ) + # Create temp history db dbFile = os.path.join(tempDir, 'data.db') createTestDbTable( @@ -53,6 +55,7 @@ class TestGenData(unittest.TestCase): (50, 'V', 5, 10, None, None, 2, 'human'), } ) + # Run genData(enwikiDb, dbFile) # Check diff --git a/backend/tests/test_gen_disp_data.py b/backend/tests/test_gen_disp_data.py index 0d54eb0..8fe13e4 100644 --- a/backend/tests/test_gen_disp_data.py +++ b/backend/tests/test_gen_disp_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestDbTable, readTestDbTable from hist_data.gen_disp_data import genData @@ -58,9 +59,11 @@ class TestGenData(unittest.TestCase): (7, 70), } ) + # Run genData(dbFile, [10, 1, MONTH_SCALE, DAY_SCALE], 2, False) genData(dbFile, [10, 1, MONTH_SCALE, DAY_SCALE], 2, True) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT * FROM events'), diff --git a/backend/tests/test_gen_events_data.py b/backend/tests/test_gen_events_data.py index a94bc89..9622dc2 100644 --- a/backend/tests/test_gen_events_data.py +++ b/backend/tests/test_gen_events_data.py @@ -1,6 +1,11 @@ import unittest -import tempfile, os, json, bz2, pickle, indexed_bzip2 -# Local imports +import tempfile +import os +import json +import bz2 +import pickle +import indexed_bzip2 + from tests.common import readTestDbTable from hist_data.gen_events_data import genData @@ -18,15 +23,18 @@ def runGenData(wikiItemArray: str, preGenOffsets: bool, nProcs: int): file.write(b',') file.write(b'\n') file.write(b']\n') + # Create temp offsets file if requested offsetsFile = os.path.join(tempDir, 'offsets.dat') if preGenOffsets: with indexed_bzip2.open(wikidataFile) as file: with open(offsetsFile, 'wb') as file2: pickle.dump(file.block_offsets(), file2) + # Run genData() dbFile = os.path.join(tempDir, 'events.db') genData(wikidataFile, offsetsFile, dbFile, nProcs) + # Read db return readTestDbTable(dbFile, 'SELECT * FROM events') @@ -164,15 +172,19 @@ class TestGenData(unittest.TestCase): (7, 'media two', -2199, -2100, None, None, 0, 'work'), (8, 'organism one', -400000000, -300000001, None, None, 0, 'organism'), } + def test_wikiItems(self): rows = runGenData(self.testWikiItems, False, 1) self.assertEqual(rows, self.expectedRows) + def test_empty_dump(self): rows = runGenData([{}], False, 1) self.assertEqual(rows, set()) + def test_multiprocessing(self): rows = runGenData(self.testWikiItems, False, 4) self.assertEqual(rows, self.expectedRows) + def test_existing_offsets(self): rows = runGenData(self.testWikiItems, True, 3) self.assertEqual(rows, self.expectedRows) diff --git a/backend/tests/test_gen_imgs.py b/backend/tests/test_gen_imgs.py index ea4bd70..893be5c 100644 --- a/backend/tests/test_gen_imgs.py +++ b/backend/tests/test_gen_imgs.py @@ -1,6 +1,8 @@ import unittest from unittest.mock import patch -import tempfile, os, shutil +import tempfile +import os +import shutil from tests.common import createTestDbTable, readTestDbTable from hist_data.gen_imgs import genImgs @@ -12,12 +14,14 @@ class TestGenImgs(unittest.TestCase): def test_gen(self, convertImageMock): with tempfile.TemporaryDirectory() as tempDir: convertImageMock.side_effect = lambda imgPath, outPath: shutil.copy(imgPath, outPath) + # Create temp images imgDir = os.path.join(tempDir, 'enwiki_imgs') os.mkdir(imgDir) shutil.copy(TEST_IMG, os.path.join(imgDir, '100.jpg')) shutil.copy(TEST_IMG, os.path.join(imgDir, '200.jpeg')) shutil.copy(TEST_IMG, os.path.join(imgDir, '400.png')) + # Create temp image db imgDb = os.path.join(tempDir, 'img_data.db') createTestDbTable( @@ -40,6 +44,7 @@ class TestGenImgs(unittest.TestCase): (200, 'two.jpeg', 'cc-by', 'author2', 'credits2', '', 'https://upload.wikimedia.org/two.jpeg'), } ) + # Create temp history db dbFile = os.path.join(tempDir, 'data.db') createTestDbTable( @@ -53,9 +58,11 @@ class TestGenImgs(unittest.TestCase): (30, 'third', 1, 20, 30, 40, 1, 'event'), } ) + # Run outDir = os.path.join(tempDir, 'imgs') genImgs(imgDir, imgDb, outDir, dbFile) + # Check self.assertEqual(set(os.listdir(outDir)), { '100.jpg', diff --git a/backend/tests/test_gen_picked_data.py b/backend/tests/test_gen_picked_data.py index ec1203b..e40c3c8 100644 --- a/backend/tests/test_gen_picked_data.py +++ b/backend/tests/test_gen_picked_data.py @@ -1,6 +1,8 @@ import unittest from unittest.mock import patch -import tempfile, os, shutil +import tempfile +import os +import shutil from tests.common import createTestFile, createTestDbTable, readTestDbTable from hist_data.gen_picked_data import genData @@ -12,6 +14,7 @@ class TestGenImgs(unittest.TestCase): def test_gen(self, convertImageMock): with tempfile.TemporaryDirectory() as tempDir: convertImageMock.side_effect = lambda imgPath, outPath: shutil.copy(imgPath, outPath) + # Create picked-event file pickedDir = os.path.join(tempDir, 'picked') os.mkdir(pickedDir) @@ -51,9 +54,11 @@ class TestGenImgs(unittest.TestCase): "title": "event three" }] ''') + # Create picked images shutil.copy(TEST_IMG, os.path.join(pickedDir, 'covid.jpg')) shutil.copy(TEST_IMG, os.path.join(pickedDir, 'foo.jpg')) + # Create temp history db dbFile = os.path.join(tempDir, 'data.db') createTestDbTable( @@ -126,12 +131,15 @@ class TestGenImgs(unittest.TestCase): (3, 1, 3), } ) + # Create existing event images imgOutDir = os.path.join(tempDir, 'imgs') os.mkdir(imgOutDir) shutil.copy(TEST_IMG, os.path.join(imgOutDir, '10.jpg')) + # Run genData(pickedDir, pickedEvtFile, dbFile, imgOutDir, [10, 1]) + # Check self.assertEqual(set(os.listdir(imgOutDir)), { '10.jpg', diff --git a/backend/tests/test_gen_pop_data.py b/backend/tests/test_gen_pop_data.py index 2f505f0..5080dd9 100644 --- a/backend/tests/test_gen_pop_data.py +++ b/backend/tests/test_gen_pop_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestDbTable, readTestDbTable from hist_data.gen_pop_data import genData @@ -19,6 +20,7 @@ class TestGenData(unittest.TestCase): ('three', 3, 30), } ) + # Create temp history db dbFile = os.path.join(tempDir, 'data.db') createTestDbTable( @@ -31,8 +33,10 @@ class TestGenData(unittest.TestCase): (33, 'three', 100, None, None, None, 0, 'event'), } ) + # Run genData(pageviewsDb, dbFile) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT id, pop from pop'), diff --git a/backend/tests/test_histplorer.py b/backend/tests/test_histplorer.py index 8f7e281..cd52c67 100644 --- a/backend/tests/test_histplorer.py +++ b/backend/tests/test_histplorer.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestDbTable from histplorer import handleReq, HistDate, Event, ImgInfo, EventInfo, SuggResponse @@ -105,8 +106,10 @@ class TestHandleReq(unittest.TestCase): self.tempDir = tempfile.TemporaryDirectory() self.dbFile = os.path.join(self.tempDir.name, 'data.db') initTestDb(self.dbFile) + def tearDown(self): self.tempDir.cleanup() + def test_events_req(self): response = handleReq(self.dbFile, {'QUERY_STRING': 'type=events&range=-1999.2002-11-1&scale=1&incl=3&limit=2'}) self.assertEqual(response.events, [ @@ -123,6 +126,7 @@ class TestHandleReq(unittest.TestCase): Event(1, 'event one', HistDate(None, 1900, 1, 1), None, None, None, 'event', 10, 11), ]) self.assertEqual(response.unitCounts, {-2000: 1, 1900: 2, 1990: 1}) + def test_info_req(self): response = handleReq(self.dbFile, {'QUERY_STRING': 'type=info&event=event%20three'}) self.assertEqual(response, @@ -136,6 +140,7 @@ class TestHandleReq(unittest.TestCase): Event(4, 'event four', HistDate(False, -2000, 10, 10), None, HistDate(False, 1, 10, 10), None, 'event', 20, 1000), 'desc four', 400, ImgInfo('example.com/2', 'cc-by', 'artist two', 'credits two'))) + def test_sugg_req(self): response = handleReq(self.dbFile, {'QUERY_STRING': 'type=sugg&input=event t'}) self.assertEqual(response, SuggResponse(['event two', 'event three'], False)) diff --git a/backend/tests/test_reduce_event_data.py b/backend/tests/test_reduce_event_data.py deleted file mode 100644 index 22fe204..0000000 --- a/backend/tests/test_reduce_event_data.py +++ /dev/null @@ -1,141 +0,0 @@ -import unittest -import tempfile, os - -from tests.common import createTestDbTable, readTestDbTable -from hist_data.reduce_event_data import reduceData -from hist_data.cal import gregorianToJdn, julianToJdn, MONTH_SCALE, DAY_SCALE - -class TestReduceData(unittest.TestCase): - def test_reduce(self): - with tempfile.TemporaryDirectory() as tempDir: - # Create temp history db - dbFile = os.path.join(tempDir, 'data.db') - createTestDbTable( - dbFile, - 'CREATE TABLE events (id INT PRIMARY KEY, title TEXT UNIQUE, ' \ - 'start INT, start_upper INT, end INT, end_upper INT, fmt INT, ctg TEXT)', - 'INSERT INTO events VALUES (?, ?, ?, ?, ?, ?, ?, ?)', - { - (1, 'event one', 1900, None, None, None, 0, 'event'), - (2, 'event two', 2452594, None, 2455369, None, 3, 'human'), # 2/11/2002 - (3, 'event three', 2448175, 2448200, None, None, 1, 'discovery'), # 10/10/1990 - (4, 'event four', 1900, None, None, None, 0, 'event'), # Copy of 1 - (5, 'event five', 2452595, None, 2455369, None, 3, 'human'), # Day after 2 - } - ) - createTestDbTable( - dbFile, - 'CREATE TABLE pop (id INT PRIMARY KEY, pop INT)', - 'INSERT INTO pop VALUES (?, ?)', - { - (1, 10), - (2, 20), - (3, 30), - (4, 40), - (5, 50), - } - ) - createTestDbTable( - dbFile, - 'CREATE TABLE dist (scale INT, unit INT, count INT, PRIMARY KEY (scale, unit))', - 'INSERT INTO dist VALUES (?, ?, ?)', - { - (1, 1900, 2), - (1, 1990, 1), - (1, 2002, 2), - (MONTH_SCALE, gregorianToJdn(1900, 1, 1), 2), - (MONTH_SCALE, gregorianToJdn(1990, 10, 1), 1), - (MONTH_SCALE, julianToJdn(2002, 11, 1), 2), - (DAY_SCALE, gregorianToJdn(1900, 1, 1), 2), - (DAY_SCALE, gregorianToJdn(1990, 10, 10), 1), - (DAY_SCALE, 2452594, 1), - (DAY_SCALE, 2452595, 1), - } - ) - createTestDbTable( - dbFile, - 'CREATE TABLE event_disp (id INT, scale INT, PRIMARY KEY (id, scale))', - 'INSERT INTO event_disp VALUES (?, ?)', - { - (1, 1), - (1, MONTH_SCALE), - (1, DAY_SCALE), - (2, 1), - (2, MONTH_SCALE), - (2, DAY_SCALE), - (3, 1), - (3, MONTH_SCALE), - (3, DAY_SCALE), - (4, 1), - (4, MONTH_SCALE), - (4, DAY_SCALE), - (5, 1), - (5, MONTH_SCALE), - (5, DAY_SCALE), - } - ) - createTestDbTable( - dbFile, - 'CREATE TABLE event_imgs (id INT PRIMARY KEY, img_id INT)', - 'INSERT INTO event_imgs VALUES (?, ?)', - { - (1, 11), - (2, 21), - } - ) - createTestDbTable( - dbFile, - 'CREATE TABLE images (id INT PRIMARY KEY, url TEXT, license TEXT, artist TEXT, credit TEXT)', - 'INSERT INTO images VALUES (?, ?, ?, ?, ?)', - { - (11, 'example.com/1', 'cc0', 'artist one', 'credits one'), - (21, 'example.com/1', 'cc0', 'artist two', 'credits two'), - } - ) - createTestDbTable( - dbFile, - 'CREATE TABLE descs (id INT PRIMARY KEY, wiki_id INT, desc TEXT)', - 'INSERT INTO descs VALUES (?, ?, ?)', - { - (1, 100, 'desc one'), - } - ) - # Run - reduceData(dbFile, [1, MONTH_SCALE, DAY_SCALE]) - # Check - self.assertEqual( - readTestDbTable(dbFile, 'SELECT * FROM events'), - { - (1, 'event one', 1900, None, None, None, 0, 'event'), - (2, 'event two', 2452594, None, 2455369, None, 3, 'human'), - } - ) - self.assertEqual( - readTestDbTable(dbFile, 'SELECT * from pop'), - { - (1, 10), - (2, 20), - } - ) - self.assertEqual( - readTestDbTable(dbFile, 'SELECT * from dist'), - { - (1, 1900, 1), - (1, 2002, 1), - (MONTH_SCALE, gregorianToJdn(1900, 1, 1), 1), - (MONTH_SCALE, julianToJdn(2002, 11, 1), 1), - (DAY_SCALE, gregorianToJdn(1900, 1, 1), 1), - (DAY_SCALE, 2452594, 1), - } - ) - self.assertEqual( - readTestDbTable(dbFile, 'SELECT * from event_disp'), - { - (1, 1), - (1, MONTH_SCALE), - (1, DAY_SCALE), - (2, 1), - (2, MONTH_SCALE), - (2, DAY_SCALE), - } - ) |
