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
42
43
44
45
46
|
import os
import re
import subprocess
import sys
from tempfile import mkstemp
from test.data import TEST_DATA_DIR
REALESTATE_FILE_PATH = os.path.join(TEST_DATA_DIR, "csv", "realestate.csv")
class TestCSV2RDF:
def test_csv2rdf_cli(self):
completed = subprocess.run(
[
sys.executable,
"-m",
"rdflib.tools.csv2rdf",
str(REALESTATE_FILE_PATH),
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
assert completed.returncode == 0
assert "Converted 19 rows into 228 triples." in completed.stderr
assert re.search(r"Took [\d\.]+ seconds\.", completed.stderr)
assert "<http://example.org/instances/0>" in completed.stdout
assert "<http://example.org/props/zip>" in completed.stdout
def test_csv2rdf_cli_fileout(self):
fh, fname = mkstemp()
completed = subprocess.run(
[
sys.executable,
"-m",
"rdflib.tools.csv2rdf",
"-o",
fname,
str(REALESTATE_FILE_PATH),
],
)
assert completed.returncode == 0
with open(fname) as f:
assert len(f.readlines()) == 228
os.close(fh)
os.remove(fname)
|