Skip to content

Commit

Permalink
Merge pull request #1102 from Santhosh-Siddhardha/main
Browse files Browse the repository at this point in the history
Added test file for lichess module
  • Loading branch information
nikhil25803 authored Jun 6, 2024
2 parents 67b42dd + b0e4262 commit 0c5e0bc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/scrape_up/steam/steamScraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ def _scrape_page(self, url, filter, n0Games):
if len(all_game_info) >= n0Games:
break
except requests.RequestException as e:

break
return all_game_info

Expand Down
62 changes: 62 additions & 0 deletions src/test/lichess_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import unittest
from scrape_up.lichess import LichessGames


class TestLichessGames(unittest.TestCase):
"""
| Methods | Details |
| ----------------------------- | -------------------------------------------------------------------------- |
| `.fetch_games()` | Fetch all the games data for the specified username. |
"""

def setUp(self):
"""
Initialize a LichessGames instance before each test method.
"""
self.username = "chess_player" # Example username
self.lichess_scraper = LichessGames(username=self.username)

def test_fetch_games(self):
"""
Test the fetch_games() method.
"""
try:
games = self.lichess_scraper.fetch_games()

# Check if games is a list of dictionaries
self.assertIsInstance(games, list)
for game in games:
self.assertIsInstance(game, dict)
self.assertIn("white_player", game)
self.assertIn("black_player", game)
self.assertIn("pgn", game)

white_player = game["white_player"]
black_player = game["black_player"]

self.assertIn("username", white_player)
self.assertIn("before_game_score", white_player)
self.assertIn("score_change", white_player)

self.assertIn("username", black_player)
self.assertIn("before_game_score", black_player)
self.assertIn("score_change", black_player)
except:
return None

def test_fetch_games_empty(self):
"""
Test fetch_games() method with a username that has no games.
"""
try:
self.lichess_scraper = LichessGames(username="non_existent_user")
games = self.lichess_scraper.fetch_games()
self.assertEqual(
games, [], "Expected an empty list for a non-existent user"
)
except:
return None


if __name__ == "__main__":
unittest.main()
3 changes: 0 additions & 3 deletions src/test/quora_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def setUp(self):

def test_fetch_answers(self):
try:

expected_answers = ["Accepted answer 1", "Suggested answer 1"]

self.assertEqual(
Expand All @@ -21,7 +20,6 @@ def test_fetch_answers(self):

def test_get_by_query(self):
try:

expected_answer = "Suggested answer 1"

self.assertEqual(
Expand All @@ -33,7 +31,6 @@ def test_get_by_query(self):

def test_profile_details(self):
try:

expected_profile = {
"name": "Nikhil Raj",
"url": "https://www.quora.com/profile/Nikhil-Raj",
Expand Down
2 changes: 0 additions & 2 deletions src/test/swiggy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def setUp(self):

def test_get_restraunt_details(self):
try:

expected_data = {
"name": "Pizza Hut",
"cuisine": "Pizzas",
Expand All @@ -38,7 +37,6 @@ def test_get_restraunt_details(self):

def test_get_restaurants(self):
try:

expected_restaurants = [
{
"Name": "Domino's Pizza",
Expand Down

0 comments on commit 0c5e0bc

Please sign in to comment.