forked from fsspec/filesystem_spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_github.py
41 lines (31 loc) · 1.48 KB
/
test_github.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import fsspec
def test_github_open_small_file():
# test opening a small file <1 MB
with fsspec.open("github://mwaskom:seaborn-data@4e06bf0/penguins.csv") as f:
assert f.readline().startswith(b"species,island")
def test_github_open_large_file():
# test opening a large file >1 MB
with fsspec.open("github://mwaskom:seaborn-data@83bfba7/brain_networks.csv") as f:
assert f.readline().startswith(b"network,1,1,2,2")
def test_github_open_lfs_file():
# test opening a git-lfs tracked file
with fsspec.open(
"github://cBioPortal:datahub@55cd360"
"/public/acc_2019/data_gene_panel_matrix.txt",
) as f:
assert f.readline().startswith(b"SAMPLE_ID\tmutations")
def test_github_cat():
# test using cat to fetch the content of multiple files
fs = fsspec.filesystem("github", org="mwaskom", repo="seaborn-data")
paths = ["penguins.csv", "mpg.csv"]
cat_result = fs.cat(paths)
assert set(cat_result.keys()) == {"penguins.csv", "mpg.csv"}
assert cat_result["penguins.csv"].startswith(b"species,island")
assert cat_result["mpg.csv"].startswith(b"mpg,cylinders")
def test_github_ls():
# test using ls to list the files in a resository
fs = fsspec.filesystem("github", org="mwaskom", repo="seaborn-data")
ls_result = set(fs.ls(""))
expected = {"brain_networks.csv", "mpg.csv", "penguins.csv", "README.md", "raw"}
# check if the result is a subset of the expected files
assert expected.issubset(ls_result)