Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b01ba5d4 authored by PAPERMAN Charles's avatar PAPERMAN Charles
Browse files

Merge branch '6-fixing-tests-for-the-export-function' into 'main'

Fixed the export_test bug. The tests used to fail when the test_graph was not...

Closes #6

See merge request pydisk/examples/vizitig!6
parents e9fa0f80 b5253cf3
No related branches found
No related tags found
1 merge request!6Fixed the export_test bug. The tests used to fail when the test_graph was not...
import argparse import argparse
from itertools import groupby from itertools import groupby
from pathlib import Path from pathlib import Path
from typing import Iterator, Mapping, MutableMapping, Tuple, Any from typing import Any, Iterator, Mapping, MutableMapping, Tuple
import networkdisk as nd import networkdisk as nd
from tqdm import tqdm from tqdm import tqdm
...@@ -22,7 +22,7 @@ def chunk(g, n): ...@@ -22,7 +22,7 @@ def chunk(g, n):
def nodes_iter_from_desc( def nodes_iter_from_desc(
it: Iterator[NodeHeader], it: Iterator[NodeHeader],
k: int, k: int,
gene_annotation: None | MutableMapping[str, set[str]] = None gene_annotation: None | MutableMapping[str, set[str]] = None,
) -> Iterator[Tuple[int, Mapping]]: ) -> Iterator[Tuple[int, Mapping]]:
for node in it: for node in it:
d: MutableMapping[str, Any] = dict(seq=node.sequence) d: MutableMapping[str, Any] = dict(seq=node.sequence)
...@@ -81,7 +81,7 @@ def generate_graph( ...@@ -81,7 +81,7 @@ def generate_graph(
G.add_nodes_from(list(u)) G.add_nodes_from(list(u))
else: else:
list(u) list(u)
G.graph["genes"] = {k: tuple(v) for k,v in genes_metas_data.items() } G.graph["genes"] = {k: tuple(v) for k,v in genes_metas_data.items() }
log(timed=True) log(timed=True)
...@@ -110,7 +110,7 @@ def generate_graph( ...@@ -110,7 +110,7 @@ def generate_graph(
if not parse_only: if not parse_only:
G.reindex() G.reindex()
log(timed=True) log(timed=True)
def build_cli(args): def build_cli(args):
......
from pathlib import Path from pathlib import Path
from typing import Iterator
from vizitig.cli import subparsers from vizitig.cli import subparsers
from vizitig.info import get_graph, reload_graph from vizitig.info import get_graph, reload_graph
from vizitig.parsing import parse_gtf, parse_reference_sequences from vizitig.parsing import parse_gtf, parse_reference_sequences
from vizitig.update.bulk_update import tag_graph_from_kmer_gene from vizitig.update.bulk_update import tag_graph_from_kmer_gene
from typing import Iterator
def main(args): def main(args):
Graph = get_graph(args.graph_name) Graph = get_graph(args.graph_name)
......
import re import re
from typing import Any, Iterable, Literal, Optional, Mapping from typing import Any, Iterable, Literal, Optional
from networkdisk.sqlite import DiGraph from networkdisk.sqlite import DiGraph
from pydantic import BaseModel from pydantic import BaseModel
......
import random import random
from pathlib import Path
from pytest import raises from pytest import fixture, mark, raises
from vizitig.errors import * from vizitig.errors import EmptyExportError
from vizitig.export import export_graph from vizitig.export import export_graph
from vizitig.tests.utils import create_dummy_graph, delete_dummy_graph, test_graph_name
def test_export_graph_bcalm_in_normal_conditions(tmp_path): @fixture(scope="function")
def Setup_and_cleaning_fixture_for_vizitig_graph_testing():
"""This fixture is used to setup and clean before and after a test.
First it calls create_dummy_grah that creates a dummy graph and will be
used for testing, then it deletes all the files that contain the
test_graph_name wth delete_dummy_graph, to remove the .db and .fa
files that were created for the test.
In between, it runs the test.
"""
create_dummy_graph()
yield
delete_dummy_graph()
@mark.usefixtures("Setup_and_cleaning_fixture_for_vizitig_graph_testing")
def test_export_graph_bcalm_in_normal_conditions(tmp_path: Path):
test_file = tmp_path / "file" test_file = tmp_path / "file"
export_graph("test", list(range(32)), "bcalm", test_file) export_graph(test_graph_name, list(range(32)), "bcalm", test_file)
assert test_file.exists() assert test_file.exists()
test_file.unlink() test_file.unlink()
def test_export_graph_bcalm_subgraph(tmp_path): @mark.usefixtures("Setup_and_cleaning_fixture_for_vizitig_graph_testing")
def test_export_graph_bcalm_subgraph(tmp_path: Path):
test_file = tmp_path / "file" test_file = tmp_path / "file"
export_graph("test", random.sample(list(range(32)), 16), "bcalm", test_file) sample_nodes = random.sample(list(range(32)), 16) + [1] #We want to extract at least the first node.
#With small example graphs, it can happen that no nodes are picked in the sample so we add
#at least the first node to avoid the EmptyExportError
export_graph(test_graph_name, sample_nodes, "bcalm", test_file)
assert test_file.exists() assert test_file.exists()
test_file.unlink() test_file.unlink()
def test_export_graph_bcalm_crashes_with_bad_nodes_id(tmp_path): @mark.usefixtures("Setup_and_cleaning_fixture_for_vizitig_graph_testing")
def test_export_graph_bcalm_crashes_with_bad_nodes_id(tmp_path: Path):
test_file = tmp_path / "file" test_file = tmp_path / "file"
with raises(EmptyExportError): with raises(EmptyExportError):
export_graph("test", list([-1]), "bcalm", test_file) export_graph(test_graph_name, list([-1]), "bcalm", test_file)
assert not test_file.exists() assert not test_file.exists()
"""
def test_deux():
assert True
assert True
def test_trois():
with raises(ValueError):
raise ValueError()
def test_quatres():
with raises(ValueError):
raise TypeError()
"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment