Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add tests to prevent regression #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Test
on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Test
run: python -m unittest
7 changes: 7 additions & 0 deletions gen-fixture.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
# ./gen-fixture.sh tests/fixtures/example.py
# ./gen-fixture.sh tests/fixtures/example.py expected
# ./gen-fixture.sh tests/fixtures/example.py sample
# for f in $(ls tests/fixtures/*.py); do ./gen-fixture.sh "$f"; done

PYTHONPATH=./ python "$1" > "${1%.py}.${2:-expected}.txt"
Empty file added tests/__init__.py
Empty file.
76 changes: 76 additions & 0 deletions tests/fixtures/expect_error_sample.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

<DESCRIBE::>expect_error, new version

<IT::>f0 raises nothing

<FAILED::>f0 did not raise any exception

<FAILED::>f0 did not raise Exception

<FAILED::>f0 did not raise ArithmeticError

<FAILED::>f0 did not raise ZeroDivisionError

<FAILED::>f0 did not raise LookupError

<FAILED::>f0 did not raise KeyError

<FAILED::>f0 did not raise OSError

<COMPLETEDIN::>0.03

<IT::>f1 raises Exception

<PASSED::>Test Passed

<PASSED::>Test Passed

<FAILED::>f1 did not raise ArithmeticError

<FAILED::>f1 did not raise ZeroDivisionError

<FAILED::>f1 did not raise LookupError

<FAILED::>f1 did not raise KeyError

<FAILED::>f1 did not raise OSError

<COMPLETEDIN::>0.02

<IT::>f2 raises Exception >> ArithmeticError >> ZeroDivisionError

<PASSED::>Test Passed

<PASSED::>Test Passed

<PASSED::>Test Passed

<PASSED::>Test Passed

<FAILED::>f2 did not raise LookupError

<FAILED::>f2 did not raise KeyError

<FAILED::>f2 did not raise OSError

<COMPLETEDIN::>0.02

<IT::>f3 raises Exception >> LookupError >> KeyError

<PASSED::>Test Passed

<PASSED::>Test Passed

<FAILED::>f3 did not raise ArithmeticError

<FAILED::>f3 did not raise ZeroDivisionError

<PASSED::>Test Passed

<PASSED::>Test Passed

<FAILED::>f3 did not raise OSError

<COMPLETEDIN::>0.02

<COMPLETEDIN::>0.11
60 changes: 60 additions & 0 deletions tests/fixtures/expect_error_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# https://www.codewars.com/kumite/5ab735bee7093b17b2000084?sel=5ab735bee7093b17b2000084
import codewars_test as test


def f0():
pass


# BaseException >> Exception
def f1():
raise Exception()


# BaseException >> Exception >> ArithmeticError >> ZeroDivisionError
def f2():
return 1 // 0


# BaseException >> Exception >> LookupError >> KeyError
def f3():
return {}[1]


excn = (
"Exception",
"ArithmeticError",
"ZeroDivisionError",
"LookupError",
"KeyError",
"OSError",
)
exc = (Exception, ArithmeticError, ZeroDivisionError, LookupError, KeyError, OSError)


@test.describe("expect_error, new version")
def d2():
@test.it("f0 raises nothing")
def i0():
test.expect_error("f0 did not raise any exception", f0)
for i in range(6):
test.expect_error("f0 did not raise {}".format(excn[i]), f0, exc[i])

@test.it("f1 raises Exception")
def i1():
test.expect_error("f1 did not raise Exception", f1)
for i in range(6):
test.expect_error("f1 did not raise {}".format(excn[i]), f1, exc[i])

@test.it("f2 raises Exception >> ArithmeticError >> ZeroDivisionError")
def i2():
test.expect_error("f2 did not raise Exception", f2)
for i in range(6):
test.expect_error("f2 did not raise {}".format(excn[i]), f2, exc[i])

@test.it("f3 raises Exception >> LookupError >> KeyError")
def i3():
test.expect_error("f3 did not raise Exception", f3)
for i in range(6):
test.expect_error("f3 did not raise {}".format(excn[i]), f3, exc[i])

20 changes: 20 additions & 0 deletions tests/fixtures/multiple_groups.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

<DESCRIBE::>group 1

<IT::>test 1

<FAILED::>1 should equal 2

<COMPLETEDIN::>0.01

<COMPLETEDIN::>0.02

<DESCRIBE::>group 2

<IT::>test 1

<FAILED::>1 should equal 2

<COMPLETEDIN::>0.00

<COMPLETEDIN::>0.01
15 changes: 15 additions & 0 deletions tests/fixtures/multiple_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import codewars_test as test


@test.describe("group 1")
def group_1():
@test.it("test 1")
def test_1():
test.assert_equals(1, 2)


