File: test_csv2rdf.py

package info (click to toggle)
rdflib 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 38,248 kB
  • sloc: python: 39,216; sh: 153; makefile: 110
file content (47 lines) | stat: -rw-r--r-- 1,494 bytes parent folder | download
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
47
import subprocess
import unittest
import sys
from os import remove, close
from tempfile import mkstemp
from pathlib import Path


class CSV2RDFTest(unittest.TestCase):
    def setUp(self):
        self.REALESTATE_FILE_PATH = Path(__file__).parent / "csv" / "realestate.csv"

    def test_csv2rdf_cli(self):
        completed = subprocess.run(
            [
                sys.executable,
                "-m",
                "rdflib.tools.csv2rdf",
                str(self.REALESTATE_FILE_PATH),
            ],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            universal_newlines=True,
        )
        self.assertEqual(completed.returncode, 0)
        self.assertRegex(completed.stderr, r"Converted \d+ rows into \d+ triples.")
        self.assertRegex(completed.stderr, r"Took [\d\.]+ seconds.")
        self.assertIn("<http://example.org/instances/0>", completed.stdout)
        self.assertIn("<http://example.org/props/zip>", completed.stdout)

    def test_csv2rdf_cli_fileout(self):
        fh, fname = mkstemp()
        completed = subprocess.run(
            [
                sys.executable,
                "-m",
                "rdflib.tools.csv2rdf",
                "-o",
                fname,
                str(self.REALESTATE_FILE_PATH),
            ],
        )
        self.assertEqual(completed.returncode, 0)
        with open(fname) as f:
            self.assertGreater(len(f.readlines()), 0)
        close(fh)
        remove(fname)