|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +from typing import ClassVar, Literal |
| 4 | + |
3 | 5 | import pytest
|
4 | 6 |
|
5 | 7 | import higlass as hg
|
@@ -205,3 +207,37 @@ def test_options_mixin():
|
205 | 207 | assert track is other
|
206 | 208 | assert track.uid == other.uid
|
207 | 209 | assert track.options and track.options["foo"] == "bar"
|
| 210 | + |
| 211 | + |
| 212 | +def test_plugin_track(): |
| 213 | + """Test that plugin track attributes are maintained after a copy.""" |
| 214 | + some_url = "https://some_url" |
| 215 | + |
| 216 | + # Here we'll create a custom plugin track. |
| 217 | + class PileupTrack(hg.PluginTrack): |
| 218 | + type: Literal["pileup"] = "pileup" |
| 219 | + plugin_url: ClassVar[str] = some_url |
| 220 | + |
| 221 | + # Specify the track-specific data |
| 222 | + pileup_data = { |
| 223 | + "type": "bam", |
| 224 | + "url": "https://some_url/sorted.bam", |
| 225 | + "chromSizesUrl": "https://some_url/sorted.chromsizes.bam", |
| 226 | + "options": {"maxTileWidth": 30000}, |
| 227 | + } |
| 228 | + |
| 229 | + # Create and use the custom track |
| 230 | + pileup_track = PileupTrack(data=pileup_data) |
| 231 | + |
| 232 | + view = hg.view((pileup_track, "top")) |
| 233 | + uid1 = view.uid |
| 234 | + assert view.tracks.top[0].plugin_url == some_url |
| 235 | + |
| 236 | + # The .domain() function creates a copy of the view. We want to make sure |
| 237 | + # that the plugin_url attribute of the PluginTrack is maintained |
| 238 | + view = view.domain(x=[0, 10]) |
| 239 | + uid2 = view.uid |
| 240 | + assert view.tracks.top[0].plugin_url == some_url |
| 241 | + |
| 242 | + # Check to make sure the copy behavior changed the uid as expected |
| 243 | + assert uid1 != uid2 |
0 commit comments