From 57284d79fed8360c274b951f24c12a2a1933725f Mon Sep 17 00:00:00 2001
From: Kevin Scott <kevsc634@student.liu.se>
Date: Tue, 10 Mar 2020 19:19:16 +0100
Subject: [PATCH] refactored test cases in port and removed conftest.py

---
 test/graph_id/conftest.py                     |  1 -
 test/port/{test_port.py => test_inputport.py} | 16 ++---
 test/port/test_outputport.py                  | 63 +++++++------------
 test/signal_flow_graph/conftest.py            |  1 -
 4 files changed, 25 insertions(+), 56 deletions(-)
 delete mode 100644 test/graph_id/conftest.py
 rename test/port/{test_port.py => test_inputport.py} (87%)
 delete mode 100644 test/signal_flow_graph/conftest.py

diff --git a/test/graph_id/conftest.py b/test/graph_id/conftest.py
deleted file mode 100644
index 5871ed8e..00000000
--- a/test/graph_id/conftest.py
+++ /dev/null
@@ -1 +0,0 @@
-import pytest
diff --git a/test/port/test_port.py b/test/port/test_inputport.py
similarity index 87%
rename from test/port/test_port.py
rename to test/port/test_inputport.py
index 0a1e759b..7a78d5f7 100644
--- a/test/port/test_port.py
+++ b/test/port/test_inputport.py
@@ -7,7 +7,6 @@ import pytest
 from b_asic import InputPort, OutputPort
 from b_asic import Signal
 
-# Fixtures 
 @pytest.fixture
 def inp_port():
     return InputPort(0, None)
@@ -40,7 +39,6 @@ def connected_sig():
     inp_port = InputPort(0, None)
     return Signal(source=out_port, destination=inp_port)
 
-# Tests
 def test_connect_port_then_disconnect(inp_port, out_port):
     """Test connect unused port to port."""
     s1 = inp_port.connect_port(out_port)
@@ -62,16 +60,10 @@ def test_connect_port_then_disconnect(inp_port, out_port):
     assert s1.destination is None
 
 def test_connect_used_port_to_new_port(inp_port, out_port, out_port2):
-    """Test connect used port to new used port."""
-    s1 = inp_port.connect_port(out_port)
-
-    correct_exception = False
-    try:
-        s2 = inp_port.connect_port(out_port2)
-    except AssertionError:
-        correct_exception = True
-
-    assert correct_exception
+    """Does connecting multiple ports to an inputport throw error?"""
+    inp_port.connect_port(out_port)
+    with pytest.raises(AssertionError):
+        inp_port.connect_port(out_port2)
 
 def test_connect_signal_then_disconnect(inp_port, s_w_source):
     inp_port.connect_signal(s_w_source)
diff --git a/test/port/test_outputport.py b/test/port/test_outputport.py
index 6713e3a0..f48afbdb 100644
--- a/test/port/test_outputport.py
+++ b/test/port/test_outputport.py
@@ -1,52 +1,31 @@
 """
-B-ASIC test suite for InputPort
+B-ASIC test suite for OutputPort
 TODO: More info
 """
-from b_asic import InputPort, OutputPort, Signal
+from b_asic import InputPort, OutputPort
 import pytest
 
-def test_connect_and_disconnect_multiple_signals(signals):
-    """test if multiple signals can connect to an output port."""
-    out_port = OutputPort(0, None)
-    in_port = InputPort(0, None)
-    in_port1 = InputPort(0, None)
-
-    s1 = out_port.connect_port(in_port)
-
-    assert in_port.connected_ports == [out_port]
-    assert out_port.connected_ports == [in_port]
-    assert in_port.signals == [s1]
-    assert out_port.signals == [s1]
-    assert s1.source is out_port
-    assert s1.destination is in_port
-    assert out_port.signal_count() == 1
-
-    s2 = Signal(destination=in_port1)
-    out_port.connect_signal(s2)
+@pytest.fixture
+def inp_ports():
+    return [InputPort(_, None) for _ in range(0,3)]
 
-    assert in_port1.connected_ports == [out_port]
-    assert out_port.connected_ports == [in_port, in_port1]
-    assert in_port1.signals == [s2]
-    assert out_port.signals == [s1, s2]
-    assert s2.source is out_port
-    assert s2.destination is in_port1
-    assert out_port.signal_count() == 2
-
-    s3 = Signal()
-    out_port.connect_signal(s3)
+def test_connect_multiple_signals(inp_ports):
+    """Can multiple ports connect to an output port?"""
+    out_port = OutputPort(0, None)
 
-    assert out_port.connected_ports == [in_port, in_port1]
-    assert out_port.signals == [s1, s2, s3]
-    assert s3.source is out_port
-    assert s3.destination is None
-    assert out_port.signal_count() == 3
+    for port in inp_ports:
+        out_port.connect_port(port)
+    
+    assert out_port.signal_count() == len(inp_ports)
 
-    out_port.disconnect_signal(1)
+def test_disconnect_multiple_signals(inp_ports):
+    """Can multiple ports disconnect from an output port?"""
+    out_port = OutputPort(0, None)
 
-    assert out_port.connected_ports == [in_port]
-    assert out_port.signals == [s1, s3]
-    assert out_port.signal_count() == 2
+    for port in inp_ports:
+        out_port.connect_port(port)
+    
+    for _ in inp_ports:
+        out_port.disconnect_signal(0)
 
-    assert s2.destination is in_port1
-    assert s2.source is None
-    assert in_port1.signals == [s2]
+    assert out_port.signal_count() == 0
\ No newline at end of file
diff --git a/test/signal_flow_graph/conftest.py b/test/signal_flow_graph/conftest.py
deleted file mode 100644
index 5871ed8e..00000000
--- a/test/signal_flow_graph/conftest.py
+++ /dev/null
@@ -1 +0,0 @@
-import pytest
-- 
GitLab