aboutsummaryrefslogtreecommitdiff
path: root/backend/tests/enwiki
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2023-01-29 11:30:47 +1100
committerTerry Truong <terry06890@gmail.com>2023-01-29 11:30:47 +1100
commit8781fdb2b8c530a6c1531ae9e82221eb062e34fb (patch)
treeffd824aa9b945d69b47f012617ee13d98764d078 /backend/tests/enwiki
parentf5e87ae628bab0eef97b3e3e62f6d71cca9c99c0 (diff)
Adjust backend coding style
Add line spacing, section comments, and import consistency
Diffstat (limited to 'backend/tests/enwiki')
-rw-r--r--backend/tests/enwiki/test_download_img_license_info.py8
-rw-r--r--backend/tests/enwiki/test_download_imgs.py5
-rw-r--r--backend/tests/enwiki/test_gen_desc_data.py4
-rw-r--r--backend/tests/enwiki/test_gen_dump_index_db.py7
-rw-r--r--backend/tests/enwiki/test_gen_img_data.py9
-rw-r--r--backend/tests/enwiki/test_gen_pageview_data.py6
6 files changed, 33 insertions, 6 deletions
diff --git a/backend/tests/enwiki/test_download_img_license_info.py b/backend/tests/enwiki/test_download_img_license_info.py
index ed6e426..bd91478 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 tol_data.enwiki.download_img_license_info import downloadInfo
@@ -53,6 +54,7 @@ TEST_RESPONSE1 = {
}
}
}
+
TEST_RESPONSE2 = {
'batchcomplete': '',
'query': {
@@ -152,8 +154,10 @@ class TestDownloadInfo(unittest.TestCase):
(1, 'Octopus2.jpg'),
}
)
+
# Run
downloadInfo(imgDb)
+
# Check
self.assertEqual(
readTestDbTable(imgDb, 'SELECT name, license, artist, credit, restrictions, url from imgs'),
@@ -162,6 +166,7 @@ class TestDownloadInfo(unittest.TestCase):
'https://upload.wikimedia.org/wikipedia/commons/5/57/Octopus2.jpg'),
}
)
+
# Run with updated image-data db
createTestDbTable(
imgDb,
@@ -172,6 +177,7 @@ class TestDownloadInfo(unittest.TestCase):
}
)
downloadInfo(imgDb)
+
# Check
self.assertEqual(
readTestDbTable(imgDb, 'SELECT name, license, artist, credit, restrictions, url from imgs'),
diff --git a/backend/tests/enwiki/test_download_imgs.py b/backend/tests/enwiki/test_download_imgs.py
index 2618b8a..aaf27bc 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 tol_data.enwiki.download_imgs import downloadImgs
@@ -40,10 +41,12 @@ class TestDownloadInfo(unittest.TestCase):
('six','cc-by','','fred','','https://upload.wikimedia.org/6.png'),
}
)
+
# Create temp output directory
with tempfile.TemporaryDirectory() as outDir:
# Run
downloadImgs(imgDb, outDir, 0)
+
# Check
expectedImgs = {
'1.jpg': 'img:https://upload.wikimedia.org/1.jpg',
diff --git a/backend/tests/enwiki/test_gen_desc_data.py b/backend/tests/enwiki/test_gen_desc_data.py
index 801aa69..0d1536b 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 tol_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 e0715f3..b918f15 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 tol_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 1703b78..0a8f79d 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 tol_data.enwiki.gen_img_data import getInputPageIdsFromDb, genData
@@ -20,8 +21,10 @@ class TestGetInputPageIdsFromDb(unittest.TestCase):
('and another', 2),
}
)
+
# Run
pageIds = getInputPageIdsFromDb(dbFile)
+
# Check
self.assertEqual(pageIds, {1, 2})
@@ -40,9 +43,11 @@ class TestGenData(unittest.TestCase):
('Autism',25,0,-1),
}
)
+
# Run
imgDb = os.path.join(tempDir, 'imgData.db')
genData({10, 25}, TEST_DUMP_FILE, indexDb, imgDb)
+
# Check
self.assertEqual(
readTestDbTable(imgDb, 'SELECT page_id, img_name from page_imgs'),
@@ -51,8 +56,10 @@ class TestGenData(unittest.TestCase):
(25, 'Autism-stacking-cans 2nd edit.jpg'),
}
)
+
# Run with updated page-ids set
genData({13, 10}, TEST_DUMP_FILE, indexDb, imgDb)
+
# Check
self.assertEqual(
readTestDbTable(imgDb, 'SELECT page_id, img_name from page_imgs'),
diff --git a/backend/tests/enwiki/test_gen_pageview_data.py b/backend/tests/enwiki/test_gen_pageview_data.py
index 5002eb0..0c4a35e 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 tol_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'),