Spaces:
Sleeping
Sleeping
AttackingOrDefending commited on
Commit ·
8374797
1
Parent(s): fc6e666
Test bot update (#21)
Browse files- .github/workflows/lishogi-bot-build.yml +1 -1
- tests.py +29 -22
.github/workflows/lishogi-bot-build.yml
CHANGED
|
@@ -27,4 +27,4 @@ jobs:
|
|
| 27 |
pip install -r requirements.txt
|
| 28 |
- name: Test with pytest
|
| 29 |
run: |
|
| 30 |
-
pytest tests.py -s
|
|
|
|
| 27 |
pip install -r requirements.txt
|
| 28 |
- name: Test with pytest
|
| 29 |
run: |
|
| 30 |
+
pytest tests.py -s
|
tests.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import pytest
|
|
|
|
| 2 |
import requests
|
| 3 |
import time
|
| 4 |
import yaml
|
| 5 |
-
from shutil import copyfile
|
| 6 |
import importlib
|
| 7 |
lishogi_bot = importlib.import_module("lishogi-bot")
|
| 8 |
|
|
@@ -39,28 +39,35 @@ def run_bot(CONFIG, logging_level):
|
|
| 39 |
except:
|
| 40 |
pass
|
| 41 |
time.sleep(2)
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
try:
|
| 49 |
-
li.abort(game)
|
| 50 |
-
except:
|
| 51 |
-
pass
|
| 52 |
time.sleep(2)
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
else:
|
| 65 |
lishogi_bot.logger.error("{} is not a bot account. Please upgrade it to a bot account!".format(user_profile["username"]))
|
| 66 |
games = li.get_ongoing_games()
|
|
|
|
| 1 |
import pytest
|
| 2 |
+
import pytest_timeout
|
| 3 |
import requests
|
| 4 |
import time
|
| 5 |
import yaml
|
|
|
|
| 6 |
import importlib
|
| 7 |
lishogi_bot = importlib.import_module("lishogi-bot")
|
| 8 |
|
|
|
|
| 39 |
except:
|
| 40 |
pass
|
| 41 |
time.sleep(2)
|
| 42 |
+
while li.get_ongoing_games():
|
| 43 |
+
time.sleep(60)
|
| 44 |
+
|
| 45 |
+
@pytest.mark.timeout(300)
|
| 46 |
+
def run_test():
|
| 47 |
+
game_id = li.challenge_ai()['id']
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
time.sleep(2)
|
| 49 |
+
games = li.get_ongoing_games()
|
| 50 |
+
game_ids = list(map(lambda game: game['gameId'], games))
|
| 51 |
+
for game in game_ids:
|
| 52 |
+
if game != game_id:
|
| 53 |
+
try:
|
| 54 |
+
li.abort(game)
|
| 55 |
+
except:
|
| 56 |
+
pass
|
| 57 |
+
time.sleep(2)
|
| 58 |
+
lishogi_bot.start(li, user_profile, engine_factory, CONFIG, logging_level, None, one_game=True)
|
| 59 |
+
response = requests.get('https://lishogi.org/game/export/{}'.format(game_id))
|
| 60 |
+
response = response.text
|
| 61 |
+
response = response.lower()
|
| 62 |
+
response = response.split('\n')
|
| 63 |
+
result = list(filter(lambda line: 'result' in line, response))
|
| 64 |
+
result = result[0][9:-2]
|
| 65 |
+
color = list(filter(lambda line: 'sente' in line, response))
|
| 66 |
+
color = 'w' if username.lower() in color[0] else 'b'
|
| 67 |
+
win = result == '1-0' and color == 'w' or result == '0-1' and color == 'b'
|
| 68 |
+
assert win
|
| 69 |
+
|
| 70 |
+
run_test()
|
| 71 |
else:
|
| 72 |
lishogi_bot.logger.error("{} is not a bot account. Please upgrade it to a bot account!".format(user_profile["username"]))
|
| 73 |
games = li.get_ongoing_games()
|