Assignment 3: Package + Test#

Course: 06-643 Scientific Software Engineering with AI Coding Agents

Topics covered: L04 (Python Packaging), L05 (Testing with AI)

In this assignment you will take the scholartools code from Assignment 2 and turn it into a properly structured Python package with comprehensive tests. You will use an AI coding agent to help write tests and then critically evaluate what the AI missed. The assignment has two components: a technical component (Parts 1–3) and a reflection (Part 4).

Part 1: Package Structure#

Take your scholartools code from Assignment 2 and organize it into a proper Python package with the following structure:

scholartools/
├── pyproject.toml          # Project metadata, dependencies, and project URLs
├── README.md               # Installation and usage instructions
├── src/
│   └── scholartools/
│       ├── __init__.py     # Version and public API imports
│       ├── api.py          # API functions (search_works, get_author, etc.)
│       └── metrics.py      # calculate_h_index(citation_counts) function
└── tests/
    ├── test_api.py         # Tests for API functions
    └── test_metrics.py     # Tests for h-index calculation

Requirements:

  • pyproject.toml should include project metadata (name, version, description, author), dependencies, and project URLs (e.g., repository link).

  • src/scholartools/__init__.py should define __version__ and import the public API so users can do from scholartools import search_works, calculate_h_index, etc.

  • src/scholartools/api.py should contain your API functions from Assignment 2.

  • src/scholartools/metrics.py should contain a function calculate_h_index(citation_counts) that computes the h-index from a list of citation counts.

  • README.md should explain how to install and use the package.

Install the package in editable mode and demonstrate it works.

Show your directory structure#

Use tree or find to display the layout of your package.

# Show your package directory structure
# !tree /path/to/scholartools
# or
# !find /path/to/scholartools -type f | head -20

Install in editable mode and demonstrate usage#

# Install your package in editable mode
# !pip install -e /path/to/scholartools
# Demonstrate that the package imports correctly
# Your code here
# Demonstrate an API function (e.g., search_works)
# Your code here
# Demonstrate calculate_h_index with a sample list of citation counts
# Your code here

Part 2: AI-Assisted Testing#

Use an AI coding agent to help you write tests for your package. You should end up with two test files:

  • tests/test_api.py — tests for the API functions. Use mocking (e.g., unittest.mock.patch) for network calls so tests run without internet access.

  • tests/test_metrics.py — tests for the calculate_h_index function with known input/output pairs.

Your tests should cover:

  • Normal operation — typical inputs produce expected outputs.

  • Edge cases — empty inputs, single-element lists, all-zero citations, etc.

  • Error handling — invalid data types, negative numbers, network errors (for API tests).

Run pytest and show the output. Aim for >90% coverage.

# Run pytest and show results
# !cd /path/to/scholartools && pytest -v
# Run pytest with coverage report
# !cd /path/to/scholartools && pytest --cov=scholartools

Part 3: Testing Edge Cases#

Review the tests the AI generated. Identify at least 3 edge cases that the AI did not initially test for. Write those tests yourself (or prompt the AI more specifically to generate them).

Examples of commonly missed edge cases:

  • Very large citation counts or very long lists

  • Duplicate citation values and how they affect the h-index

  • Non-integer inputs (floats, strings mixed in)

  • API responses with missing or unexpected fields

  • Rate limiting or timeout behavior

Describe each edge case, why it matters, and show the test.

Edge Case 1#

Description: (What is the edge case and why does it matter?)

# Your test for edge case 1
# Your code here

Edge Case 2#

Description: (What is the edge case and why does it matter?)

# Your test for edge case 2
# Your code here

Edge Case 3#

Description: (What is the edge case and why does it matter?)

# Your test for edge case 3
# Your code here
# Show updated coverage report after adding your edge case tests
# !cd /path/to/scholartools && pytest --cov=scholartools

Part 4: Reflection#

1. How did you structure your prompts to get good tests from the AI?#

Your response here.

2. What edge cases did the AI miss? Why do you think it missed them?#

Your response here.

3. What did you learn about your own code by writing tests for it?#

Your response here.

4. How did packaging your code change your approach to organizing it?#

Your response here.