|
3 | 3 | import subprocess
|
4 | 4 | import sys
|
5 | 5 | from tempfile import mkstemp
|
| 6 | +from unittest.mock import mock_open, patch, sentinel |
6 | 7 |
|
| 8 | +from rdflib.tools import csv2rdf |
7 | 9 | from test.data import TEST_DATA_DIR
|
8 | 10 |
|
9 | 11 | REALESTATE_FILE_PATH = os.path.join(TEST_DATA_DIR, "csv", "realestate.csv")
|
@@ -44,3 +46,20 @@ def test_csv2rdf_cli_fileout(self):
|
44 | 46 | assert len(f.readlines()) == 228
|
45 | 47 | os.close(fh)
|
46 | 48 | os.remove(fname)
|
| 49 | + |
| 50 | + @patch.object(csv2rdf.CSV2RDF, "convert", return_value=None) |
| 51 | + def test_csv2rdf_config_file_opened(self, config_mock): |
| 52 | + """Test that the config file is read when specified.""" |
| 53 | + # Pretend there is a file with the section we're looking for. |
| 54 | + # We don't care about the actual path, since it won't really be opened |
| 55 | + # but when we try to open it, we will get back the section header |
| 56 | + # so that the reader doesn't complain. |
| 57 | + config_file = sentinel.file_path |
| 58 | + open_mock = mock_open(read_data="[csv2rdf]") |
| 59 | + # Also pretend that we're passing the arguments from the command line |
| 60 | + cli_args = ["csv2rdf.py", "-f", config_file, str(REALESTATE_FILE_PATH)] |
| 61 | + with patch.object(csv2rdf.sys, "argv", cli_args): |
| 62 | + with patch("builtins.open", open_mock): |
| 63 | + csv2rdf.main() |
| 64 | + # Check that we've "opened" the right file |
| 65 | + open_mock.assert_called_once_with(config_file) |
0 commit comments