Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

allow Paths in save() #83

Closed
wants to merge 6 commits into from
Closed

Conversation

RoyalTS
Copy link

@RoyalTS RoyalTS commented Nov 30, 2020

Complement to vega/altair#2355

@RoyalTS
Copy link
Author

RoyalTS commented Nov 30, 2020

Not quite sure where the test failures are coming from. They seem unrelated to the changes I made

@jakevdp
Copy link
Member

jakevdp commented Dec 1, 2020

Looks good! We'll need some tests of this here as well. I think you could add one of path-based format inference here:

def test_infer_format(spec: JSONDict) -> None:
with temporary_filename(suffix=".html") as filename:
with open(filename, "w") as fp:
save(spec, fp)
with open(filename, "r") as fp:
html = fp.read()
assert html.strip().startswith("<!DOCTYPE html>")

and add one of file opening and writing here:

@pytest.mark.parametrize("mode", ["w", "wb"])
def test_maybe_open_filename(mode: str) -> None:
content_raw = "testing maybe_open with filename\n"
content = content_raw.encode() if "b" in mode else content_raw
with temporary_filename() as filename:
with maybe_open(filename, mode) as f:
f.write(content)
with open(filename, "rb" if "b" in mode else "r") as f:
assert f.read() == content

As a side-note, it looks like we don't have any integration tests of saving a chart to a disk. That is indirectly covered by unit tests of the relevant utilities, but since saving a chart is a core functionality of this library, it would be better to have a full end-to-end test of that behavior!

@RoyalTS
Copy link
Author

RoyalTS commented Dec 1, 2020

We'll need some tests of this here as well. I think you could add one of path-based format inference here:

Wouldn't

@pytest.mark.parametrize(
be the better place for testing format inference from the passed fp?

If so, I'm not sure I understand the current test. The use_filename==False mode just seems like a more convoluted way of generating a filename, one that introduces a failure mode (the temp file not being created) that has nothing to do with the test. What am I missing?

@jakevdp
Copy link
Member

jakevdp commented Dec 1, 2020

The test aims to exercise format inference from either a file pointer (in which case fp.name is the relevant name) or a filename (in which the string itself is the relevant name). I'm not certain I understand what failure mode you're referring to.

@RoyalTS
Copy link
Author

RoyalTS commented Dec 1, 2020

Oh, I see. In that case one would want to test four different possible values for fp?

  1. string path
  2. pathlib.Path
  3. file pointer
  4. output streams

with format inference working as inteded for 1-3 and failing in the fourth case?

@jakevdp
Copy link
Member

jakevdp commented Dec 1, 2020

Yeah, that sounds right.

@jakevdp
Copy link
Member

jakevdp commented Dec 1, 2020

New tests look great!

@RoyalTS
Copy link
Author

RoyalTS commented Dec 2, 2020

The build seems to have encountered an internal error. Any way to trigger a new one manually?

@jakevdp
Copy link
Member

jakevdp commented Dec 2, 2020

I triggered a new run

@RoyalTS
Copy link
Author

RoyalTS commented Dec 2, 2020

Lots of failing tests but none look like they're due to the changes?

@jakevdp
Copy link
Member

jakevdp commented Dec 2, 2020

Yeah, looks like there are failures on master due to tests not being resilient to dependency updates.

@jakevdp
Copy link
Member

jakevdp commented Dec 2, 2020

Also the lint job is just failing for reasons I don't understand.

@RoyalTS
Copy link
Author

RoyalTS commented Dec 2, 2020

That makes two of us then :)

@joelostblom
Copy link
Member

Thanks for you PR @RoyalTS . As you have noticed, there hasn't been any development in this repo for a while. Since Altair 5.2, the functionality of Altair Saver is now available in Altair via the vl-convert package. Most of the functionality has been available since 5.0, and the main addition in 5.2 was PDF export. See the docs on how to save charts for more details.

We are going to archive this repo, so I'm closing all the open issues and PRs before doing so. Try out the new options for saving charts mentioned above and if you run into issues, please open an issue directly in the altair or vl-convert repo.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants