summaryrefslogtreecommitdiff
path: root/test/test_graph
Commit message (Collapse)AuthorAgeFilesLines
* fix: HTTP 308 Permanent Redirect status code handling (#2389)Iwan Aucamp2023-05-172-9/+97
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change the handling of HTTP status code 308 to behave more like `urllib.request.HTTPRedirectHandler`, most critically, the new 308 handling will create a new `urllib.request.Request` object with the new URL, which will prevent state from being carried over from the original request. One case where this is important is when the domain name changes, for example, when the original URL is `http://www.w3.org/ns/adms.ttl` and the redirect URL is `https://uri.semic.eu/w3c/ns/adms.ttl`. With the previous behaviour, the redirect would contain a `Host` header with the value `www.w3.org` instead of `uri.semic.eu` because the `Host` header is placed in `Request.unredirected_hdrs` and takes precedence over the `Host` header in `Request.headers`. Other changes: - Only handle HTTP status code 308 on Python versions before 3.11 as Python 3.11 will handle 308 by default [[ref](https://docs.python.org/3.11/whatsnew/changelog.html#id128)]. - Move code which uses `http://www.w3.org/ns/adms.ttl` and `http://www.w3.org/ns/adms.rdf` out of `test_guess_format_for_parse` into a separate parameterized test, which instead uses the embedded http server. This allows the test to fully control the `Content-Type` header in the response instead of relying on the value that the server is sending. This is needed because the server is sending `Content-Type: text/plain` for the `adms.ttl` file, which is not a valid RDF format, and the test is expecting `Content-Type: text/turtle`. Fixes: - <https://github.com/RDFLib/rdflib/issues/2382>.
* test: Eliminate flake8 errors in tests (#2353)Iwan Aucamp2023-04-141-1/+1
| | | | | | | | | | | | | | | | | | | | | Eliminate some occurrences of the following flake8 errors in tests: * E265 block comment should start with '# ' * E266 too many leading '#' for block comment * E402 module level import not at top of file * E712 comparison to False should be 'if cond is False:' or 'if not cond:' * E712 comparison to True should be 'if cond is True:' or 'if cond:' * E722 do not use bare 'except' * F401 ... imported but unused * F403 ... used; unable to detect undefined names * F405 ... may be undefined, or defined from star imports: ... * F541 f-string is missing placeholders * F841 local variable 'result' is assigned to but never used * N806 variable 'TEST_DIR' in function should be lowercase This is pursuant to eliminating [flakeheaven](https://github.com/flakeheaven/flakeheaven), as it no longer supports the latest version of flake8 [[ref](https://github.com/flakeheaven/flakeheaven/issues/132)].
* fix: correct imports and `__all__` (#2340)Iwan Aucamp2023-04-123-8/+7
| | | | | | | | Disable [`implicit_reexport`](https://mypy.readthedocs.io/en/stable/config_file.html#confval-implicit_reexport) and eliminate all errors reported by mypy after this. This helps ensure that import statements import from the right module and that the `__all__` variable is correct.
* feat: add optional `target_graph` argument to `Graph.cbd` and use it for ↵Matt Goldberg2023-04-111-1/+26
| | | | | | | | | DESCRIBE queries (#2322) Add optional keyword only `target_graph` argument to `rdflib.graph.Graph.cbd` and use this new argument in `evalDescribeQuery`. This makes it possible to compute a concise bounded description without creating a new graph to hold the result, and also without potentially having to copy it to another final graph. Co-authored-by: Iwan Aucamp <aucampia@gmail.com>
* refactor: eliminate inheritance from object (#2339)Iwan Aucamp2023-04-101-1/+1
| | | | | This change removes the redundant inheritance from `object` (i.e. `class Foo(object): pass`) that is no longer needed in Python 3 and is a relic from Python 2.
* fix: restore the 6.1.1 default bound namespaces (#2313)Iwan Aucamp2023-03-261-1/+2
| | | | | | | | | | | | The namespaces bound by default by `rdflib.graph.Graph` and `rdflib.namespace.NamespaceManager` was reduced in version 6.2.0 of RDFLib, however, this also would cause code that worked with 6.1.1 to break, so this constituted a breaking change. This change restores the previous behaviour, binding the same namespaces as was bound in 6.1.1. To bind a reduced set of namespaces, the `bind_namespaces` parameter of `rdflib.graph.Graph` or `rdflib.namespace.NamespaceManager` can be used. - Closes <https://github.com/RDFLib/rdflib/issues/2103>.
* fix: IRI to URI conversion (#2304)Iwan Aucamp2023-03-231-4/+39
| | | | | | | | | | | | | | | | | The URI to IRI conversion was percentage-quoting characters that should not have been quoted, like equals in the query string. It was also not quoting things that should have been quoted, like the username and password components of a URI. This change improves the conversion by only quoting characters that are not allowed in specific parts of the URI and quoting previously unquoted components. The safe characters for each segment are taken from [RFC3986](https://datatracker.ietf.org/doc/html/rfc3986). The new behavior is heavily inspired by [`werkzeug.urls.iri_to_uri`](https://github.com/pallets/werkzeug/blob/92c6380248c7272ee668e1f8bbd80447027ccce2/src/werkzeug/urls.py#L926-L931) though there are some differences. - Closes <https://github.com/RDFLib/rdflib/issues/2120>.
* build(deps-dev): bump mypy from 1.0.1 to 1.1.1 (#2274)dependabot[bot]2023-03-191-1/+2
| | | | | | | | | | | | | | | | | | build(deps-dev): bump mypy from 1.0.1 to 1.1.1 Bumps [mypy](https://github.com/python/mypy) from 1.0.1 to 1.1.1. - [Release notes](https://github.com/python/mypy/releases) - [Commits](https://github.com/python/mypy/compare/v1.0.1...v1.1.1) updated-dependencies: - dependency-name: mypy dependency-type: direct:development update-type: version-update:semver-minor Also added type ignores for newly detected type errors. Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Iwan Aucamp <aucampia@gmail.com>
* build(deps-dev): bump black from 22.12.0 to 23.1.0 (#2248)dependabot[bot]2023-03-112-8/+0
|
* fix: small InputSource related issues (#2255)Iwan Aucamp2023-03-113-8/+22
| | | | | | | | | | | | | | | | | | | | | | | | I have added a bunch of tests for `InputSource` handling, checking most kinds of input source with most parsers. During this, I detected the following issues that I fixed: - `rdflib.util._iri2uri()` was URL quoting the `netloc` parameter, but this is wrong and the `idna` encoding already takes care of special characters. I removed the URL quoting of `netloc`. - HexTuple parsing was handling the input source in a way that would only work for some input sources, and not raising errors for other input sources. I changed the input source handling to be more generic. - `rdflib.parser.create_input_source()` incorrectly used `file.buffer` instead of `source.buffer` when dealing with IO stream sources. Other changes with no runtime impact include: - Changed the HTTP mocking stuff in test slightly to accommodate serving arbitrary files, as I used this in the `InputSource` tests. - Don't use Google in tests, as we keep getting `urllib.error.HTTPError: HTTP Error 429: Too Many Requests` from it.
* build(deps-dev): bump mypy from 0.991 to 1.0.1 (#2247)dependabot[bot]2023-03-061-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | * build(deps-dev): bump mypy from 0.991 to 1.0.1 Bumps [mypy](https://github.com/python/mypy) from 0.991 to 1.0.1. - [Release notes](https://github.com/python/mypy/releases) - [Commits](https://github.com/python/mypy/compare/v0.991...v1.0.1) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix type errors --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Iwan Aucamp <aucampia@gmail.com>
* fix: Don't register berkelydb as a store if it is not available on the ↵Clay G2022-08-231-3/+0
| | | | | | | | | system (#2096) This is so that it is simpler and easier to do something with all plugins without treating different plugins in different ways. Also remove test code that tries to accommodate the plugin being present but not usable. Fixes #1816
* test: content-type handling with SPARQLStore + CONSTRUCT queries (#2092)Iwan Aucamp2022-08-231-20/+5
| | | | | | Confirm various content type values are handled correctly with CONSTRUCT queries and SPARQLStore. This aims to confirm that #1195 is fixed.
* fix: always parse HexTuple files as utf-8 (#2070)Iwan Aucamp2022-08-071-11/+0
| | | | | | | | | | Always parse HexTuple files as utf-8 as was the intent anyway as evidenced by the code that will raise a warning if the encoding provided for a HexTuple file is something other than utf-8 or None. https://github.com/RDFLib/rdflib/blob/cfa418074b27b12aac905ba266b002a237c5ff4c/rdflib/plugins/parsers/hext.py#L73-L79 Not adding any tests as this code is already tested and an XFAIL is removed in this patch.
* Fallback to old `Store.bind` signature on `TypeError` (#2018)Iwan Aucamp2022-07-151-0/+213
| | | | | | | | | | | | | | If `Store.bind` raises a `TypeError`, and the string conversion of this TypeError contains `override`, then log a warning and call `Store.bind` without an override. This is done so that stores that do not accept `override` on `Store.bind` still work, but at the cost of still having the bug that was fixed by introducing the `override` parameter. Also added a private flag which can be used to disable the fix entirely and never use `override` when calling `Store.bind`. - Fixes https://github.com/RDFLib/rdflib/issues/1880
* Add more tests for graph_diff (#1983)Iwan Aucamp2022-06-052-8/+170
| | | | | | | | | | | | | This is to confirm that `graph_diff` does not work with quads. Other changes: - Added support to `GraphHelper` for collapsing `BNode`s to a specific IRI when converting to triple sets, this is in addition to the current functionality for ignoring BNodes. This makes it possible to more accurately compare Graphs that contain blank nodes. - Added `assert_cgraph_isomorphic` to `GraphHelper`. This method adds some rudimentary support for checking if conjunctive graphs are isomorphic, it will ignore named graphs that have blank nodes as name.
* Convert some more graph tests to pytest (#1982)Iwan Aucamp2022-06-054-117/+105
| | | | This patch converts some additional graph tests to pytest, I'm doing this in preperation for adding more tests to `test_diff.py`.
* More type hints for `rdflib.graph` and related (#1853)Iwan Aucamp2022-05-262-8/+11
| | | | | | | | | | | | | | | | | | This patch primarily adds more type hints for `rdflib.graph`, but also adds type hints to some related modules in order to work with the new type hints for `rdflib.graph`. I'm mainly doing this as a baseline for adding type hints to `rdflib.store`. I have created type aliases to make it easier to type everything consistently and to make type hints easier easier to change in the future. The type aliases are private however (i.e. `_`-prefixed) and should be kept as such for now. This patch only contains typing changes and does not change runtime behavior. Broken off from https://github.com/RDFLib/rdflib/pull/1850
* [pre-commit.ci] auto fixes from pre-commit.com hookspre-commit-ci[bot]2022-05-191-39/+39
| | | | for more information, see https://pre-commit.ci
* Fixes #1429, add `iri2uri` (#1902)Graham Higgins2022-05-191-0/+37
| | | | | | | Add an iri-to-uri conversion utility to encode IRIs to URIs for `Graph.parse()` sources. Added a couple of tests because feeding it with a suite of IRIs to check seems overkill (not that I could find one). Fixes #1429 Co-authored-by: Iwan Aucamp <aucampia@gmail.com>
* Replace rdlib.net and rdflib.net with rdflib.github.io (#1901)Graham Higgins2022-05-191-4/+9
| | | | | | | | This is being done because `rdlib.net` is a typo and `rdflib.net` is not owned or associated with this project. Also: - Expand testing for some parts of the code impacted by this. Co-authored-by: Iwan Aucamp <aucampia@gmail.com>
* Add tests demonstrating forward-slash behaviors in Turtle, JSON-LD, and ↵Alex Nelson2022-05-181-0/+14
| | | | | | | | | | | SPARQL (#1872) This patch adds test to verify that forward-slashes, and escaped forward slashes, work correctly in Turtle, JSON-LD and SPARQL. Some of the added tests check that SPARQL queries that contain seemingly escaped forward slashes as part of `PN_LOCAL` fail to execute as the SPARQL spec does not allow for escaped forward slashes in `PN_LOCAL`. Currently the RDFLib SPARQL processor does however allow escaped forward slashes as part of `PN_LOCAL`, so these tests have been marked with xfail as RDFLib should provide some way to parse SPARQL in strict mode, and in this mode leaniancies should be disabled and any non-standard SPARQL should be treated as invalid. Co-authored-by: Iwan Aucamp <aucampia@gmail.com>
* test: convert `test_graph_http.py` to pytest (#1956)Iwan Aucamp2022-05-181-33/+26
| | | | | | This is a fairly straight forward conversion to pytest. Also: - Fix/ignore some flake8 errors.
* test: remove unused imports in test codeIwan Aucamp2022-05-176-10/+3
| | | | | | | | | | This patch removes unused imports in test code. This is mainly to remove the potential snag for flake8/flakeheaven. The actual cleanup was done with `pycln --all test`. Also: - Remove superflous `pass` statements.
* Added test for example at CBD definition. Fixes #1914. (#1915)asejal2022-05-131-0/+27
| | | | | We have added a test for the example at the definition for Concise Bounded Definition [here](https://www.w3.org/Submission/CBD/#example). Fixes #1914
* test: add more graph variants highlighting bugsIwan Aucamp2022-05-121-0/+23
| | | | | | | | | | | | | | | This patch adds some additional graph variants: - diverse_triples: More than one triple using various features. - diverse_quads: More than one quad in more than one graph using various features. - more_quads: Simple quads in more than one graph. This also highlights some additional issues: - There is a bug in JSON-LD and HexTuple serialization that drops datatypes. - The TriG parser gets confused about what graph a quad is in. - There is some encoding related issue with HexTuple parsing on windows.
* Improved mock HTTP ServerIwan Aucamp2022-05-121-27/+33
| | | | | This changes the HTTP server mock to a more versatile implementation with support for more HTTP methods.
* continuing re-org of w3c testsGraham Higgins2022-05-101-4/+2
| | | | - update to use new test utils structure
* test: move test utility modules into `test/utils/` (#1879)Iwan Aucamp2022-05-046-11/+6
| | | | | | | This patch moves all test utility modules into `test/utils/` and the tests for these modules into `test/utils/test/`. This is to make test utilities more organized and in preparation for adding more test utilities related to test suites.
* test: move `test/variants` into `test/data`Iwan Aucamp2022-04-231-2/+3
| | | | This is to bring it in line with other test data.
* Fixes, improvements and test for namespace (re)-binding on stores.Iwan Aucamp2022-04-191-3/+6
| | | | | | | | | | | - Added store specific tests for namespace binding and rebinding. - Copied @gjhiggins fix for `rdflib.plugins.stores.memory.Memory.bind` to `rdflib.plugins.stores.memory.SimpleMemory.bind`. - Changed `bind` on `Memory`, `SimpleMemory`, `BerkleyDB` stores to explicitly check for `is not None`/`is None` instead of falsey/truthy. - Added `pytest.util._coalesce` to do null coalescing, for more info see deferred PEP-505 https://peps.python.org/pep-0505/.
* [pre-commit.ci] auto fixes from pre-commit.com hookspre-commit-ci[bot]2022-04-191-91/+39
| | | | for more information, see https://pre-commit.ci
* refactor: move graph namespace rebinding test to graph directoryIwan Aucamp2022-04-191-0/+488
|
* Merge pull request #1821 from edmondchuc/fix-issue-1808Iwan Aucamp2022-04-181-0/+93
|\ | | | | Fix issue 1808
| * Add some paramaterized tests for skolemization and de-skolemizationIwan Aucamp2022-04-151-0/+93
| |
* | Merge remote-tracking branch 'upstream/master' into test-reorgIwan Aucamp2022-04-1713-63/+51
|\ \ | |/
| * [pre-commit.ci] auto fixes from pre-commit.com hookspre-commit-ci[bot]2022-04-1511-71/+93
| | | | | | | | for more information, see https://pre-commit.ci
* | test re-orgGraham Higgins2022-04-164-25/+240
|/
* Merge pull request #1813 from gjhiggins/migrate-test_graph-to-pytestIwan Aucamp2022-04-151-0/+384
|\ | | | | | | | | Migrate to pytest, relocate in subfolder Merging with only one approval as the coverage remains the same and it only affects tests.
| * Only test BerkelyDB if it is installedIwan Aucamp2022-04-141-0/+3
| |
| * Add back tests for other storesIwan Aucamp2022-04-141-26/+67
| |
| * Migrate to pyetst, relocate in subfolderGraham Higgins2022-04-141-0/+340
| |
* | [pre-commit.ci] auto fixes from pre-commit.com hookspre-commit-ci[bot]2022-04-146-12/+23
|/ | | | for more information, see https://pre-commit.ci
* Merge pull request #1801 from aucampia/iwana-20220410T1604-more_variantsIwan Aucamp2022-04-131-5/+35
|\ | | | | | | | | Add two xfails related to Example 2 from RDF 1.1 TriG specification Merging with only one review as this just adds tests within the variant and round trip test harnesses which are parameterized. Some of the added tests are xfails but given that the rest of the tests for the same parameterized harnesses pass it seems likely that the xfail tests are valid.
| * Add two xfails related to Example 2 from RDF 1.1 TriG specificationIwan Aucamp2022-04-111-5/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The first xfail occurs during round tripping, TriG seems to be making some mistake when encoding blank nodes, as it is encoding that "Bob" knows someone who does not exist. This was reported by @gjhiggins in https://github.com/RDFLib/rdflib/pull/1796#discussion_r846781069 The second xfail seems to be related to hextuple parsing, when comparing the hextuple parsed result of Example 2 with the TriG parsed graph of Example 2 the graphs are not isomorphic more than 70% of the time, but sometimes they are isomorphic. Inoticed this while adding the xfail for the issue @gjhiggins noticed. Other changes: - Added `simple_quad` to variants tests with HexTuple and TriG format. - Added an additional exact_match assert for variants which can be used to sidestep some of the known issues with isomorphic graph detection. This is useful for graphs with no BNodes. - Also added round-tripping for `variants/simple_quad.trig`. - Various changes to ensure determensitic ordering so that it is easier to compare things visually and so that tests always do the exact same thing in the exact same order.
* | take the opportunity to remove references to unittest, as suggestedGraham Higgins2022-04-121-2/+1
| |
* | fix whoopsiesGraham Higgins2022-04-121-1/+1
| |
* | migrate yet more tests to pytestGraham Higgins2022-04-122-51/+20
|/
* update test_graph_generators to import from test.dataGraham Higgins2022-04-051-8/+11
|
* more test re-orgGraham Higgins2022-04-025-0/+1042
|