-
Notifications
You must be signed in to change notification settings - Fork 2
Html representation of processor and metadata in notebooks #395
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0d933b2
basics for repr for metadata and processor class
zain-sohail 337cbd3
basics for repr for metadata and processor class
zain-sohail 3ee0679
metadata pretty html representation
zain-sohail 3f5056a
fix linting/test errors
zain-sohail c65194a
idea for plots
zain-sohail ec547ca
apply some fixes
zain-sohail 3e84f82
remove yaml dump
zain-sohail 9f45f81
put back metadata property
zain-sohail 8c2246b
add tests for metadata
zain-sohail File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,75 @@ | ||
import json | ||
from typing import Any | ||
from typing import Dict | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from sed.core.metadata import DuplicateEntryError | ||
from sed.core.metadata import MetaHandler | ||
|
||
metadata: Dict[Any, Any] = {} | ||
metadata["entry_title"] = "Title" | ||
# sample | ||
metadata["sample"] = {} | ||
metadata["sample"]["size"] = np.array([1, 2, 3]) | ||
metadata["sample"]["name"] = "Sample Name" | ||
|
||
|
||
@pytest.fixture | ||
def meta_handler(): | ||
# Create a MetaHandler instance | ||
return MetaHandler(meta=metadata) | ||
|
||
|
||
def test_add_entry_overwrite(meta_handler): | ||
# Add a new entry to metadata with 'overwrite' policy | ||
new_entry = {"sample": "Sample Name"} | ||
meta_handler.add(new_entry, "sample", duplicate_policy="overwrite") | ||
assert "sample" in meta_handler.metadata | ||
assert meta_handler.metadata["sample"] == new_entry | ||
|
||
|
||
def test_add_entry_raise(meta_handler): | ||
# Attempt to add a duplicate entry with 'raise' policy | ||
with pytest.raises(DuplicateEntryError): | ||
meta_handler.add({}, "entry_title", duplicate_policy="raise") | ||
|
||
|
||
def test_add_entry_append(meta_handler): | ||
# Add a new entry to metadata with 'append' policy | ||
new_entry = {"sample": "Sample Name"} | ||
meta_handler.add(new_entry, "sample", duplicate_policy="append") | ||
assert "sample" in meta_handler.metadata | ||
assert "sample_1" in meta_handler.metadata | ||
assert meta_handler.metadata["sample_1"] == new_entry | ||
|
||
|
||
def test_add_entry_merge(meta_handler): | ||
# Add a new entry to metadata with 'merge' policy | ||
entry_to_merge = {"name": "Name", "type": "type"} | ||
meta_handler.add(entry_to_merge, "sample", duplicate_policy="merge") | ||
print(meta_handler.metadata) | ||
assert "sample" in meta_handler.metadata | ||
assert "name" in meta_handler.metadata["sample"] | ||
assert "type" in meta_handler.metadata["sample"] | ||
|
||
|
||
def test_repr(meta_handler): | ||
# Test the __repr__ method | ||
assert repr(meta_handler) == json.dumps(metadata, default=str, indent=4) | ||
|
||
|
||
def test_repr_html(meta_handler): | ||
# Test the _repr_html_ method | ||
html = meta_handler._format_attributes(metadata) | ||
assert meta_handler._repr_html_() == html | ||
|
||
html_test = "<div style='padding-left: 0px;'><b>Entry Title</b> [entry_title]: Title</div>" | ||
html_test += ( | ||
"<div style='padding-left: 0px;'><details><summary><b>Sample</b> [sample]</summary>" | ||
) | ||
html_test += "<div style='padding-left: 20px;'><b>Size</b> [size]: (3,)</div>" | ||
html_test += "<div style='padding-left: 20px;'><b>Name</b> [name]: Sample Name" | ||
html_test += "</div></details></div>" | ||
assert html == html_test |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.