-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: remove assert statement from non-test files #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,7 +112,8 @@ def test_model_calibration(): | |
| # Test temperature setting | ||
| logger.info("Testing temperature calibration...") | ||
| model.temperature.data.fill_(1.0) | ||
| assert model.temperature.item() == 1.0, "Temperature not set correctly" | ||
| if model.temperature.item() != 1.0: | ||
| raise AssertionError("Temperature not set correctly") | ||
| logger.info("✅ Temperature calibration works") | ||
|
|
||
| # Create test data | ||
|
|
@@ -156,8 +157,10 @@ def test_model_calibration(): | |
| logger.info(f"Macro F1: {macro_f1:.4f}") | ||
|
|
||
| # Basic validation | ||
| assert 0 <= micro_f1 <= 1, f"Invalid F1 score: {micro_f1}" | ||
| assert 0 <= macro_f1 <= 1, f"Invalid F1 score: {macro_f1}" | ||
| if not 0 <= micro_f1 <= 1: | ||
| raise AssertionError(f"Invalid F1 score: {micro_f1}") | ||
| if not 0 <= macro_f1 <= 1: | ||
| raise AssertionError(f"Invalid F1 score: {macro_f1}") | ||
|
Comment on lines
+160
to
+163
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These checks should use assert 0 <= micro_f1 <= 1, f"Invalid F1 score: {micro_f1}"
assert 0 <= macro_f1 <= 1, f"Invalid F1 score: {macro_f1}" |
||
|
|
||
| logger.info("✅ Metrics calculation works") | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,9 +133,12 @@ def test_model_compression(): | |
| logger.info(f"Inference speedup: {speedup:.2f}x") | ||
|
|
||
| # Basic validation | ||
| assert quantized_size < original_size, f"Quantized model should be smaller: {quantized_size} >= {original_size}" | ||
| assert size_reduction > 0, f"Size reduction should be positive: {size_reduction}" | ||
| assert speedup > 0, f"Speedup should be positive: {speedup}" | ||
| if quantized_size >= original_size: | ||
| raise AssertionError(f"Quantized model should be smaller: {quantized_size} >= {original_size}") | ||
| if size_reduction <= 0: | ||
| raise AssertionError(f"Size reduction should be positive: {size_reduction}") | ||
| if speedup <= 0: | ||
| raise AssertionError(f"Speedup should be positive: {speedup}") | ||
|
Comment on lines
+136
to
+141
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this is a test file, these validations should be written using assert quantized_size < original_size, f"Quantized model should be smaller: {quantized_size} >= {original_size}"
assert size_reduction > 0, f"Size reduction should be positive: {size_reduction}"
assert speedup > 0, f"Speedup should be positive: {speedup}" |
||
|
|
||
| # Test model saving | ||
| logger.info("Testing model saving...") | ||
|
|
@@ -152,7 +155,8 @@ def test_model_compression(): | |
| }, output_path) | ||
|
|
||
| # Verify file was created | ||
| assert output_path.exists(), f"Compressed model file not created: {output_path}" | ||
| if not output_path.exists(): | ||
| raise AssertionError(f"Compressed model file not created: {output_path}") | ||
|
Comment on lines
+158
to
+159
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| logger.info(f"✅ Compressed model saved to {output_path}") | ||
|
|
||
| # Clean up | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,12 +71,15 @@ def test_performance_tracker(): | |
|
|
||
| # Test current performance | ||
| current_perf = tracker.get_current_performance() | ||
| assert "f1_score" in current_perf | ||
| assert current_perf["f1_score"] == 0.75 | ||
| if "f1_score" not in current_perf: | ||
| raise AssertionError | ||
| if current_perf["f1_score"] != 0.75: | ||
| raise AssertionError | ||
|
Comment on lines
+74
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change significantly degrades the test's utility. By replacing assert "f1_score" in current_perf
assert current_perf["f1_score"] == 0.75 |
||
|
|
||
| # Test trend analysis | ||
| trend = tracker.get_trend_analysis() | ||
| assert "insufficient_data" in trend | ||
| if "insufficient_data" not in trend: | ||
| raise AssertionError | ||
|
Comment on lines
+81
to
+82
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| # Test degradation detection | ||
| degradation_alert = tracker.detect_degradation() | ||
|
|
@@ -121,7 +124,8 @@ def test_drift_detector(): | |
|
|
||
| drift_metrics = detector.detect_drift(current_data) | ||
| assert isinstance(drift_metrics, DriftMetrics) | ||
| assert not drift_metrics.drift_detected | ||
| if drift_metrics.drift_detected: | ||
| raise AssertionError | ||
|
Comment on lines
+127
to
+128
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is detrimental to test debugging as it raises an assert not drift_metrics.drift_detected |
||
|
|
||
| # Test with drifted data | ||
| drifted_data = pd.DataFrame( | ||
|
|
@@ -161,10 +165,14 @@ def test_alert_system(): | |
| ) | ||
|
|
||
| # Test alert properties | ||
| assert alert.alert_type == "TEST_ALERT" | ||
| assert alert.severity == "MEDIUM" | ||
| assert alert.message == "Test alert message" | ||
| assert not alert.action_required | ||
| if alert.alert_type != "TEST_ALERT": | ||
| raise AssertionError | ||
| if alert.severity != "MEDIUM": | ||
| raise AssertionError | ||
| if alert.message != "Test alert message": | ||
| raise AssertionError | ||
| if alert.action_required: | ||
| raise AssertionError | ||
|
Comment on lines
+168
to
+175
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replacing this block of assert alert.alert_type == "TEST_ALERT"
assert alert.severity == "MEDIUM"
assert alert.message == "Test alert message"
assert not alert.action_required |
||
|
|
||
| # Test alert serialization | ||
| alert_dict = { | ||
|
|
@@ -201,7 +209,8 @@ def test_config_creation(): | |
|
|
||
| # Check if config file was created | ||
| config_path = Path(test_config_path) | ||
| assert config_path.exists() | ||
| if not config_path.exists(): | ||
| raise AssertionError | ||
|
Comment on lines
+212
to
+213
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| # Load and validate config | ||
| import yaml | ||
|
|
@@ -210,10 +219,14 @@ def test_config_creation(): | |
| config = yaml.safe_load(f) | ||
|
|
||
| # Check required fields | ||
| assert "model_path" in config | ||
| assert "window_size" in config | ||
| assert "monitor_interval" in config | ||
| assert "alert_threshold" in config | ||
| if "model_path" not in config: | ||
| raise AssertionError | ||
| if "window_size" not in config: | ||
| raise AssertionError | ||
| if "monitor_interval" not in config: | ||
| raise AssertionError | ||
| if "alert_threshold" not in config: | ||
| raise AssertionError | ||
|
Comment on lines
+222
to
+229
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block of checks is another example where replacing assert "model_path" not in config
assert "window_size" not in config
assert "monitor_interval" not in config
assert "alert_threshold" not in config |
||
|
|
||
| # Clean up | ||
| config_path.unlink() | ||
|
|
@@ -254,15 +267,21 @@ def test_monitoring_initialization(): | |
| monitor = ModelHealthMonitor(test_config_path) | ||
|
|
||
| # Test basic properties | ||
| assert monitor.config["window_size"] == 10 | ||
| assert monitor.config["alert_threshold"] == 0.1 | ||
| assert not monitor.monitoring_active | ||
| if monitor.config["window_size"] != 10: | ||
| raise AssertionError | ||
| if monitor.config["alert_threshold"] != 0.1: | ||
| raise AssertionError | ||
| if monitor.monitoring_active: | ||
| raise AssertionError | ||
|
Comment on lines
+270
to
+275
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These property checks are part of a test and should use assert monitor.config["window_size"] == 10
assert monitor.config["alert_threshold"] == 0.1
assert not monitor.monitoring_active |
||
|
|
||
| # Test health status | ||
| health_status = monitor.get_health_status() | ||
| assert "timestamp" in health_status | ||
| assert "model_loaded" in health_status | ||
| assert "monitoring_active" in health_status | ||
| if "timestamp" not in health_status: | ||
| raise AssertionError | ||
| if "model_loaded" not in health_status: | ||
| raise AssertionError | ||
| if "monitoring_active" not in health_status: | ||
| raise AssertionError | ||
|
Comment on lines
+279
to
+284
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These health status checks should use assert "timestamp" in health_status
assert "model_loaded" in health_status
assert "monitoring_active" in health_status |
||
|
|
||
| # Clean up | ||
| Path(test_config_path).unlink() | ||
|
|
@@ -295,13 +314,20 @@ def test_metrics_collection(): | |
| ) | ||
|
|
||
| # Test metrics properties | ||
| assert metrics.f1_score == 0.75 | ||
| assert metrics.precision == 0.78 | ||
| assert metrics.recall == 0.72 | ||
| assert metrics.inference_time_ms == 150.0 | ||
| assert metrics.throughput_rps == 33.3 | ||
| assert metrics.memory_usage_mb == 512.0 | ||
| assert metrics.gpu_utilization == 45.0 | ||
| if metrics.f1_score != 0.75: | ||
| raise AssertionError | ||
| if metrics.precision != 0.78: | ||
| raise AssertionError | ||
| if metrics.recall != 0.72: | ||
| raise AssertionError | ||
| if metrics.inference_time_ms != 150.0: | ||
| raise AssertionError | ||
| if metrics.throughput_rps != 33.3: | ||
| raise AssertionError | ||
| if metrics.memory_usage_mb != 512.0: | ||
| raise AssertionError | ||
| if metrics.gpu_utilization != 45.0: | ||
| raise AssertionError | ||
|
Comment on lines
+317
to
+330
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This large block of assert metrics.f1_score == 0.75
assert metrics.precision == 0.78
assert metrics.recall == 0.72
assert metrics.inference_time_ms == 150.0
assert metrics.throughput_rps == 33.3
assert metrics.memory_usage_mb == 512.0
assert metrics.gpu_utilization == 45.0 |
||
|
|
||
| # Test metrics serialization | ||
| metrics_dict = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,9 +34,12 @@ def test_t5_model_loading(): | |
| logger.info("✅ T5 model initialized successfully") | ||
|
|
||
| # Test basic model properties | ||
| assert hasattr(model, "model"), "Model should have 'model' attribute" | ||
| assert hasattr(model, "tokenizer"), "Model should have 'tokenizer' attribute" | ||
| assert hasattr(model, "device"), "Model should have 'device' attribute" | ||
| if not hasattr(model, "model"): | ||
| raise AssertionError("Model should have 'model' attribute") | ||
| if not hasattr(model, "tokenizer"): | ||
| raise AssertionError("Model should have 'tokenizer' attribute") | ||
| if not hasattr(model, "device"): | ||
| raise AssertionError("Model should have 'device' attribute") | ||
|
Comment on lines
+37
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These checks for model attributes are in a test function and should use assert hasattr(model, "model"), "Model should have 'model' attribute"
assert hasattr(model, "tokenizer"), "Model should have 'tokenizer' attribute"
assert hasattr(model, "device"), "Model should have 'device' attribute" |
||
|
|
||
| logger.info("✅ Model attributes validation passed") | ||
|
|
||
|
|
@@ -71,7 +74,8 @@ def test_t5_summarization(): | |
|
|
||
| # Validate summary | ||
| assert isinstance(summary, str), "Summary should be a string" | ||
| assert len(summary) > 0, "Summary should not be empty" | ||
| if len(summary) <= 0: | ||
| raise AssertionError("Summary should not be empty") | ||
|
Comment on lines
+77
to
+78
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change should be reverted. assert len(summary) > 0, "Summary should not be empty" |
||
| assert len(summary) < len(test_text), "Summary should be shorter than input" | ||
|
|
||
| logger.info("✅ Summary validation passed") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In test files,
assertstatements are preferred overif/raise AssertionError. Test frameworks likepytestuseassertto provide detailed failure reports, including the values of variables in the asserted expression. This change removes that benefit, making test failures harder to debug.