Skip to content

Commit

Permalink
Update tests to use existing files on disk. Fixes failing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Oct 8, 2022
1 parent 6f700a4 commit f945f0a
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions test_zipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,22 +418,30 @@ def test_inheritance(self, alpharep):
file = cls(alpharep).joinpath('some dir').parent
assert isinstance(file, cls)

def test_can_pickle_string_path(self):
path_1 = zipp.Path("/path/to/a/file.zip")
path_1_pickle = pickle.dumps(path_1)
path_1_load = pickle.loads(path_1_pickle)
assert path_1.root == path_1_load.root
path_2 = zipp.Path("/path/to/a/file.zip", at="something.txt")
path_2_pickle = pickle.dumps(path_2)
path_2_load = pickle.loads(path_2_pickle)
assert path_2.root == path_2_load.root

def test_can_pickle_pathlib_path(self):
path_1 = zipp.Path(pathlib.Path("/path/to/a/file.zip"))
path_1_pickle = pickle.dumps(path_1)
path_1_load = pickle.loads(path_1_pickle)
assert path_1.root == path_1_load.root
path_2 = zipp.Path(pathlib.Path("/path/to/a/file.zip", at="something.txt"))
path_2_pickle = pickle.dumps(path_2)
path_2_load = pickle.loads(path_2_pickle)
assert path_2.root == path_2_load.root
@pass_alpharep
def test_can_pickle_string_path(self, alpharep):
zipfile_ondisk = str(self.zipfile_ondisk(alpharep))

saved_1 = pickle.dumps(zipp.Path(zipfile_ondisk))
restored_1 = pickle.loads(saved_1)
a, b, g = restored_1.iterdir()
assert a.read_text() == "content of a"

saved_2 = pickle.dumps(zipp.Path(zipfile_ondisk, at="b/"))
restored_2 = pickle.loads(saved_2)
c, d, f = restored_2.iterdir()
assert c.read_text() == 'content of c'

@pass_alpharep
def test_can_pickle_pathlib_path(self, alpharep):
zipfile_ondisk = self.zipfile_ondisk(alpharep)

saved_1 = pickle.dumps(zipp.Path(zipfile_ondisk))
restored_1 = pickle.loads(saved_1)
a, b, g = restored_1.iterdir()
assert a.read_text() == "content of a"

saved_2 = pickle.dumps(zipp.Path(zipfile_ondisk, at="b/"))
restored_2 = pickle.loads(saved_2)
c, d, f = restored_2.iterdir()
assert c.read_text() == 'content of c'

0 comments on commit f945f0a

Please sign in to comment.