spec-test 0.1.2__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. spec_test-0.1.3/.gitignore +3 -0
  2. {spec_test-0.1.2 → spec_test-0.1.3}/PKG-INFO +1 -1
  3. {spec_test-0.1.2 → spec_test-0.1.3}/docs/specs/spec-spec-test.md +3 -0
  4. {spec_test-0.1.2 → spec_test-0.1.3}/pyproject.toml +6 -1
  5. {spec_test-0.1.2 → spec_test-0.1.3}/spec_test/decorators.py +38 -13
  6. {spec_test-0.1.2 → spec_test-0.1.3}/spec_test/runner.py +4 -2
  7. spec_test-0.1.3/tests/test_decorators.py +135 -0
  8. {spec_test-0.1.2 → spec_test-0.1.3}/uv.lock +22 -1
  9. spec_test-0.1.2/.gitignore +0 -1
  10. spec_test-0.1.2/tests/test_decorators.py +0 -72
  11. {spec_test-0.1.2 → spec_test-0.1.3}/.github/workflows/publish.yml +0 -0
  12. {spec_test-0.1.2 → spec_test-0.1.3}/CLAUDE.md +0 -0
  13. {spec_test-0.1.2 → spec_test-0.1.3}/README.md +0 -0
  14. {spec_test-0.1.2 → spec_test-0.1.3}/prompt.md +0 -0
  15. {spec_test-0.1.2 → spec_test-0.1.3}/spec_test/__init__.py +0 -0
  16. {spec_test-0.1.2 → spec_test-0.1.3}/spec_test/cli.py +0 -0
  17. {spec_test-0.1.2 → spec_test-0.1.3}/spec_test/collector.py +0 -0
  18. {spec_test-0.1.2 → spec_test-0.1.3}/spec_test/pytest_plugin.py +0 -0
  19. {spec_test-0.1.2 → spec_test-0.1.3}/spec_test/reporter.py +0 -0
  20. {spec_test-0.1.2 → spec_test-0.1.3}/spec_test/types.py +0 -0
  21. {spec_test-0.1.2 → spec_test-0.1.3}/spec_test/verifier.py +0 -0
  22. {spec_test-0.1.2 → spec_test-0.1.3}/tests/__init__.py +0 -0
  23. {spec_test-0.1.2 → spec_test-0.1.3}/tests/conftest.py +0 -0
  24. {spec_test-0.1.2 → spec_test-0.1.3}/tests/test_cli.py +0 -0
  25. {spec_test-0.1.2 → spec_test-0.1.3}/tests/test_collector.py +0 -0
  26. {spec_test-0.1.2 → spec_test-0.1.3}/tests/test_reporter.py +0 -0
  27. {spec_test-0.1.2 → spec_test-0.1.3}/tests/test_verifier.py +0 -0
@@ -0,0 +1,3 @@
1
+ dist/
2
+ __pycache__/
3
+ *.pyc
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spec-test
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Specification-driven development tool with test verification
5
5
  Author: Pulse Team
6
6
  License: MIT
@@ -10,6 +10,9 @@ spec-test is a tool for specification-driven development that links requirements
10
10
  - **DEC-002**: @spec decorator adds pytest marker to test
11
11
  - **DEC-003**: @spec decorator preserves function metadata
12
12
  - **DEC-004**: @specs decorator supports multiple spec IDs
13
+ - **DEC-005**: @spec decorator preserves async function behavior
14
+ - **DEC-006**: @spec decorator works regardless of decorator order with pytest.mark.asyncio
15
+ - **DEC-007**: @specs decorator preserves async function behavior
13
16
 
14
17
  ## Collector Requirements
15
18
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "spec-test"
3
- version = "0.1.2"
3
+ version = "0.1.3"
4
4
  description = "Specification-driven development tool with test verification"
5
5
  authors = [{ name = "Pulse Team" }]
6
6
  readme = "README.md"
@@ -43,3 +43,8 @@ target-version = "py311"
43
43
  [tool.mypy]
44
44
  python_version = "3.11"
45
45
  strict = true
46
+
47
+ [dependency-groups]
48
+ dev = [
49
+ "pytest-asyncio>=1.3.0",
50
+ ]
@@ -1,5 +1,6 @@
1
1
  """Decorators for linking tests to specifications."""
2
2
 
3
+ import asyncio
3
4
  import functools
4
5
  from typing import Callable, Optional
5
6
 
