Skip to content

Commit a61737b

Browse files
authored
Merge branch 'MinoMino:master' into master
2 parents dd99e58 + 3fabae3 commit a61737b

27 files changed

Lines changed: 1449 additions & 75 deletions

.github/workflows/pre-commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: actions/setup-python@v2
1717
- name: Get python version
1818
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
19-
- uses: actions/cache@v1
19+
- uses: actions/cache@v4
2020
with:
2121
path: ~/.cache/pre-commit
2222
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
pull_request:
8+
branches:
9+
- "master"
10+
11+
jobs:
12+
ubuntu:
13+
uses: ./.github/workflows/test-ubuntu.yml
14+
pypa_ubuntu:
15+
uses: ./.github/workflows/test-pypa-ubuntu.yml
16+
with_docker:
17+
uses: ./.github/workflows/test-with-docker.yml
18+
upload-to-codecov:
19+
needs: [pypa_ubuntu, with_docker, ubuntu]
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
- name: Download artifacts
25+
uses: actions/download-artifact@v4
26+
- name: Upload to Codecov
27+
uses: codecov/codecov-action@v4
28+
with:
29+
token: ${{ secrets.CODECOV_TOKEN }}
Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
name: Tests (PyPA packages)
22

3-
on:
4-
push:
5-
branches:
6-
- "master"
7-
pull_request:
8-
branches:
9-
- "master"
3+
on: [workflow_call]
104

115
jobs:
126
test:
@@ -25,18 +19,16 @@ jobs:
2519
os: "ubuntu-22.04"
2620
- python-version: "3.7"
2721
os: "ubuntu-22.04"
28-
- python-version: "3.6"
29-
os: "ubuntu-20.04"
30-
- python-version: "3.5"
31-
os: "ubuntu-20.04"
3222

3323
runs-on: ${{ matrix.os }}
3424
env:
35-
GET_PIP_PATH_PREFIX: ${{ contains(fromJSON('["3.7", "3.6", "3.5"]'), matrix.python-version) && format('pip/{0}/', matrix.python-version) || '' }}
25+
GET_PIP_PATH_PREFIX: ${{ contains(fromJSON('["3.7", "3.8"]'), matrix.python-version) && format('pip/{0}/', matrix.python-version) || '' }}
3626
steps:
3727
- uses: actions/checkout@v3
3828
with:
3929
submodules: 'true'
30+
- name: Set up Redis server
31+
run: sudo apt-get install redis
4032
- name: Include ppa repository
4133
run: sudo add-apt-repository ppa:deadsnakes/ppa
4234

@@ -47,7 +39,7 @@ jobs:
4739
sudo update-alternatives --install /usr/bin/python3-config python3-config `which python${{ matrix.python-version }}-config` 1
4840
4941
- name: Install disutils package
50-
if: contains(fromJSON('["3.5"]'), matrix.python-version) == false
42+
if: contains(fromJSON('["3.7", "3.8", "3.9", "3.10", "3.11"]'), matrix.python-version)
5143
run: sudo apt-get install python${{ matrix.python-version }}-distutils
5244

5345
- name: Download get-pip.py
@@ -56,16 +48,26 @@ jobs:
5648
- name: Install pip
5749
run: python3 get-pip.py
5850

59-
# TODO: try to remove this after unpining redis
60-
- name: Install setuptools
61-
if: contains(fromJSON('["3.12"]'), matrix.python-version)
62-
run: python3 get-pip.py "setuptools"
63-
6451
- name: Install requirements
6552
run: python3 -m pip install -r requirements.txt
6653

54+
- name: Create symlinks for testing
55+
run: |
56+
ln -s tests/_minqlx.py
57+
ln -s tests/minqlx_plugin_test
58+
ln -s tests/minqlx-repo/python/minqlx
59+
6760
- name: Install requirements for testing
68-
run: python3 -m pip install mockito
61+
run: python3 -m pip install mockito coverage
6962

7063
- name: Run tests
71-
run: python3 -m unittest tests
64+
run: coverage run -m unittest tests
65+
66+
- name: Make coverage report
67+
run: coverage xml
68+
69+
- name: Upload coverage report as artifact
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: coverage - pypa - ubuntu - ${{ matrix.python-version }}.xml
73+
path: coverage.xml

.github/workflows/test-ubuntu.yml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
name: Tests (Ubuntu packages)
22

3-
on:
4-
push:
5-
branches:
6-
- "master"
7-
pull_request:
8-
branches:
9-
- "master"
3+
on: [workflow_call]
104

115
jobs:
126
test:
137
strategy:
148
matrix:
15-
os: ["ubuntu-24.04", "ubuntu-22.04", "ubuntu-20.04"]
9+
os: ["ubuntu-24.04", "ubuntu-22.04"]
1610

1711
runs-on: ${{ matrix.os }}
1812
steps:
1913
- uses: actions/checkout@v3
2014
with:
2115
submodules: 'true'
16+
- name: Set up Redis server
17+
run: sudo apt-get update && sudo apt-get install redis
2218
- name: Set up Python
2319
run: sudo apt-get install python3
2420
- name: Install requirements
2521
run: sudo apt-get install python3-redis python3-hiredis python3-requests python3-zmq
26-
- name: Install requirements for testing (from PyPA)
27-
if: matrix.os == 'ubuntu-20.04'
28-
run: python3 -m pip install mockito
29-
- name: Install requirements for testing (from Ubuntu packages)
30-
if: matrix.os != 'ubuntu-20.04'
31-
run: sudo apt-get install python3-mockito
22+
- name: Install requirements for testing
23+
run: sudo apt-get install python3-mockito python3-coverage
24+
- name: Create symlinks for testing
25+
run: |
26+
ln -s tests/_minqlx.py
27+
ln -s tests/minqlx_plugin_test
28+
ln -s tests/minqlx-repo/python/minqlx
3229
- name: Run tests
33-
run: python3 -m unittest tests
30+
run: python3-coverage run -m unittest tests
31+
32+
- name: Make coverage report
33+
run: python3-coverage xml
34+
35+
- name: Upload coverage report as artifact
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: coverage - apt - ubuntu - ${{ matrix.os }}.xml
39+
path: coverage.xml
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Tests (using Docker)
2+
3+
on: [workflow_call]
4+
5+
jobs:
6+
test:
7+
strategy:
8+
matrix:
9+
dockerfile-suffix: [
10+
"python35", "python36",
11+
]
12+
force-redis-package-version: [
13+
"", "==2.10",
14+
]
15+
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
submodules: 'true'
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
- name: Build image
25+
uses: docker/build-push-action@v5
26+
with:
27+
context: .
28+
file: ./tests/dockerfiles/Dockerfile.${{ matrix.dockerfile-suffix }}
29+
push: false
30+
load: true
31+
tags: test:latest
32+
build-args: FORCE_REDIS_PACKAGE_VERSION=${{ matrix.force-redis-package-version }}
33+
34+
- name: Test
35+
run: |
36+
mkdir output
37+
docker run --rm --mount type=bind,src=./output,dst=/output test:latest
38+
39+
- name: Upload coverage report as artifact
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: coverage - docker - ${{ matrix.dockerfile-suffix }} - ${{ matrix.force-redis-package-version }}.xml
43+
path: ./output/coverage.xml

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
*.pyc
22
test.py
3+
_minqlx.py
4+
minqlx_plugin_test
5+
minqlx

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "tests/minqlx-plugin-tests"]
2-
path = tests/minqlx-plugin-tests
3-
url = https://github.com/mgaertne/minqlx-plugin-tests.git
1+
[submodule "minqlx"]
2+
path = tests/minqlx-repo
3+
url = https://github.com/MinoMino/minqlx.git

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ repos:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
8+
exclude: tests/minqlx_plugin_test

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ To install requirements for unit testing:
105105
```
106106
git submodule init
107107
git submodule update --recursive
108+
ln -s tests/_minqlx.py
109+
ln -s tests/minqlx_plugin_test
110+
ln -s tests/minqlx-repo/python/minqlx
108111
python3 -m pip install mockito
109112
```
110113

ban.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import datetime
2121
import time
2222
import re
23+
import redis
2324

2425
LENGTH_REGEX = re.compile(r"(?P<number>[0-9]+) (?P<scale>seconds?|minutes?|hours?|days?|weeks?|months?|years?)")
2526
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
@@ -199,7 +200,11 @@ def cmd_ban(self, player, msg, channel):
199200
base_key = PLAYER_KEY.format(ident) + ":bans"
200201
ban_id = self.db.zcard(base_key)
201202
db = self.db.pipeline()
202-
db.zadd(base_key, time.time() + td.total_seconds(), ban_id)
203+
ban_time = time.time() + td.total_seconds()
204+
if redis.VERSION < (3,):
205+
db.zadd(base_key, ban_time, ban_id)
206+
else:
207+
db.zadd(base_key, {ban_id: ban_time})
203208
ban = {"expires": expires, "reason": reason, "issued": now, "issued_by": player.steam_id}
204209
db.hmset(base_key + ":{}".format(ban_id), ban)
205210
db.execute()
@@ -239,7 +244,10 @@ def cmd_unban(self, player, msg, channel):
239244
else:
240245
db = self.db.pipeline()
241246
for ban_id, score in bans:
242-
db.zincrby(base_key, ban_id, -score)
247+
if redis.VERSION < (3,):
248+
db.zincrby(base_key, ban_id, -score)
249+
else:
250+
db.zincrby(base_key, -score, ban_id)
243251
db.execute()
244252
channel.reply("^6{}^7 has been unbanned.".format(name))
245253

0 commit comments

Comments
 (0)