Skip to content

Commit

Permalink
feat(test): #16 add unit tests
Browse files Browse the repository at this point in the history
- Add unit testing for the rust module
  • Loading branch information
rohaquinlop committed Mar 4, 2024
1 parent 731f5a9 commit 79b7694
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ jobs:
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
- name: Install pytest
run: pip install pytest
- name: Test wheels
run: pytest --pyargs ${{ github.repository }} --doctest-modules
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
Expand All @@ -64,6 +68,10 @@ jobs:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Install pytest
run: pip install pytest
- name: Test wheels
run: pytest --pyargs ${{ github.repository }} --doctest-modules
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
Expand All @@ -86,6 +94,10 @@ jobs:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Install pytest
run: pip install pytest
- name: Test wheels
run: pytest --pyargs ${{ github.repository }} --doctest-modules
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
Expand Down
101 changes: 101 additions & 0 deletions tests/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from complexipy import rust
import unittest
from pathlib import Path


class TestFiles(unittest.TestCase):
local_path = Path(__file__).resolve().parent

def test_path(self):
path = self.local_path / "src"
files = rust.main(path.resolve().as_posix(), True, False, 0)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(40, total_complexity)

def test(self):
path = self.local_path / "src/test.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(9, total_complexity)

def test_break_continue(self):
path = self.local_path / "src/test_break_continue.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(3, total_complexity)

def test_decorator(self):
path = self.local_path / "src/test_decorator.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(1, total_complexity)

def test_for(self):
path = self.local_path / "src/test_for.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(5, total_complexity)

def test_for_assign(self):
path = self.local_path / "src/test_for_assign.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(1, total_complexity)

def test_if(self):
path = self.local_path / "src/test_if.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(3, total_complexity)

def test_main(self):
path = self.local_path / "src/test_main.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(0, total_complexity)

def test_match(self):
path = self.local_path / "src/test_match.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(0, total_complexity)

def test_multiple_func(self):
path = self.local_path / "src/test_multiple_func.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(0, total_complexity)

def test_nested_func(self):
path = self.local_path / "src/test_nested_func.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(2, total_complexity)

def test_recursive(self):
path = self.local_path / "src/test_recursive.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(0, total_complexity)

def test_ternary_op(self):
path = self.local_path / "src/test_ternary_op.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(1, total_complexity)

def test_try(self):
path = self.local_path / "src/test_try.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(3, total_complexity)

def test_try_nested(self):
path = self.local_path / "src/test_try_nested.py"
files = rust.main(path.resolve().as_posix(), False, False, 15)
total_complexity = sum([file.complexity for file in files])
self.assertEqual(12, total_complexity)


if __name__ == "__main__":
unittest.main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/src/test_for_assign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def test_for(n: int):
lst = [i for i in range(n)]

for i in lst:
print(i)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 79b7694

Please sign in to comment.