Esempio n. 1
0
def test_drop_cmd(conn):
    """Test drop command of VQL language

    The following tables are tested:
    - selections
    - wordsets
    """
    # Create a selection named "subset"
    conn.execute("INSERT INTO selections (name) VALUES ('subset')")
    assert "subset" in [
        i["name"]
        for i in conn.execute("SELECT name FROM selections").fetchall()
    ]
    ret = command.drop_cmd(conn, feature="selections", name="subset")
    assert "subset" not in [
        i["name"]
        for i in conn.execute("SELECT name FROM selections").fetchall()
    ]
    assert ret["success"]

    # Create wordset
    test_file = "examples/gene.txt"
    wordset_name = "bouzniouf"
    command.import_cmd(conn, "wordsets", wordset_name, test_file)
    command.drop_cmd(conn, feature="wordsets", name=wordset_name)

    assert wordset_name not in [
        i["name"]
        for i in conn.execute("SELECT name FROM wordsets").fetchall()
    ]
Esempio n. 2
0
def test_show_cmd(conn):
    """Test SHOW command of VQL language

    Test the following tables:
    - samples
    - selections
    - fields
    - wordsets
    - WORDSETS (UPPER CASE name)
    - truc (wrong table) => VQLSyntaxError expected
    """
    # Test samples
    result = list(command.execute(conn, "SHOW samples"))
    print("Found samples:", result)
    assert len(result) == 2

    found_sample_names = {sample["name"] for sample in result}
    expected_sample_names = {"NORMAL", "TUMOR"}
    assert expected_sample_names == found_sample_names

    # Test selections
    # Create a selection
    command.create_cmd(conn, source="variants", target="A")
    result = list(command.execute(conn, "SHOW selections"))
    print("Found selections:", result)
    assert len(result) == 2

    # Test fields
    result = list(command.execute(conn, "SHOW fields"))
    print("Found fields:", result)
    # Just test keys of the first item
    assert result[0].keys() == {
        'id', 'name', 'category', 'type', 'description'
    }

    # Test wordsets
    # Create a wordset
    # Test import of word set
    test_file = "examples/gene.txt"
    wordset_name = "bouzniouf"
    command.import_cmd(conn, "wordsets", wordset_name, test_file)
    result = list(command.execute(conn, "SHOW wordsets"))
    print("Found wordsets in lower case:", result)
    assert len(result) == 1

    expected_wordset = {'name': 'bouzniouf', 'count': 2}
    assert expected_wordset == result[0]

    # Test WORDSETS
    result = list(command.execute(conn, "SHOW WORDSETS"))
    print("Found WORDSETS in upper case:", result)
    assert len(result) == 1

    expected_wordset = {'name': 'bouzniouf', 'count': 2}
    assert expected_wordset == result[0]

    # Test wrong table
    # Exception is expected
    with pytest.raises(vql.VQLSyntaxError, match=r".*truc doesn't exists.*"):
        list(command.execute(conn, "SHOW truc"))
Esempio n. 3
0
def test_import_cmd(conn):
    """Test import wordset from file (import_cmd is for word sets only FOR NOW)

    Import from a kindly external file with 2 genes.
    """
    # Test import of word set
    test_file = "examples/gene.txt"
    wordset_name = "boby"

    command.import_cmd(conn, "wordsets", wordset_name, test_file)

    for record in conn.execute("SELECT * FROM wordsets"):
        item = dict(record)
        assert item["name"] == wordset_name
Esempio n. 4
0
    def import_wordset(self, words, wordset_name):
        """Import given words into a new wordset in database

        Warnings:
            There is NO CHECK on manual user's inputs! Except during DB insertion.

        Args:
            words(list): List of words to be inserted
            wordset_name(str): Name of the word set

        Returns:
            (boolean): Status of the wordset creation
        """
        # Dump the list in a temporary file
        _, filename = tempfile.mkstemp()
        with open(filename, "w") as file:
            [file.write(word + "\n") for word in words]

        # Import the content of the temp file in DB
        result = import_cmd(self.conn, "wordsets", wordset_name, filename)

        if not result["success"]:
            LOGGER.error(result)
            QMessageBox.critical(
                self,
                self.tr("Error while importing set"),
                self.tr("Error while importing set '%s'") % wordset_name,
            )

        os.remove(filename)
        return result["success"]