@test.describe("group 2")
def group_2():
@test.it("test 1")
def test_1():
test.assert_equals(1, 2)
14 changes: 14 additions & 0 deletions tests/fixtures/nested_groups.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

<DESCRIBE::>group 1

<DESCRIBE::>group 1 1

<IT::>test 1

<FAILED::>1 should equal 2

<COMPLETEDIN::>0.01

<COMPLETEDIN::>0.02

<COMPLETEDIN::>0.02
10 changes: 10 additions & 0 deletions tests/fixtures/nested_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import codewars_test as test


@test.describe("group 1")
def group_1():
@test.describe("group 1 1")
def group_1_1():
@test.it("test 1")
def test_1():
test.assert_equals(1, 2)
6 changes: 6 additions & 0 deletions tests/fixtures/old_group.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

<DESCRIBE::>group 1

<IT::>test 1

<PASSED::>Test Passed
6 changes: 6 additions & 0 deletions tests/fixtures/old_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Deprecated and should not be used
import codewars_test as test

test.describe("group 1")
test.it("test 1")
test.assert_equals(1, 1)
2 changes: 2 additions & 0 deletions tests/fixtures/old_top_level_assertion_fail.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<FAILED::>1 should equal 2
4 changes: 4 additions & 0 deletions tests/fixtures/old_top_level_assertion_fail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Deprecated and should not be used
import codewars_test as test

test.assert_equals(1, 2)
4 changes: 4 additions & 0 deletions tests/fixtures/old_top_level_assertion_fail_pass.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<FAILED::>1 should equal 2

<PASSED::>Test Passed
4 changes: 4 additions & 0 deletions tests/fixtures/old_top_level_assertion_fail_pass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import codewars_test as test

test.assert_equals(1, 2)
test.assert_equals(1, 1)
2 changes: 2 additions & 0 deletions tests/fixtures/old_top_level_assertion_pass.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<PASSED::>Test Passed
4 changes: 4 additions & 0 deletions tests/fixtures/old_top_level_assertion_pass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Deprecated and should not be used
import codewars_test as test

test.assert_equals(1, 1)
16 changes: 16 additions & 0 deletions tests/fixtures/passing_failing.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

<DESCRIBE::>group 1

<IT::>test 1

<PASSED::>Test Passed

<COMPLETEDIN::>0.00

<IT::>test 2

<FAILED::>1 should equal 2

<COMPLETEDIN::>0.00

<COMPLETEDIN::>0.02
12 changes: 12 additions & 0 deletions tests/fixtures/passing_failing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import codewars_test as test


@test.describe("group 1")
def group_1():
@test.it("test 1")
def test_1():
test.assert_equals(1, 1)

@test.it("test 2")
def test_2():
test.assert_equals(1, 2)
10 changes: 10 additions & 0 deletions tests/fixtures/single_failing.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

<DESCRIBE::>group 1

<IT::>test 1

<FAILED::>1 should equal 2

<COMPLETEDIN::>0.00

<COMPLETEDIN::>0.01
8 changes: 8 additions & 0 deletions tests/fixtures/single_failing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import codewars_test as test


@test.describe("group 1")
def group_1():
@test.it("test 1")
def test_1():
test.assert_equals(1, 2)
10 changes: 10 additions & 0 deletions tests/fixtures/single_passing.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

<DESCRIBE::>group 1

<IT::>test 1

<PASSED::>Test Passed

<COMPLETEDIN::>0.01

<COMPLETEDIN::>0.02
8 changes: 8 additions & 0 deletions tests/fixtures/single_passing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import codewars_test as test


@test.describe("group 1")
def group_1():
@test.it("test 1")
def test_1():
test.assert_equals(1, 1)
6 changes: 6 additions & 0 deletions tests/fixtures/timeout_failing.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

<DESCRIBE::>group 1

<FAILED::>Exceeded time limit of 0.010 seconds

<COMPLETEDIN::>30.41
11 changes: 11 additions & 0 deletions tests/fixtures/timeout_failing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import codewars_test as test


@test.describe("group 1")
def group_1():
@test.timeout(0.01)
def test_1():
x = 0
while x < 10 ** 9:
x += 1
test.pass_()
8 changes: 8 additions & 0 deletions tests/fixtures/timeout_passing.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

<DESCRIBE::>group 1

<PASSED::>Test Passed

<PASSED::>Test Passed

<COMPLETEDIN::>17.19
10 changes: 10 additions & 0 deletions tests/fixtures/timeout_passing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import codewars_test as test


@test.describe("group 1")
def group_1():
# This outputs 2 PASSED
@test.timeout(0.01)
def test_1():
test.assert_equals(1, 1)

Loading