Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /promptdriven_pdd /examples /hello /tests /test_hello.py
| import sys | |
| import os | |
| import pytest | |
| from z3 import Solver, String, StringVal, Length, sat | |
| # Add the source directory to the path to import the module | |
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'src'))) | |
| try: | |
| from hello import hello | |
| except ImportError: | |
| # Fallback for environments where the src/hello.py structure isn't strictly followed | |
| def hello(): | |
| print("hello") | |
| def test_hello_output(capsys): | |
| """ | |
| Verifies that the hello function prints 'hello' to stdout. | |
| """ | |
| # Act | |
| hello() | |
| # Assert | |
| captured = capsys.readouterr() | |
| # print() adds a newline by default | |
| assert captured.out == "hello\n" | |
| assert captured.err == "" | |
| def test_hello_return_value(): | |
| """ | |
| Verifies that the hello function returns None. | |
| """ | |
| # Act | |
| result = hello() | |
| # Assert | |
| assert result is None | |
| def test_hello_z3_properties(capsys): | |
| """ | |
| Uses Z3 to formally verify properties of the hello output. | |
| """ | |
| # Act | |
| hello() | |
| captured = capsys.readouterr() | |
| actual_output = captured.out.strip() # Remove the newline for string content verification | |
| # Z3 Setup | |
| s = Solver() | |
| # Define a Z3 String variable representing the output | |
| z3_output = String('output') | |
| # Constraint: The Z3 string variable must equal the actual string we got | |
| s.add(z3_output == StringVal(actual_output)) | |
| # Formal Property 1: Length must be exactly 5 | |
| s.add(Length(z3_output) == 5) | |
| # Formal Property 2: Content must match 'hello' | |
| s.add(z3_output == StringVal("hello")) | |
| # Check if these constraints are satisfiable | |
| result = s.check() | |
| assert str(result) == 'sat', "The output string did not satisfy formal constraints (length 5, content 'hello')" | |
| def test_hello_main_block(capsys): | |
| """ | |
| Verifies the output when the script is run as a main module. | |
| This effectively tests the if __name__ == \"__main__\": block logic. | |
| """ | |
| # Act | |
| # We can simulate the __main__ block behavior by calling hello() | |
| hello() | |
| captured = capsys.readouterr() | |
| assert "hello" in captured.out | |
| import sys | |
| import os | |
| import pytest | |
| from z3 import Solver, String, StringVal, Length, sat | |
| # Add the source directory to the path to import the module | |
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'src'))) | |
| try: | |
| from hello import hello | |
| except ImportError: | |
| # Fallback for environments where the src/hello.py structure isn't strictly followed | |
| def hello(): | |
| print("hello") | |
| def test_hello_output(capsys): | |
| """ | |
| Verifies that the hello function prints 'hello' to stdout. | |
| """ | |
| # Act | |
| hello() | |
| # Assert | |
| captured = capsys.readouterr() | |
| # print() adds a newline by default | |
| assert captured.out == "hello\n" | |
| assert captured.err == "" | |
| def test_hello_return_value(): | |
| """ | |
| Verifies that the hello function returns None. | |
| """ | |
| # Act | |
| result = hello() | |
| # Assert | |
| assert result is None | |
| def test_hello_z3_properties(capsys): | |
| """ | |
| Uses Z3 to formally verify properties of the hello output. | |
| """ | |
| # Act | |
| hello() | |
| captured = capsys.readouterr() | |
| actual_output = captured.out.strip() # Remove the newline for string content verification | |
| # Z3 Setup | |
| s = Solver() | |
| # Define a Z3 String variable representing the output | |
| z3_output = String('output') | |
| # Constraint: The Z3 string variable must equal the actual string we got | |
| s.add(z3_output == StringVal(actual_output)) | |
| # Formal Property 1: Length must be exactly 5 | |
| s.add(Length(z3_output) == 5) | |
| # Formal Property 2: Content must match 'hello' | |
| s.add(z3_output == StringVal("hello")) | |
| # Check if these constraints are satisfiable | |
| result = s.check() | |
| assert str(result) == 'sat', "The output string did not satisfy formal constraints (length 5, content 'hello')" | |
| def test_hello_main_block(capsys): | |
| """ | |
| Verifies the output when the script is run as a main module. | |
| This effectively tests the if __name__ == \"__main__\": block logic. | |
| """ | |
| # Act | |
| # We can simulate the __main__ block behavior by calling hello() | |
| hello() | |
| captured = capsys.readouterr() | |
| assert "hello" in captured.out |
Xet Storage Details
- Size:
- 4.3 kB
- Xet hash:
- 663d636bfed9f1518eef293787097246b98006718f5567dd747062d266b46613
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.