summaryrefslogtreecommitdiff
path: root/test/test_csv2rdf.py
blob: fee10a3165bf557924f126a74e3916b1a4cc0bde (plain)
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
import subprocess
import unittest
from os import remove
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(
            ["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):
        _, fname = mkstemp()
        completed = subprocess.run(["csv2rdf", "-o", fname, str(self.REALESTATE_FILE_PATH)], )
        self.assertEqual(completed.returncode, 0)
        with open(fname) as f:
            self.assertGreater(len(f.readlines()), 0)
        remove(fname)