Skip to content

Commit

Permalink
Prefer using tests from CPython
Browse files Browse the repository at this point in the history
  • Loading branch information
ktnlvr committed Jun 4, 2023
1 parent 1acfffa commit b928b4e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install flake8
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install self
run: |
Expand All @@ -34,4 +34,4 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
python -m pystd
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ext/cpython"]
path = ext/cpython
url = https://github.com/python/cpython.git
1 change: 1 addition & 0 deletions ext/cpython
Submodule cpython added at ce558e
25 changes: 25 additions & 0 deletions pystd/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
import unittest
import importlib.util
from typing import List
from unittest import TestSuite, TextTestRunner

from . import random


def load_cpython_tests() -> List[TestSuite]:
spec = importlib.util.spec_from_file_location(
"test_random", "ext/cpython/Lib/test/test_random.py"
)
test_random = importlib.util.module_from_spec(spec)
spec.loader.exec_module(test_random)
suite = unittest.defaultTestLoader.loadTestsFromModule(test_random)
return [suite]


sys.modules["random"] = random

if __name__ == "__main__":
suits = load_cpython_tests()
for suit in suits:
TextTestRunner(verbosity=2).run(suit)
11 changes: 11 additions & 0 deletions pystd/random.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Sequence
import time

_seed = 4


Expand Down Expand Up @@ -61,3 +62,13 @@ def shuffle(seq: Sequence) -> object:

def sample(population, k, *, counts=None):
...


class Random:
def __init__(seed):
...


class SystemRandom:
def random(self):
return random()
2 changes: 0 additions & 2 deletions tests/test_always_pass.py

This file was deleted.

37 changes: 0 additions & 37 deletions tests/test_random.py

This file was deleted.

0 comments on commit b928b4e

Please sign in to comment.