diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 61cf672..317d2d8 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -44,4 +44,4 @@ jobs: - name: Test with pytest run: | - python -m pytest test.py + python -m pytest tests diff --git a/test.py b/tests/test_clean_number.py similarity index 75% rename from test.py rename to tests/test_clean_number.py index f22a8b0..670b4be 100644 --- a/test.py +++ b/tests/test_clean_number.py @@ -1,11 +1,4 @@ import re -import sqlite3 - -import pytest - -from tekken8_scraper.jun_kazama_scraper import JunKazamaScraper -from tekken8_scraper.migrate_to_sqlite import migrate_to_sqlite -from tekken8_scraper.transform_data import clean_data def test_clean_numbers(): @@ -19,6 +12,8 @@ def test_clean_numbers(): assert sum(numbers) == 29 assert sum(numbers) / len(numbers) == 14.5 + +def test_clean_num2(): input_str = '-6 (high blocked)' # Extract numeric values using regular expressions numbers = re.findall(r'-?\d+', input_str) @@ -26,6 +21,8 @@ def test_clean_numbers(): numbers = [int(num) for num in numbers] assert numbers[0] == -6 + +def test_clean_num3(): input_str = "+21a~+64a (-5~+38)" # Extract numeric values using regular expressions numbers = re.findall(r'-?\d+', input_str) @@ -38,6 +35,8 @@ def test_clean_numbers(): assert sum(numbers) == 118 assert sum(numbers) / len(numbers) == 29.5 + +def test_clean_num4(): input_str = ",i27~28" # Extract numeric values using regular expressions numbers = re.findall(r'-?\d+', input_str) @@ -46,6 +45,8 @@ def test_clean_numbers(): assert sum(numbers) == 55 assert sum(numbers) / len(numbers) == 27.5 + +def clean_num5(): input_str = "7,9,12,21" # Extract numbers using regular expressions numbers = re.findall(r'-?\d+', input_str) @@ -54,6 +55,8 @@ def test_clean_numbers(): assert sum(numbers) == 49 assert sum(numbers) / len(numbers) == 12.25 + +def test_clean_num6(): input_str = "-6~+37g" # Extract numbers using regular expressions numbers = re.findall(r'-?\d+', input_str) @@ -63,6 +66,8 @@ def test_clean_numbers(): assert numbers[1] == 37 assert sum(numbers) == 31 + +def test_clean_num7(): input_str = "-6~+37g" match = re.search(r'-?\d+', input_str) @@ -70,21 +75,3 @@ def test_clean_numbers(): # Convert the first found number to an integer number = int(match.group(0)) assert number == -6 - - -def test_full_process(): - jks = JunKazamaScraper() - jun_data = jks.start_jun_scraper() - jun_data_cleaned = clean_data(jun_data) - sqlite_db = 'jun_kazama_test.db' - migrate_to_sqlite(jun_data_cleaned, sqlite_db) - - with sqlite3.connect(sqlite_db) as conn: - cursor = conn.cursor() - cursor.execute('SELECT * FROM JunKazamaData') - data = cursor.fetchall() - assert len(data) > 0 - - -if __name__ == '__main__': - pytest.main([__file__]) diff --git a/tests/test_scraper.py b/tests/test_scraper.py new file mode 100644 index 0000000..3a2dc30 --- /dev/null +++ b/tests/test_scraper.py @@ -0,0 +1,25 @@ +import sqlite3 + +import pytest + +from tekken8_scraper.jun_kazama_scraper import JunKazamaScraper +from tekken8_scraper.migrate_to_sqlite import migrate_to_sqlite +from tekken8_scraper.transform_data import clean_data + + +def test_full_process(): + jks = JunKazamaScraper() + jun_data = jks.start_jun_scraper() + jun_data_cleaned = clean_data(jun_data) + sqlite_db = 'jun_kazama_test.db' + migrate_to_sqlite(jun_data_cleaned, sqlite_db) + + with sqlite3.connect(sqlite_db) as conn: + cursor = conn.cursor() + cursor.execute('SELECT * FROM JunKazamaData') + data = cursor.fetchall() + assert len(data) > 0 + + +if __name__ == '__main__': + pytest.main([__file__])