Skip to content

Commit 5a84dbb

Browse files
Mock & Stubbing done
1 parent b3dc9d7 commit 5a84dbb

File tree

7 files changed

+747
-113
lines changed

7 files changed

+747
-113
lines changed

courseProjectDocs/Unit-Testing/README.md

Lines changed: 99 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,11 @@ python -m pytest \
9999
## Expected Test Results
100100

101101
When you run the tests, you should see:
102-
103-
- **Total Tests:** 15
104-
- **Tests Passed:** 15
105-
- **Tests Failed:** 0
106-
- **Success Rate:** 100%
107-
- **Execution Time:** ~1.04 seconds
102+
- **Total Tests**: 15
103+
- **Tests Passed**: 15
104+
- **Tests Failed**: 0
105+
- **Success Rate**: 100%
106+
- **Execution Time**: ~1.04 seconds
108107

109108
**Sample Output:**
110109
```
@@ -117,16 +116,16 @@ pandas/tests/test_nanops_additional.py::test_nanmean_mask_edge_cases PASSED
117116
pandas/tests/test_nanops_additional.py::test_nanvar_ddof_boundary_conditions PASSED
118117
pandas/tests/test_nanops_additional.py::test_nanargmax_nanargmin_error_conditions PASSED
119118
pandas/tests/test_nanops_additional.py::test_nanskew_nankurt_insufficient_samples PASSED
120-
pandas/tests/test_series_constructors_additional.py::test_series_constructor_invalid_key_types PASSED [ 7%]
121-
pandas/tests/test_series_constructors_additional.py::test_series_constructor_empty_edge_cases PASSED [ 8%]
122-
pandas/tests/test_series_constructors_additional.py::test_series_constructor_mixed_dtype_edge_cases PASSED [ 9%]
123-
pandas/tests/test_series_constructors_additional.py::test_series_constructor_memory_intensive PASSED [ 10%]
124-
pandas/tests/test_series_constructors_additional.py::test_series_constructor_invalid_index_length PASSED [ 11%]
125-
pandas/tests/tseries/offsets/test_offsets.py::test_dateoffset_boundary_values PASSED [ 12%]
126-
pandas/tests/tseries/offsets/test_offsets.py::test_business_day_weekend_edge_cases PASSED [ 13%]
127-
pandas/tests/tseries/offsets/test_offsets.py::test_custom_business_hour_edge_cases PASSED [ 14%]
128-
pandas/tests/tseries/offsets/test_offsets.py::test_quarter_offset_leap_year PASSED [ 15%]
129-
pandas/tests/tseries/offsets/test_offsets.py::test_offset_frequency_string_edge_cases PASSED [ 16%]
119+
pandas/tests/test_series_constructors_additional.py::test_series_constructor_invalid_key_types PASSED
120+
pandas/tests/test_series_constructors_additional.py::test_series_constructor_empty_edge_cases PASSED
121+
pandas/tests/test_series_constructors_additional.py::test_series_constructor_mixed_dtype_edge_cases PASSED
122+
pandas/tests/test_series_constructors_additional.py::test_series_constructor_memory_intensive PASSED
123+
pandas/tests/test_series_constructors_additional.py::test_series_constructor_invalid_index_length PASSED
124+
pandas/tests/tseries/offsets/test_offsets.py::test_dateoffset_boundary_values PASSED
125+
pandas/tests/tseries/offsets/test_offsets.py::test_business_day_weekend_edge_cases PASSED
126+
pandas/tests/tseries/offsets/test_offsets.py::test_custom_business_hour_edge_cases PASSED
127+
pandas/tests/tseries/offsets/test_offsets.py::test_quarter_offset_leap_year PASSED
128+
pandas/tests/tseries/offsets/test_offsets.py::test_offset_frequency_string_edge_cases PASSED
130129
131130
============================== 15 passed in 1.04s ==============================
132131
```
@@ -135,7 +134,6 @@ pandas/tests/tseries/offsets/test_offsets.py::test_offset_frequency_string_edge_
135134

136135
### Comprehensive Coverage Command
137136
To run both baseline and additional tests for complete coverage analysis:
138-
139137
```bash
140138
python -m pytest \
141139
pandas/tests/series/test_constructors.py \
@@ -154,76 +152,107 @@ python -m pytest \
154152
```
155153

156154
### Coverage Report Location
157-
- **HTML Report:** `courseProjectDocs/Setup/htmlcov/index.html`
158-
- **Terminal Output:** Displayed during test execution
159-
- **Expected Coverage:** 11% overall (improvement from ~10% baseline)
155+
- **HTML Report**: `courseProjectDocs/Setup/htmlcov/index.html`
156+
- **Terminal Output**: Displayed during test execution
157+
- **Expected Coverage**: 11% overall (improvement from ~10% baseline)
160158

161-
## Troubleshooting
159+
## Unit Testing II - Mocking & Stubbing Tests
162160

163-
### Common Issues and Solutions
161+
### Additional Mocking Tests (NEW)
164162

165-
1. **Environment Setup**
166-
- Ensure virtual environment is activated
167-
- Verify Python 3.13+ installation
168-
- Check pandas development build installation
163+
In addition to the original 15 unit tests above, we have added 15 mocking-based tests for Unit Testing II assignment:
169164

170-
2. **Test Execution Problems**
171-
- Clear pytest cache: `python -m pytest --cache-clear`
172-
- Run tests individually if batch execution fails
173-
- Check for import conflicts
174-
175-
3. **Coverage Report Issues**
176-
- Ensure output directory exists: `mkdir -p courseProjectDocs/Setup/htmlcov`
177-
- Run with verbose output: `--cov-report=term-missing`
165+
**New Test Files:**
166+
1. **`pandas/tests/mocking/test_database_io.py`** - 5 tests for database I/O operations
167+
2. **`pandas/tests/mocking/test_filesystem_io.py`** - 5 tests for file system I/O operations
168+
3. **`pandas/tests/mocking/test_datetime.py`** - 5 tests for datetime/time-series operations
178169

170+
### Prerequisites for Mocking Tests
171+
Before running the mocking tests, ensure you have:
172+
- All prerequisites from above
173+
- **pytest-mock 3.15.1+** (NEW REQUIREMENT)
179174

175+
```bash
176+
# Install pytest-mock if not already installed
177+
pip install pytest-mock
178+
```
180179

181-
## Project Team Information
182-
183-
**Course:** SWEN 777 - Software Testing and Quality Assurance
184-
**Project:** Pandas Unit Testing Extension
185-
**Team Members:**
186-
- Nithikesh Reddy
187-
- Sandeep
188-
- Malikarjuna
180+
### Running Mocking Tests
189181

182+
#### Run All 15 Mocking Tests
183+
```bash
184+
# Run all mocking tests with verbose output
185+
pytest pandas/tests/mocking/ -v
186+
```
190187

191-
## Results
188+
**Expected Output:**
189+
```
190+
============================= test session starts ==============================
191+
platform darwin -- Python 3.13.5, pytest-8.4.2, pluggy-1.6.0
192+
collected 15 items
192193
193-
- **Test Execution:** All 15 tests should pass
194-
- **Coverage Improvement:** From ~10% to 11% overall coverage
195-
- **New Code Coverage:** 100% coverage for added test functions
196-
- pytest-cov 7.0.0+ (for coverage analysis)
197-
- numpy
198-
- Virtual environment recommended
194+
pandas/tests/mocking/test_database_io.py::TestDatabaseIOMocking::test_read_sql_basic PASSED
195+
pandas/tests/mocking/test_database_io.py::TestDatabaseIOMocking::test_read_sql_empty_result PASSED
196+
pandas/tests/mocking/test_database_io.py::TestDatabaseIOMocking::test_read_sql_with_parameters PASSED
197+
pandas/tests/mocking/test_database_io.py::TestDatabaseIOMocking::test_read_sql_dtype_handling PASSED
198+
pandas/tests/mocking/test_database_io.py::TestDatabaseIOMocking::test_read_sql_connection_error_handling PASSED
199+
pandas/tests/mocking/test_datetime.py::TestDateTimeOperationsMocking::test_timestamp_now_mocked PASSED
200+
pandas/tests/mocking/test_datetime.py::TestDateTimeOperationsMocking::test_date_range_generation PASSED
201+
pandas/tests/mocking/test_datetime.py::TestDateTimeOperationsMocking::test_time_series_resampling PASSED
202+
pandas/tests/mocking/test_datetime.py::TestDateTimeOperationsMocking::test_rolling_window_operations PASSED
203+
pandas/tests/mocking/test_datetime.py::TestDateTimeOperationsMocking::test_datetime_parsing_with_format PASSED
204+
pandas/tests/mocking/test_filesystem_io.py::TestFileSystemIOMocking::test_read_csv_basic PASSED
205+
pandas/tests/mocking/test_filesystem_io.py::TestFileSystemIOMocking::test_read_csv_with_delimiter PASSED
206+
pandas/tests/mocking/test_filesystem_io.py::TestFileSystemIOMocking::test_read_excel_basic PASSED
207+
pandas/tests/mocking/test_filesystem_io.py::TestFileSystemIOMocking::test_read_hdf_basic PASSED
208+
pandas/tests/mocking/test_filesystem_io.py::TestFileSystemIOMocking::test_csv_file_not_found_handling PASSED
209+
210+
============================== 15 passed in 0.83s ==============================
211+
```
199212

200-
## Setting Up Test Environment
213+
#### Run Mocking Tests by Category
214+
```bash
215+
# Database I/O tests
216+
pytest pandas/tests/mocking/test_database_io.py -v
201217

202-
1. Create and activate a virtual environment
203-
2. Install development dependencies from requirements-dev.txt
204-
3. Build pandas in development mode
218+
# File System I/O tests
219+
pytest pandas/tests/mocking/test_filesystem_io.py -v
205220

206-
## Coverage Analysis
221+
# DateTime operations tests
222+
pytest pandas/tests/mocking/test_datetime.py -v
223+
```
207224

208-
To analyze coverage improvements from these tests, use pytest with coverage flags targeting the specific modules (pandas.core.nanops, pandas.core.series, pandas.tseries.offsets) and generate both HTML and terminal reports.
225+
#### Generate Mocking Test Coverage Report
226+
```bash
227+
# Generate coverage report for mocking test code
228+
pytest pandas/tests/mocking/ --cov=pandas/tests/mocking --cov-report=term
229+
230+
# Expected output:
231+
# Name Stmts Miss Branch BrPart Cover
232+
# --------------------------------------------------------------------------------
233+
# pandas/tests/mocking/__init__.py 0 0 0 0 100%
234+
# pandas/tests/mocking/test_database_io.py 44 0 0 0 100%
235+
# pandas/tests/mocking/test_datetime.py 70 10 8 3 81%
236+
# pandas/tests/mocking/test_filesystem_io.py 45 1 2 1 96%
237+
# --------------------------------------------------------------------------------
238+
# TOTAL 159 11 10 4 90%
239+
```
209240

210-
## Test Design Principles
211-
All added tests follow these principles:
212-
1. **Edge Case Focus:** Target boundary conditions and unusual inputs
213-
2. **Error Handling:** Test exception conditions and error paths
214-
3. **Uncovered Logic:** Address gaps identified in coverage analysis
215-
4. **Maintainability:** Clear naming and comprehensive documentation
216-
5. **Integration:** Seamlessly integrate with existing test structure
241+
### Mocking Test Results Summary
242+
- **Total Mocking Tests**: 15
243+
- **Passed**: 15 (100%)
244+
- **Failed**: 0
245+
- **Execution Time**: 0.83 seconds
246+
- **Test Code Coverage**: 90%
217247

218-
## Files Modified
248+
For detailed mocking strategy and design decisions, see: `courseProjectDocs/Unit-Testing/mocking.md`
219249

220-
1. `pandas/tests/test_nanops.py` - Added 5 test functions (lines ~1280-1340)
221-
2. `pandas/tests/series/test_constructors.py` - Added 5 test functions (lines ~890-970)
222-
3. `pandas/tests/tseries/offsets/test_offsets.py` - Added 5 test functions (lines ~1235-1310)
223250

224-
## Group Members
251+
## Project Team Information
225252

226-
- Member 1: Nanops module test cases (5 tests)
227-
- Member 2: Series constructor test cases (5 tests)
228-
- Member 3: DateTime offset test cases (5 tests)
253+
**Course:** SWEN 777 - Software Testing and Quality Assurance
254+
**Team Members:**
255+
- Nithikesh Reddy
256+
- Sandeep
257+
- Malikarjuna
229258

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/Volumes/T7Shield/SWEN777/SWEN_777_Pandas/venv/lib/python3.13/site-packages/pytest_cython/__init__.py:2: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
2+
from pkg_resources import get_distribution
3+
[1/1] Generating write_version_file with a custom command
4+
+ /Volumes/T7Shield/SWEN777/SWEN_777_Pandas/venv/bin/ninja
5+
============================= test session starts ==============================
6+
platform darwin -- Python 3.13.5, pytest-8.4.2, pluggy-1.6.0 -- /Volumes/T7Shield/SWEN777/SWEN_777_Pandas/venv/bin/python3.13
7+
cachedir: .pytest_cache
8+
hypothesis profile 'pandas_ci' -> database=None, deadline=None, max_examples=15, suppress_health_check=(HealthCheck.too_slow, HealthCheck.differing_executors)
9+
PyQt5 5.15.11 -- Qt runtime 5.15.17 -- Qt compiled 5.15.14
10+
rootdir: /Volumes/T7Shield/SWEN777/SWEN_777_Pandas
11+
configfile: pyproject.toml
12+
plugins: anyio-4.11.0, hypothesis-6.140.3, cov-7.0.0, cython-0.3.1, localserver-0.9.0.post0, mock-3.15.1, qt-4.5.0, xdist-3.8.0
13+
collecting ... collected 15 items
14+
15+
pandas/tests/mocking/test_database_io.py::TestDatabaseIOMocking::test_read_sql_basic PASSED
16+
pandas/tests/mocking/test_database_io.py::TestDatabaseIOMocking::test_read_sql_empty_result PASSED
17+
pandas/tests/mocking/test_database_io.py::TestDatabaseIOMocking::test_read_sql_with_parameters PASSED
18+
pandas/tests/mocking/test_database_io.py::TestDatabaseIOMocking::test_read_sql_dtype_handling PASSED
19+
pandas/tests/mocking/test_database_io.py::TestDatabaseIOMocking::test_read_sql_connection_error_handling PASSED
20+
pandas/tests/mocking/test_datetime.py::TestDateTimeOperationsMocking::test_timestamp_now_mocked PASSED
21+
pandas/tests/mocking/test_datetime.py::TestDateTimeOperationsMocking::test_date_range_generation PASSED
22+
pandas/tests/mocking/test_datetime.py::TestDateTimeOperationsMocking::test_time_series_resampling PASSED
23+
pandas/tests/mocking/test_datetime.py::TestDateTimeOperationsMocking::test_rolling_window_operations PASSED
24+
pandas/tests/mocking/test_datetime.py::TestDateTimeOperationsMocking::test_datetime_parsing_with_format PASSED
25+
pandas/tests/mocking/test_filesystem_io.py::TestFileSystemIOMocking::test_read_csv_basic PASSED
26+
pandas/tests/mocking/test_filesystem_io.py::TestFileSystemIOMocking::test_read_csv_with_delimiter PASSED
27+
pandas/tests/mocking/test_filesystem_io.py::TestFileSystemIOMocking::test_read_excel_basic PASSED
28+
pandas/tests/mocking/test_filesystem_io.py::TestFileSystemIOMocking::test_read_hdf_basic PASSED
29+
pandas/tests/mocking/test_filesystem_io.py::TestFileSystemIOMocking::test_csv_file_not_found_handling PASSED
30+
31+
- generated xml file: /Volumes/T7Shield/SWEN777/SWEN_777_Pandas/test-data.xml --
32+
============================= slowest 30 durations =============================
33+
34+
(30 durations < 0.005s hidden. Use -vv to show these durations.)
35+
============================== 15 passed in 0.83s ==============================

0 commit comments

Comments
 (0)