# -*- coding: utf-8 -*- """Unit tests for Python API""" from __future__ import unicode_literals from __future__ import print_function # Standard imports import pytest import tempfile @pytest.fixture() def feed_model_with_SCC(): """Fixture for a Cadbiom model with 4 Strongly Connected Components :return: A list of SCC, and the corrected model with start nodes inserted. :rtype: , > """ scc = [['I', 'K', 'J', 'L'], ['Y', 'X', 'Z']] model = """ """ return scc, model def test_SCC_search(feed_model_with_SCC): """Test the correction of a model by removing Strongly Connected Components - We add a start node for every SCC - We add a transition between the start node and the smallest node of every SCC (sorted in lexicogrpahic order) - Thus, we add xml preamble in the model Keep in mind that by testing the result of the export of a model, we also test its content... """ import cadbiom.models.guard_transitions.analyser.model_corrections as mc model = feed_model_with_SCC[1] # Create the file model in /tmp/ # Note: prevent the deletion of the file after the close() call fd_model = tempfile.NamedTemporaryFile(suffix='.bcx', delete=False) fd_model.write( """ """ ) fd_model.close() # Make a new model file (with "_without_scc" suffix in filename) mc.add_start_nodes(fd_model.name) # Filename + path expected_lines = set(model.split("\n")) with open(fd_model.name[:-4] + "_without_scc.bcx", 'r') as file: found_lines = set(file.read().split("\n")) assert found_lines == expected_lines