diff --git a/flask_to_fastapi_migration/input_repo/main.py b/flask_to_fastapi_migration/input_repo/main.py index aa16449..f25325b 100644 --- a/flask_to_fastapi_migration/input_repo/main.py +++ b/flask_to_fastapi_migration/input_repo/main.py @@ -11,22 +11,26 @@ authors = ["Author A", "Author B", "Author C"] categories = ["Fiction", "Non-Fiction", "Biography"] + # Home Page @app.route("/") def home(): return render_template("index.html") + # Books Page @app.route("/books", methods=["GET"]) def get_books(): return render_template("books.html", books=books) + @app.route("/books", methods=["POST"]) def add_book(): data = request.json books.append(data) return jsonify(data), 201 + @app.route("/books/", methods=["PUT"]) def update_book(book_id): data = request.json @@ -36,33 +40,39 @@ def update_book(book_id): return jsonify(book) return jsonify({"error": "Book not found"}), 404 + @app.route("/books/", methods=["DELETE"]) def delete_book(book_id): global books books = [book for book in books if book["id"] != book_id] return jsonify({"message": "Book deleted"}) + # Authors Page @app.route("/authors", methods=["GET"]) def get_authors(): return render_template("authors.html", authors=authors) + @app.route("/authors", methods=["POST"]) def add_author(): data = request.json authors.append(data["name"]) return jsonify({"name": data["name"]}), 201 + # Categories Page @app.route("/categories", methods=["GET"]) def get_categories(): return render_template("categories.html", categories=categories) + @app.route("/categories", methods=["POST"]) def add_category(): data = request.json categories.append(data["name"]) return jsonify({"name": data["name"]}), 201 + if __name__ == "__main__": app.run(debug=True) diff --git a/freezegun_to_timemachine_migration/run.py b/freezegun_to_timemachine_migration/run.py index da86ba3..141f3a9 100644 --- a/freezegun_to_timemachine_migration/run.py +++ b/freezegun_to_timemachine_migration/run.py @@ -1,4 +1,5 @@ from codegen import Codebase + codebase = Codebase.from_repo("getmoto/moto", commit="786a8ada7ed0c7f9d8b04d49f24596865e4b7901") print("🚀 Starting FreezeGun to TimeMachine conversion...") @@ -9,32 +10,31 @@ print(f"📝 Processing: {file.filepath}") # Update imports for imp in file.imports: - if imp.symbol_name and 'freezegun' in imp.source: - if imp.name == 'freeze_time': + if imp.symbol_name and "freezegun" in imp.source: + if imp.name == "freeze_time": # required due to Codegen limitations - imp.edit('from time_machine import travel') + imp.edit("from time_machine import travel") else: - imp.set_import_module('time_machine') + imp.set_import_module("time_machine") # Find all function calls in the file for fcall in file.function_calls: # Skip if not a freeze_time call - if 'freeze_time' not in fcall.source: + if "freeze_time" not in fcall.source: continue # Get original source and prepare new source new_source = fcall.source # Add tick parameter if not present - if not fcall.get_arg_by_parameter_name('tick'): - if new_source.endswith(')'): + if not fcall.get_arg_by_parameter_name("tick"): + if new_source.endswith(")"): new_source = new_source[:-1] - if not new_source.endswith('('): - new_source += ',' - new_source += ' tick=False)' + if not new_source.endswith("("): + new_source += "," + new_source += " tick=False)" # Replace freeze_time with travel - if '.' in new_source: - new_source = new_source.replace( - 'freeze_time', 'travel').replace('freezegun', 'time_machine') + if "." in new_source: + new_source = new_source.replace("freeze_time", "travel").replace("freezegun", "time_machine") else: - new_source = 'travel' + new_source[len('freeze_time'):] + new_source = "travel" + new_source[len("freeze_time") :] # Make single edit with complete changes fcall.edit(new_source) codebase.commit() diff --git a/generate_training_data/run.py b/generate_training_data/run.py index 2702846..1ae5421 100644 --- a/generate_training_data/run.py +++ b/generate_training_data/run.py @@ -81,12 +81,8 @@ def run(codebase: Codebase): # Update metadata training_data["metadata"]["total_processed"] = len(training_data["functions"]) if training_data["functions"]: - training_data["metadata"]["avg_dependencies"] = sum( - len(f["dependencies"]) for f in training_data["functions"] - ) / len(training_data["functions"]) - training_data["metadata"]["avg_usages"] = sum( - len(f["usages"]) for f in training_data["functions"] - ) / len(training_data["functions"]) + training_data["metadata"]["avg_dependencies"] = sum(len(f["dependencies"]) for f in training_data["functions"]) / len(training_data["functions"]) + training_data["metadata"]["avg_usages"] = sum(len(f["usages"]) for f in training_data["functions"]) / len(training_data["functions"]) # Print stats print(f"Processed {training_data['metadata']['total_processed']} functions") diff --git a/sqlalchemy_1.6_to_2.0/input_repo/main.py b/sqlalchemy_1.6_to_2.0/input_repo/main.py index 1bbbc4b..12ec215 100644 --- a/sqlalchemy_1.6_to_2.0/input_repo/main.py +++ b/sqlalchemy_1.6_to_2.0/input_repo/main.py @@ -10,6 +10,7 @@ app = FastAPI() models.Base.metadata.create_all(bind=engine) + # Dependency for the database session def get_db(): db = SessionLocal() @@ -18,6 +19,7 @@ def get_db(): finally: db.close() + # Utility Functions def get_book_or_404(book_id: int, db: Session): book = db.query(models.Book).filter(models.Book.id == book_id).first() @@ -25,8 +27,10 @@ def get_book_or_404(book_id: int, db: Session): raise HTTPException(status_code=404, detail="Book not found") return book + # CRUD Operations + @app.post("/books/", response_model=schemas.Book) def create_book(book: schemas.BookCreate, db: Session = Depends(get_db)): db_book = models.Book(**book.dict()) @@ -35,11 +39,13 @@ def create_book(book: schemas.BookCreate, db: Session = Depends(get_db)): db.refresh(db_book) return db_book + @app.get("/books/", response_model=List[schemas.Book]) def read_books(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)): books = db.query(models.Book).offset(skip).limit(limit).all() return books + @app.get("/books/{book_id}", response_model=schemas.Book) def read_book(book_id: int, db: Session = Depends(get_db)): book = db.query(models.Book).filter(models.Book.id == book_id).first() @@ -47,6 +53,7 @@ def read_book(book_id: int, db: Session = Depends(get_db)): raise HTTPException(status_code=404, detail="Book not found") return book + @app.put("/books/{book_id}", response_model=schemas.Book) def update_book(book_id: int, book: schemas.BookCreate, db: Session = Depends(get_db)): db_book = db.query(models.Book).filter(models.Book.id == book_id).first() @@ -58,6 +65,7 @@ def update_book(book_id: int, book: schemas.BookCreate, db: Session = Depends(ge db.refresh(db_book) return db_book + @app.delete("/books/{book_id}", response_model=schemas.Book) def delete_book(book_id: int, db: Session = Depends(get_db)): db_book = db.query(models.Book).filter(models.Book.id == book_id).first() @@ -67,6 +75,7 @@ def delete_book(book_id: int, db: Session = Depends(get_db)): db.commit() return db_book + @app.post("/publishers/", response_model=schemas.Publisher) def create_publisher(publisher: schemas.PublisherCreate, db: Session = Depends(get_db)): db_publisher = models.Publisher(**publisher.dict()) @@ -75,11 +84,13 @@ def create_publisher(publisher: schemas.PublisherCreate, db: Session = Depends(g db.refresh(db_publisher) return db_publisher + @app.get("/publishers/", response_model=List[schemas.Publisher]) def read_publishers(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)): publishers = db.query(models.Publisher).offset(skip).limit(limit).all() return publishers + @app.get("/publishers/{publisher_id}", response_model=schemas.Publisher) def read_publisher(publisher_id: int, db: Session = Depends(get_db)): publisher = db.query(models.Publisher).filter(models.Publisher.id == publisher_id).first() @@ -87,6 +98,7 @@ def read_publisher(publisher_id: int, db: Session = Depends(get_db)): raise HTTPException(status_code=404, detail="Publisher not found") return publisher + @app.put("/publishers/{publisher_id}", response_model=schemas.Publisher) def update_publisher(publisher_id: int, publisher: schemas.PublisherCreate, db: Session = Depends(get_db)): db_publisher = db.query(models.Publisher).filter(models.Publisher.id == publisher_id).first() @@ -98,6 +110,7 @@ def update_publisher(publisher_id: int, publisher: schemas.PublisherCreate, db: db.refresh(db_publisher) return db_publisher + @app.delete("/publishers/{publisher_id}", response_model=schemas.Publisher) def delete_publisher(publisher_id: int, db: Session = Depends(get_db)): db_publisher = db.query(models.Publisher).filter(models.Publisher.id == publisher_id).first() @@ -106,4 +119,3 @@ def delete_publisher(publisher_id: int, db: Session = Depends(get_db)): db.delete(db_publisher) db.commit() return db_publisher - diff --git a/sqlalchemy_1.6_to_2.0/input_repo/models.py b/sqlalchemy_1.6_to_2.0/input_repo/models.py index 07ba9ca..d87655f 100644 --- a/sqlalchemy_1.6_to_2.0/input_repo/models.py +++ b/sqlalchemy_1.6_to_2.0/input_repo/models.py @@ -2,6 +2,7 @@ from sqlalchemy.orm import relationship from database import Base + class Publisher(Base): __tablename__ = "publishers" diff --git a/sqlalchemy_1.6_to_2.0/input_repo/schemas.py b/sqlalchemy_1.6_to_2.0/input_repo/schemas.py index daf4fb9..9279ef4 100644 --- a/sqlalchemy_1.6_to_2.0/input_repo/schemas.py +++ b/sqlalchemy_1.6_to_2.0/input_repo/schemas.py @@ -1,12 +1,15 @@ from pydantic import BaseModel from typing import List, Optional + class PublisherBase(BaseModel): name: str + class PublisherCreate(PublisherBase): pass + class Publisher(PublisherBase): id: int books: List["Book"] = [] @@ -14,15 +17,18 @@ class Publisher(PublisherBase): class Config: orm_mode = True + class BookBase(BaseModel): title: str author: str description: str publisher_id: Optional[int] + class BookCreate(BookBase): pass + class Book(BookBase): id: int publisher: Optional[Publisher] diff --git a/sqlalchemy_1.6_to_2.0/output_repo/main.py b/sqlalchemy_1.6_to_2.0/output_repo/main.py index 93a716f..5068083 100644 --- a/sqlalchemy_1.6_to_2.0/output_repo/main.py +++ b/sqlalchemy_1.6_to_2.0/output_repo/main.py @@ -10,6 +10,7 @@ app = FastAPI() models.Base.metadata.create_all(bind=engine) + # Dependency for the database session def get_db(): db = SessionLocal() @@ -18,8 +19,10 @@ def get_db(): finally: db.close() + # CRUD Operations + @app.post("/books/", response_model=schemas.Book) def create_book(book: schemas.BookCreate, db: Session = Depends(get_db)): db_book = models.Book(**book.dict()) @@ -28,11 +31,13 @@ def create_book(book: schemas.BookCreate, db: Session = Depends(get_db)): db.refresh(db_book) return db_book + @app.get("/books/", response_model=List[schemas.Book]) def read_books(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)): books = db.query()(models.Book).offset(skip).limit(limit).scalars().all() return books + @app.get("/books/{book_id}", response_model=schemas.Book) def read_book(book_id: int, db: Session = Depends(get_db)): book = db.query()(models.Book).where(models.Book.id == book_id).first() @@ -40,6 +45,7 @@ def read_book(book_id: int, db: Session = Depends(get_db)): raise HTTPException(status_code=404, detail="Book not found") return book + @app.put("/books/{book_id}", response_model=schemas.Book) def update_book(book_id: int, book: schemas.BookCreate, db: Session = Depends(get_db)): db_book = db.query()(models.Book).where(models.Book.id == book_id).first() @@ -51,6 +57,7 @@ def update_book(book_id: int, book: schemas.BookCreate, db: Session = Depends(ge db.refresh(db_book) return db_book + @app.delete("/books/{book_id}", response_model=schemas.Book) def delete_book(book_id: int, db: Session = Depends(get_db)): db_book = db.query()(models.Book).where(models.Book.id == book_id).first() @@ -60,6 +67,7 @@ def delete_book(book_id: int, db: Session = Depends(get_db)): db.commit() return db_book + @app.post("/publishers/", response_model=schemas.Publisher) def create_publisher(publisher: schemas.PublisherCreate, db: Session = Depends(get_db)): db_publisher = models.Publisher(**publisher.dict()) @@ -68,11 +76,13 @@ def create_publisher(publisher: schemas.PublisherCreate, db: Session = Depends(g db.refresh(db_publisher) return db_publisher + @app.get("/publishers/", response_model=List[schemas.Publisher]) def read_publishers(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)): publishers = db.query()(models.Publisher).offset(skip).limit(limit).scalars().all() return publishers + @app.get("/publishers/{publisher_id}", response_model=schemas.Publisher) def read_publisher(publisher_id: int, db: Session = Depends(get_db)): publisher = db.query()(models.Publisher).where(models.Publisher.id == publisher_id).first() @@ -80,6 +90,7 @@ def read_publisher(publisher_id: int, db: Session = Depends(get_db)): raise HTTPException(status_code=404, detail="Publisher not found") return publisher + @app.put("/publishers/{publisher_id}", response_model=schemas.Publisher) def update_publisher(publisher_id: int, publisher: schemas.PublisherCreate, db: Session = Depends(get_db)): db_publisher = db.query()(models.Publisher).where(models.Publisher.id == publisher_id).first() @@ -91,6 +102,7 @@ def update_publisher(publisher_id: int, publisher: schemas.PublisherCreate, db: db.refresh(db_publisher) return db_publisher + @app.delete("/publishers/{publisher_id}", response_model=schemas.Publisher) def delete_publisher(publisher_id: int, db: Session = Depends(get_db)): db_publisher = db.query()(models.Publisher).where(models.Publisher.id == publisher_id).first() @@ -99,4 +111,3 @@ def delete_publisher(publisher_id: int, db: Session = Depends(get_db)): db.delete(db_publisher) db.commit() return db_publisher - diff --git a/sqlalchemy_1.6_to_2.0/output_repo/models.py b/sqlalchemy_1.6_to_2.0/output_repo/models.py index d6fcceb..3b26e58 100644 --- a/sqlalchemy_1.6_to_2.0/output_repo/models.py +++ b/sqlalchemy_1.6_to_2.0/output_repo/models.py @@ -3,16 +3,14 @@ from sqlalchemy.orm import relationship, Mapped, mapped_column from database import Base + class Publisher(Base): __tablename__ = "publishers" id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True) name: Mapped[str] = mapped_column(String, unique=True, index=True) - books: Mapped[List["Book"]] = relationship( - "Book", - back_populates="publisher", - lazy='selectin' - ) + books: Mapped[List["Book"]] = relationship("Book", back_populates="publisher", lazy="selectin") + class Book(Base): __tablename__ = "books" @@ -21,12 +19,5 @@ class Book(Base): title: Mapped[str] = mapped_column(String, index=True) author: Mapped[str] = mapped_column(String, index=True) description: Mapped[Optional[str]] = mapped_column(String, nullable=True) - publisher_id: Mapped[Optional[int]] = mapped_column( - Integer, - ForeignKey("publishers.id"), - nullable=True - ) - publisher: Mapped[Optional["Publisher"]] = relationship( - "Publisher", - back_populates="books" - ) \ No newline at end of file + publisher_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("publishers.id"), nullable=True) + publisher: Mapped[Optional["Publisher"]] = relationship("Publisher", back_populates="books") diff --git a/sqlalchemy_1.6_to_2.0/output_repo/schemas.py b/sqlalchemy_1.6_to_2.0/output_repo/schemas.py index daf4fb9..9279ef4 100644 --- a/sqlalchemy_1.6_to_2.0/output_repo/schemas.py +++ b/sqlalchemy_1.6_to_2.0/output_repo/schemas.py @@ -1,12 +1,15 @@ from pydantic import BaseModel from typing import List, Optional + class PublisherBase(BaseModel): name: str + class PublisherCreate(PublisherBase): pass + class Publisher(PublisherBase): id: int books: List["Book"] = [] @@ -14,15 +17,18 @@ class Publisher(PublisherBase): class Config: orm_mode = True + class BookBase(BaseModel): title: str author: str description: str publisher_id: Optional[int] + class BookCreate(BookBase): pass + class Book(BookBase): id: int publisher: Optional[Publisher] diff --git a/sqlalchemy_type_annotations/input_repo/models/organization.py b/sqlalchemy_type_annotations/input_repo/models/organization.py index 25da85c..2f4099d 100644 --- a/sqlalchemy_type_annotations/input_repo/models/organization.py +++ b/sqlalchemy_type_annotations/input_repo/models/organization.py @@ -1,5 +1,3 @@ - - from sqlalchemy import Column, Integer, String, DateTime from sqlalchemy.orm import relationship from .base import Base diff --git a/sqlalchemy_type_annotations/input_repo/models/transaction.py b/sqlalchemy_type_annotations/input_repo/models/transaction.py index debebe2..34b168f 100644 --- a/sqlalchemy_type_annotations/input_repo/models/transaction.py +++ b/sqlalchemy_type_annotations/input_repo/models/transaction.py @@ -1,6 +1,3 @@ - - - from sqlalchemy import Column, Integer, String, ForeignKey, Numeric, DateTime from sqlalchemy.orm import relationship from .base import Base diff --git a/sqlalchemy_type_annotations/input_repo/models/user.py b/sqlalchemy_type_annotations/input_repo/models/user.py index f7537ff..99f0d07 100644 --- a/sqlalchemy_type_annotations/input_repo/models/user.py +++ b/sqlalchemy_type_annotations/input_repo/models/user.py @@ -1,4 +1,3 @@ - from sqlalchemy import Column, Integer, String, ForeignKey, Boolean from sqlalchemy.orm import relationship from .base import Base diff --git a/unittest_to_pytest/repo-after/jj_classes/__init__.py b/unittest_to_pytest/input_repo/jj_classes/__init__.py similarity index 100% rename from unittest_to_pytest/repo-after/jj_classes/__init__.py rename to unittest_to_pytest/input_repo/jj_classes/__init__.py diff --git a/unittest_to_pytest/repo-after/jj_classes/castle.py b/unittest_to_pytest/input_repo/jj_classes/castle.py similarity index 99% rename from unittest_to_pytest/repo-after/jj_classes/castle.py rename to unittest_to_pytest/input_repo/jj_classes/castle.py index cb95a69..7812ab3 100644 --- a/unittest_to_pytest/repo-after/jj_classes/castle.py +++ b/unittest_to_pytest/input_repo/jj_classes/castle.py @@ -1,5 +1,6 @@ # jj_classes/castle.py + class Castle: """Defines the Castle class.""" diff --git a/unittest_to_pytest/repo-after/jj_classes/character.py b/unittest_to_pytest/input_repo/jj_classes/character.py similarity index 99% rename from unittest_to_pytest/repo-after/jj_classes/character.py rename to unittest_to_pytest/input_repo/jj_classes/character.py index 53226be..30edf8b 100644 --- a/unittest_to_pytest/repo-after/jj_classes/character.py +++ b/unittest_to_pytest/input_repo/jj_classes/character.py @@ -1,5 +1,6 @@ # jj_classes/character.py + class Character: """Defines the Character class.""" diff --git a/unittest_to_pytest/repo-before/run_tests.py b/unittest_to_pytest/input_repo/run_tests.py similarity index 100% rename from unittest_to_pytest/repo-before/run_tests.py rename to unittest_to_pytest/input_repo/run_tests.py diff --git a/unittest_to_pytest/repo-before/jj_classes/__init__.py b/unittest_to_pytest/input_repo/tests/__init__.py similarity index 100% rename from unittest_to_pytest/repo-before/jj_classes/__init__.py rename to unittest_to_pytest/input_repo/tests/__init__.py diff --git a/unittest_to_pytest/repo-before/tests/test_classes.py b/unittest_to_pytest/input_repo/tests/test_classes.py similarity index 100% rename from unittest_to_pytest/repo-before/tests/test_classes.py rename to unittest_to_pytest/input_repo/tests/test_classes.py diff --git a/unittest_to_pytest/repo-before/tests/__init__.py b/unittest_to_pytest/output_repo/jj_classes/__init__.py similarity index 100% rename from unittest_to_pytest/repo-before/tests/__init__.py rename to unittest_to_pytest/output_repo/jj_classes/__init__.py diff --git a/unittest_to_pytest/repo-before/jj_classes/castle.py b/unittest_to_pytest/output_repo/jj_classes/castle.py similarity index 99% rename from unittest_to_pytest/repo-before/jj_classes/castle.py rename to unittest_to_pytest/output_repo/jj_classes/castle.py index cb95a69..7812ab3 100644 --- a/unittest_to_pytest/repo-before/jj_classes/castle.py +++ b/unittest_to_pytest/output_repo/jj_classes/castle.py @@ -1,5 +1,6 @@ # jj_classes/castle.py + class Castle: """Defines the Castle class.""" diff --git a/unittest_to_pytest/repo-before/jj_classes/character.py b/unittest_to_pytest/output_repo/jj_classes/character.py similarity index 99% rename from unittest_to_pytest/repo-before/jj_classes/character.py rename to unittest_to_pytest/output_repo/jj_classes/character.py index 53226be..30edf8b 100644 --- a/unittest_to_pytest/repo-before/jj_classes/character.py +++ b/unittest_to_pytest/output_repo/jj_classes/character.py @@ -1,5 +1,6 @@ # jj_classes/character.py + class Character: """Defines the Character class.""" diff --git a/unittest_to_pytest/repo-after/tests/__init__.py b/unittest_to_pytest/output_repo/tests/__init__.py similarity index 100% rename from unittest_to_pytest/repo-after/tests/__init__.py rename to unittest_to_pytest/output_repo/tests/__init__.py diff --git a/unittest_to_pytest/repo-after/tests/test_classes.py b/unittest_to_pytest/output_repo/tests/test_classes.py similarity index 98% rename from unittest_to_pytest/repo-after/tests/test_classes.py rename to unittest_to_pytest/output_repo/tests/test_classes.py index 8de04e0..7e2d7e2 100644 --- a/unittest_to_pytest/repo-after/tests/test_classes.py +++ b/unittest_to_pytest/output_repo/tests/test_classes.py @@ -7,13 +7,12 @@ from jj_classes.character import Character -class TestCastle(): +class TestCastle: """Tests for the Castle class.""" + @pytest.fixture def setup_testcastle(): castle = Castle("Test Castle") - - def test_castle_name(setup_testcastle, Castle): """Test that the castle name is set correctly.""" @@ -43,13 +42,12 @@ def test_empty_name_raises_error(setup_testcastle, Castle): Castle("") -class TestCharacter(): +class TestCharacter: """Tests for the Character class.""" + @pytest.fixture def setup_testcharacter(): character = Character("Mario") - - def test_character_name(setup_testcharacter, Character): """Test that the character name is set correctly.""" @@ -72,11 +70,10 @@ def test_empty_name_raises_error(setup_testcharacter, Character): class TestCastleAndCharacter(unittest.TestCase): """Tests for the interaction between Castle and Character.""" + @pytest.fixture def setup_testcastleandcharacter(): character = Character("Mario") - - def test_character_has_access(setup_testcastleandcharacter, Character): """Test that a character with the correct powerup has access.""" diff --git a/useSuspenseQuery_to_useSuspenseQueries/run.py b/useSuspenseQuery_to_useSuspenseQueries/run.py index 57ce497..09a7e69 100644 --- a/useSuspenseQuery_to_useSuspenseQueries/run.py +++ b/useSuspenseQuery_to_useSuspenseQueries/run.py @@ -54,9 +54,7 @@ def run(codebase: Codebase): # Convert to useSuspenseQueries if needed if old_statements: new_query = f"const [{', '.join(results)}] = useSuspenseQueries({{queries: [{', '.join(queries)}]}})" - print( - f"Converting useSuspenseQuery to useSuspenseQueries in {function.name}" - ) + print(f"Converting useSuspenseQuery to useSuspenseQueries in {function.name}") # Print the diff print("\nOriginal code:")