Skip to content

Commit

Permalink
Fix error in Count iterator (#73)
Browse files Browse the repository at this point in the history
With tests.

Also avoids AutoAPI 3.4.0 (see #74)

Fixes #72.
  • Loading branch information
corranwebster authored Dec 3, 2024
1 parent f2138e0 commit a2bb2eb
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
python-version: '3.11'
- name: Install dependencies and local packages
run: python -m pip install sphinx pydata-sphinx-theme sphinx-autoapi sphinx-design
run: python -m pip install sphinx pydata-sphinx-theme "sphinx-autoapi != 3.4.0" sphinx-design
- name: Build HTML documentation with Sphinx
run: |
make html
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
python-version: '3.11'
- name: Install dependencies and local packages
run: python -m pip install sphinx pydata-sphinx-theme sphinx-autoapi sphinx-design
run: python -m pip install sphinx pydata-sphinx-theme "sphinx-autoapi != 3.4.0" sphinx-design
- name: Build HTML documentation with Sphinx
run: |
make html
Expand Down
2 changes: 1 addition & 1 deletion src/tempe/data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def __iter__(self):
i = self.start
while True:
yield i
i += 1
i += self.step

def __len__(self):
return None
Expand Down
56 changes: 56 additions & 0 deletions tests/tempe/test_data_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# SPDX-FileCopyrightText: 2024-present Unital Software <[email protected]>
#
# SPDX-License-Identifier: MIT

import unittest

from tempe.data_view import Count


class TestCount(unittest.TestCase):

def test_count(self):
"""Test count starts and steps as expected."""

count = Count(10, 5)
count_iter = iter(count)

self.assertEqual(next(count_iter), 10)
self.assertEqual(next(count_iter), 15)
self.assertEqual(next(count_iter), 20)

def test_count_getitem(self):
"""Test count getitem works as expected."""

count = Count(10, 5)

self.assertEqual(count[0], 10)
self.assertEqual(count[1], 15)
self.assertEqual(count[2], 20)

def test_count_default(self):
"""Test count default starts and steps as expected."""

count = Count()
count_iter = iter(count)

self.assertEqual(next(count_iter), 0)
self.assertEqual(next(count_iter), 1)
self.assertEqual(next(count_iter), 2)

def test_count_default_getitem(self):
"""Test count default getitem works as expected."""

count = Count()

self.assertEqual(count[0], 0)
self.assertEqual(count[1], 1)
self.assertEqual(count[2], 2)


if __name__ == "__main__":
result = unittest.main()
if not result.wasSuccessful():
import sys

sys.exit(1)

0 comments on commit a2bb2eb

Please sign in to comment.