Select the types of activity you want to include in your feed.
Demonstration bridge between ATproto and GraphQL. Generate schema types and interface with the ATmosphere via GraphQL queries. Includes a TypeScript server with IDE.
···11+"""Test configuration and fixtures for the schema generation tests."""
22+33+import os
44+import sys
55+from pathlib import Path
66+77+# Add the project root to the Python path so we can import modules
88+sys.path.insert(0, str(Path(__file__).parent.parent))
99+1010+1111+def pytest_configure(config):
1212+ """Add custom markers if needed."""
1313+ pass
+115
tests/test_schema_generation.py
···11+"""Test for schema generation consistency."""
22+33+import os
44+import tempfile
55+from pathlib import Path
66+from typing import List
77+88+from schema.generate_lexicon_schema import generate_definitions, main
99+1010+# Constant for the expected output file
1111+EXPECTED_OUTPUT_FILE = "schema/schema-generated.graphql"
1212+1313+1414+def test_schema_generation_consistency():
1515+ """
1616+ Test that running the generate_lexicon_schema.py script produces consistent output.
1717+ This test ensures that the generated schema doesn't change unexpectedly.
1818+ """
1919+ # Expected lexicon IDs from the command line
2020+ lexicon_ids = ["app.bsky.actor.getProfile", "com.atproto.server.getSession"]
2121+2222+ # Generate the expected output using the function directly
2323+ generated_content = "\n\n".join(generate_definitions(lexicon_ids))
2424+2525+ # Read the expected file if it exists
2626+ expected_file_path = Path(EXPECTED_OUTPUT_FILE)
2727+ if expected_file_path.exists():
2828+ with open(expected_file_path, "r") as f:
2929+ expected_content = f.read()
3030+3131+ # Compare the generated content with the expected content
3232+ assert generated_content == expected_content, (
3333+ "Generated schema content does not match the expected file. "
3434+ "This could mean the schema has changed or the test needs to be updated."
3535+ )
3636+3737+ else:
3838+ # If the expected file doesn't exist, create it with the current output
3939+ with open(expected_file_path, "w") as f:
4040+ f.write(generated_content)
4141+ print(f"Created new expected output file: {expected_file_path}")
4242+4343+4444+def test_main_function_output():
4545+ """
4646+ Test the main function by running it with the specified lexicon IDs
4747+ and verifying the output is consistent.
4848+ """
4949+ # Expected lexicon IDs from the command line
5050+ lexicon_ids = ["app.bsky.actor.getProfile", "com.atproto.server.getSession"]
5151+5252+ # Create a temporary file for testing
5353+ with tempfile.NamedTemporaryFile(
5454+ mode="w", suffix=".graphql", delete=False
5555+ ) as tmp_file:
5656+ tmp_path = tmp_file.name
5757+5858+ try:
5959+ # Run the main function with the lexicon IDs and output to temp file
6060+ main(lexicon_ids=lexicon_ids, output=tmp_path, append_schema=None)
6161+6262+ # Read the generated content
6363+ with open(tmp_path, "r") as f:
6464+ generated_content = f.read()
6565+6666+ # Read the expected file if it exists
6767+ expected_file_path = Path(EXPECTED_OUTPUT_FILE)
6868+ if expected_file_path.exists():
6969+ with open(expected_file_path, "r") as f:
7070+ expected_content = f.read()
7171+7272+ # Compare the generated content with the expected content
7373+ assert generated_content == expected_content, (
7474+ "Generated schema content does not match the expected file. "
7575+ "This could mean the schema has changed or the test needs to be updated."
7676+ )
7777+ else:
7878+ # If the expected file doesn't exist, create it with the current output
7979+ with open(expected_file_path, "w") as f:
8080+ f.write(generated_content)
8181+ print(f"Created new expected output file: {expected_file_path}")
8282+8383+ finally:
8484+ # Clean up the temporary file
8585+ if os.path.exists(tmp_path):
8686+ os.unlink(tmp_path)
8787+8888+8989+def test_generate_definitions_function():
9090+ """
9191+ Test the generate_definitions function directly to ensure it produces consistent output.
9292+ """
9393+ # Expected lexicon IDs from the command line
9494+ lexicon_ids = ["app.bsky.actor.getProfile", "com.atproto.server.getSession"]
9595+9696+ # Generate definitions using the function
9797+ generated_chunks = generate_definitions(lexicon_ids)
9898+ generated_content = "\n\n".join(generated_chunks)
9999+100100+ # Read the expected file if it exists
101101+ expected_file_path = Path(EXPECTED_OUTPUT_FILE)
102102+ if expected_file_path.exists():
103103+ with open(expected_file_path, "r") as f:
104104+ expected_content = f.read()
105105+106106+ # Compare the generated content with the expected content
107107+ assert generated_content == expected_content, (
108108+ "Generated schema content does not match the expected file. "
109109+ "This could mean the schema has changed or the test needs to be updated."
110110+ )
111111+ else:
112112+ # If the expected file doesn't exist, create it with the current output
113113+ with open(expected_file_path, "w") as f:
114114+ f.write(generated_content)
115115+ print(f"Created new expected output file: {expected_file_path}")