Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
- Updated README.md
- Adjusted tests
  • Loading branch information
sakan811 committed Jun 19, 2024
1 parent fdb0f10 commit 46caa73
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
- name: Test with pytest
run: |
python -m pytest test.py
python -m pytest tests
37 changes: 12 additions & 25 deletions test.py → tests/test_clean_number.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -19,13 +12,17 @@ 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)
# Convert numbers to integers
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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -63,28 +66,12 @@ 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)

if match:
# 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__])
25 changes: 25 additions & 0 deletions tests/test_scraper.py
Original file line number Diff line number Diff line change
@@ -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__])

0 comments on commit 46caa73

Please sign in to comment.