@@ -50,16 +51,29 @@ def spec(
50
51
  marked = pytest.mark.spec(func)
51
52
  marked = pytest.mark.spec_id(spec_id)(marked)
52
53
 
53
- @functools.wraps(func)
54
- def wrapper(*args, **kwargs):
55
- return func(*args, **kwargs)
54
+ # Create appropriate wrapper based on whether func is async
55
+ if asyncio.iscoroutinefunction(func):
56
56
 
57
- # Preserve spec metadata on wrapper
58
- wrapper._spec_id = spec_id
59
- wrapper._spec_description = description
60
- wrapper._spec_notes = verification_notes
57
+ @functools.wraps(func)
58
+ async def async_wrapper(*args, **kwargs):
59
+ return await func(*args, **kwargs)
61
60
 
62
- return wrapper
61
+ # Preserve spec metadata on wrapper
62
+ async_wrapper._spec_id = spec_id
63
+ async_wrapper._spec_description = description
64
+ async_wrapper._spec_notes = verification_notes
65
+ return async_wrapper
66
+ else:
67
+
68
+ @functools.wraps(func)
69
+ def wrapper(*args, **kwargs):
70
+ return func(*args, **kwargs)
71
+
72
+ # Preserve spec metadata on wrapper
73
+ wrapper._spec_id = spec_id
74
+ wrapper._spec_description = description
75
+ wrapper._spec_notes = verification_notes
76
+ return wrapper
63
77
 
64
78
  return decorator
65
79
 
@@ -103,11 +117,22 @@ def specs(*spec_ids: str):
103
117
  for sid in spec_ids:
104
118
  marked = pytest.mark.spec_id(sid)(marked)
105
119
 
106
- @functools.wraps(func)
107
- def wrapper(*args, **kwargs):
108
- return func(*args, **kwargs)
120
+ # Create appropriate wrapper based on whether func is async
121
+ if asyncio.iscoroutinefunction(func):
122
+
123
+ @functools.wraps(func)
124
+ async def async_wrapper(*args, **kwargs):
125
+ return await func(*args, **kwargs)
126
+
127
+ async_wrapper._spec_ids = spec_ids
128
+ return async_wrapper
129
+ else:
130
+
131
+ @functools.wraps(func)
132
+ def wrapper(*args, **kwargs):
133
+ return func(*args, **kwargs)
109
134
 
110
- wrapper._spec_ids = spec_ids
111
- return wrapper
135
+ wrapper._spec_ids = spec_ids
136
+ return wrapper
112
137
 
113
138
  return decorator
@@ -38,7 +38,7 @@ def _discover_from_files(tests_dir: Path) -> dict[str, SpecTest]:
38
38
  continue
39
39
 
40
40
  for node in ast.walk(tree):
41
- if not isinstance(node, ast.FunctionDef):
41
+ if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
42
42
  continue
43
43
 
44
44
  spec_info = _extract_spec_decorator(node)
@@ -58,7 +58,9 @@ def _discover_from_files(tests_dir: Path) -> dict[str, SpecTest]:
58
58
  return spec_tests
59
59
 
60
60
 
61
- def _extract_spec_decorator(node: ast.FunctionDef) -> Optional[tuple[str, str]]:
61
+ def _extract_spec_decorator(
62
+ node: ast.FunctionDef | ast.AsyncFunctionDef,
63
+ ) -> Optional[tuple[str, str]]:
62
64
  """Extract @spec decorator info from a function node."""
63
65
  for decorator in node.decorator_list:
64
66
  if isinstance(decorator, ast.Call):
@@ -0,0 +1,135 @@
1
+ """Tests for the @spec decorator."""
2
+
3
+ import pytest
4
+
5
+ from spec_test import get_spec_registry, spec, specs
6
+ from spec_test.decorators import clear_registry
7
+
8
+
9
+ @pytest.fixture(autouse=True)
10
+ def clean_registry():
11
+ """Clear registry before each test."""
12
+ clear_registry()
13
+ yield
14
+ clear_registry()
15
+
16
+
17
+ @spec("DEC-001", "@spec decorator registers test in global registry")
18
+ def test_spec_decorator_registers_in_registry():
19
+ """Test that @spec decorator adds to global registry."""
20
+ clear_registry()
21
+
22
+ @spec("TEST-001", "Test description")
23
+ def sample_test():
24
+ pass
25
+
26
+ registry = get_spec_registry()
27
+ assert "TEST-001" in registry
28
+ assert len(registry["TEST-001"]) == 1
29
+ assert registry["TEST-001"][0]["description"] == "Test description"
30
+
31
+
32
+ @spec("DEC-002", "@spec decorator adds pytest marker to test")
33
+ def test_spec_decorator_adds_pytest_marker():
34
+ """Test that @spec decorator adds pytest markers."""
35
+
36
+ @spec("TEST-002", "Test description")
37
+ def sample_test():
38
+ pass
39
+
40
+ # Check that the function has spec metadata
41
+ assert hasattr(sample_test, "_spec_id")
42
+ assert sample_test._spec_id == "TEST-002"
43
+
44
+
45
+ @spec("DEC-003", "@spec decorator preserves function metadata")
46
+ def test_spec_decorator_preserves_metadata():
47
+ """Test that @spec decorator preserves function name and docstring."""
48
+
49
+ @spec("TEST-003", "Test description")
50
+ def sample_test():
51
+ """This is a docstring."""
52
+ pass
53
+
54
+ assert sample_test.__name__ == "sample_test"
55
+ assert sample_test.__doc__ == "This is a docstring."
56
+
57
+
58
+ @spec("DEC-004", "@specs decorator supports multiple spec IDs")
59
+ def test_specs_decorator_multiple_ids():
60
+ """Test that @specs decorator handles multiple spec IDs."""
61
+ clear_registry()
62
+
63
+ @specs("TEST-A", "TEST-B", "TEST-C")
64
+ def multi_spec_test():
65
+ pass
66
+
67
+ registry = get_spec_registry()
68
+ assert "TEST-A" in registry
69
+ assert "TEST-B" in registry
70
+ assert "TEST-C" in registry
71
+ assert hasattr(multi_spec_test, "_spec_ids")
72
+ assert multi_spec_test._spec_ids == ("TEST-A", "TEST-B", "TEST-C")
73
+
74
+
75
+ @spec("DEC-005", "@spec decorator preserves async function behavior")
76
+ @pytest.mark.asyncio
77
+ async def test_spec_decorator_preserves_async():
78
+ """Test that @spec decorator works with async functions."""
79
+ import asyncio
80
+
81
+ @spec("TEST-ASYNC-001", "Async test description")
82
+ async def async_sample_test():
83
+ await asyncio.sleep(0.001)
84
+ return "async_result"
85
+
86
+ # Verify the wrapper is still a coroutine function
87
+ assert asyncio.iscoroutinefunction(async_sample_test)
88
+
89
+ # Verify it can be awaited and returns correct result
90
+ result = await async_sample_test()
91
+ assert result == "async_result"
92
+
93
+ # Verify metadata is preserved
94
+ assert hasattr(async_sample_test, "_spec_id")
95
+ assert async_sample_test._spec_id == "TEST-ASYNC-001"
96
+
97
+
98
+ @spec("DEC-006", "@spec decorator works regardless of decorator order with pytest.mark.asyncio")
99
+ @pytest.mark.asyncio
100
+ async def test_spec_decorator_order_independence():
101
+ """Test that @spec works regardless of decorator ordering with pytest.mark.asyncio."""
102
+ import asyncio
103
+
104
+ # Test with @spec below @pytest.mark.asyncio (the problematic order before fix)
105
+ @spec("TEST-ASYNC-002", "Async test with spec below mark")
106
+ async def async_test_spec_below():
107
+ await asyncio.sleep(0.001)
108
+ return "result"
109
+
110
+ assert asyncio.iscoroutinefunction(async_test_spec_below)
111
+ result = await async_test_spec_below()
112
+ assert result == "result"
113
+
114
+
115
+ @spec("DEC-007", "@specs decorator preserves async function behavior")
116
+ @pytest.mark.asyncio
117
+ async def test_specs_decorator_preserves_async():
118
+ """Test that @specs decorator works with async functions."""
119
+ import asyncio
120
+
121
+ @specs("TEST-ASYNC-A", "TEST-ASYNC-B")
122
+ async def async_multi_spec_test():
123
+ await asyncio.sleep(0.001)
124
+ return "multi_async_result"
125
+
126
+ # Verify the wrapper is still a coroutine function
127
+ assert asyncio.iscoroutinefunction(async_multi_spec_test)
128
+
129
+ # Verify it can be awaited and returns correct result
130
+ result = await async_multi_spec_test()
131
+ assert result == "multi_async_result"
132
+
133
+ # Verify metadata is preserved
134
+ assert hasattr(async_multi_spec_test, "_spec_ids")
135
+ assert async_multi_spec_test._spec_ids == ("TEST-ASYNC-A", "TEST-ASYNC-B")
@@ -429,6 +429,19 @@ wheels = [
429
429
  { url = "https://files.pythonhosted.org/packages/3b/ab/b3226f0bd7cdcf710fbede2b3548584366da3b19b5021e74f5bde2a8fa3f/pytest-9.0.2-py3-none-any.whl", hash = "sha256:711ffd45bf766d5264d487b917733b453d917afd2b0ad65223959f59089f875b", size = 374801, upload-time = "2025-12-06T21:30:49.154Z" },
430
430
  ]
431
431
 
432
+ [[package]]
433
+ name = "pytest-asyncio"
434
+ version = "1.3.0"
435
+ source = { registry = "https://pypi.org/simple" }
436
+ dependencies = [
437
+ { name = "pytest" },
438
+ { name = "typing-extensions", marker = "python_full_version < '3.13'" },
439
+ ]
440
+ sdist = { url = "https://files.pythonhosted.org/packages/90/2c/8af215c0f776415f3590cac4f9086ccefd6fd463befeae41cd4d3f193e5a/pytest_asyncio-1.3.0.tar.gz", hash = "sha256:d7f52f36d231b80ee124cd216ffb19369aa168fc10095013c6b014a34d3ee9e5", size = 50087, upload-time = "2025-11-10T16:07:47.256Z" }
441
+ wheels = [
442
+ { url = "https://files.pythonhosted.org/packages/e5/35/f8b19922b6a25bc0880171a2f1a003eaeb93657475193ab516fd87cac9da/pytest_asyncio-1.3.0-py3-none-any.whl", hash = "sha256:611e26147c7f77640e6d0a92a38ed17c3e9848063698d5c93d5aa7aa11cebff5", size = 15075, upload-time = "2025-11-10T16:07:45.537Z" },
443
+ ]
444
+
432
445
  [[package]]
433
446
  name = "pytest-cov"
434
447
  version = "7.0.0"
@@ -493,7 +506,7 @@ wheels = [
493
506
 
494
507
  [[package]]
495
508
  name = "spec-test"
496
- version = "0.1.0"
509
+ version = "0.1.2"
497
510
  source = { editable = "." }
498
511
  dependencies = [
499
512
  { name = "pydantic" },
@@ -509,6 +522,11 @@ dev = [
509
522
  { name = "ruff" },
510
523
  ]
511
524
 
525
+ [package.dev-dependencies]
526
+ dev = [
527
+ { name = "pytest-asyncio" },
528
+ ]
529
+
512
530
  [package.metadata]
513
531
  requires-dist = [
514
532
  { name = "mypy", marker = "extra == 'dev'", specifier = ">=1.0.0" },
@@ -521,6 +539,9 @@ requires-dist = [
521
539
  ]
522
540
  provides-extras = ["dev"]
523
541
 
542
+ [package.metadata.requires-dev]
543
+ dev = [{ name = "pytest-asyncio", specifier = ">=1.3.0" }]
544
+
524
545
  [[package]]
525
546
  name = "tomli"
526
547
  version = "2.4.0"
@@ -1 +0,0 @@
1
- dist/
@@ -1,72 +0,0 @@
1
- """Tests for the @spec decorator."""
2
-
3
- import pytest
4
-
5
- from spec_test import get_spec_registry, spec, specs
6
- from spec_test.decorators import clear_registry
7
-
8
-
9
- @pytest.fixture(autouse=True)
10
- def clean_registry():
11
- """Clear registry before each test."""
12
- clear_registry()
13
- yield
14
- clear_registry()
15
-
16
-
17
- @spec("DEC-001", "@spec decorator registers test in global registry")
18
- def test_spec_decorator_registers_in_registry():
19
- """Test that @spec decorator adds to global registry."""
20
- clear_registry()
21
-
22
- @spec("TEST-001", "Test description")
23
- def sample_test():
24
- pass
25
-
26
- registry = get_spec_registry()
27
- assert "TEST-001" in registry
28
- assert len(registry["TEST-001"]) == 1
29
- assert registry["TEST-001"][0]["description"] == "Test description"
30
-
31
-
32
- @spec("DEC-002", "@spec decorator adds pytest marker to test")
33
- def test_spec_decorator_adds_pytest_marker():
34
- """Test that @spec decorator adds pytest markers."""
35
-
36
- @spec("TEST-002", "Test description")
37
- def sample_test():
38
- pass
39
-
40
- # Check that the function has spec metadata
41
- assert hasattr(sample_test, "_spec_id")
42
- assert sample_test._spec_id == "TEST-002"
43
-
44
-
45
- @spec("DEC-003", "@spec decorator preserves function metadata")
46
- def test_spec_decorator_preserves_metadata():
47
- """Test that @spec decorator preserves function name and docstring."""
48
-
49
- @spec("TEST-003", "Test description")
50
- def sample_test():
51
- """This is a docstring."""
52
- pass
53
-
54
- assert sample_test.__name__ == "sample_test"
55
- assert sample_test.__doc__ == "This is a docstring."
56
-
57
-
58
- @spec("DEC-004", "@specs decorator supports multiple spec IDs")
59
- def test_specs_decorator_multiple_ids():
60
- """Test that @specs decorator handles multiple spec IDs."""
61
- clear_registry()
62
-
63
- @specs("TEST-A", "TEST-B", "TEST-C")
64
- def multi_spec_test():
65
- pass
66
-
67
- registry = get_spec_registry()
68
- assert "TEST-A" in registry
69
- assert "TEST-B" in registry
70
- assert "TEST-C" in registry
71
- assert hasattr(multi_spec_test, "_spec_ids")
72
- assert multi_spec_test._spec_ids == ("TEST-A", "TEST-B", "TEST-C")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes