-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix using wrong index in from_csv_row (#15802)
# Overview I accidentally specified the same index multiple times when hardcoding from_csv_row. Since hardcoding in this case is a no-no fix it by using built-in dataclass methods to look up headers and converting to/from csv. # Test Plan - Added unit tests that fail before fix was implemented due to hard coding - Added unit tests that ensure ordering of converted data. Although this tests the dataclass package more than it is testing our software, it is still helpful to have this because the docs aren't super clear about if the order is maintained # Changelog - Create a CSVStorageBase dataclass that contains shared methods - Have RawActivityData and ProcessResourceUsageSnapshot inherit from CSVStorageBase # Review requests Is it weird having a blank dataclass as a base? I was having trouble when trying to use an ABC. # Risk assessment The lowest of lows
- Loading branch information
1 parent
39297bb
commit a477f16
Showing
6 changed files
with
124 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
performance-metrics/tests/performance_metrics/test_data_shapes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Tests for the data shapes.""" | ||
|
||
from performance_metrics._data_shapes import ProcessResourceUsageSnapshot | ||
|
||
|
||
def test_headers_ordering() -> None: | ||
"""Tests that the headers are in the correct order.""" | ||
assert ProcessResourceUsageSnapshot.headers() == ( | ||
"query_time", | ||
"command", | ||
"running_since", | ||
"user_cpu_time", | ||
"system_cpu_time", | ||
"memory_percent", | ||
) | ||
|
||
|
||
def test_csv_row_method_ordering() -> None: | ||
"""Tests that the CSV row method returns the correct order.""" | ||
expected = ( | ||
1, | ||
"test", | ||
2, | ||
3, | ||
4, | ||
5, | ||
) | ||
|
||
assert ( | ||
ProcessResourceUsageSnapshot( | ||
query_time=1, | ||
command="test", | ||
running_since=2, | ||
user_cpu_time=3, | ||
system_cpu_time=4, | ||
memory_percent=5, | ||
).csv_row() | ||
== expected | ||
) | ||
|
||
assert ( | ||
ProcessResourceUsageSnapshot( | ||
command="test", | ||
query_time=1, | ||
user_cpu_time=3, | ||
system_cpu_time=4, | ||
running_since=2, | ||
memory_percent=5, | ||
).csv_row() | ||
== expected | ||
) | ||
|
||
assert ( | ||
ProcessResourceUsageSnapshot.from_csv_row( | ||
( | ||
1, | ||
"test", | ||
2, | ||
3, | ||
4, | ||
5, | ||
) | ||
).csv_row() | ||
== expected | ||
) |