Exemple #1
0
def test_no_forwarding_loops_no_session():
    """Confirm no-forwarding-loops assert passes and fails as expected when not specifying a session."""
    with patch.object(bfq, "detectLoops", create=True) as detectLoops:
        # Test success
        detectLoops.return_value = MockQuestion()
        assert_no_forwarding_loops()
        # Test failure
        mock_df = DataFrame.from_records([{"Loop": "found", "More": "data"}])
        detectLoops.return_value = MockQuestion(MockTableAnswer(mock_df))
        with pytest.raises(BatfishAssertException) as excinfo:
            assert_no_forwarding_loops()
        # Ensure found answer is printed
        assert mock_df.to_string() in str(excinfo.value)
Exemple #2
0
def test_no_forwarding_loops():
    """Confirm no-forwarding-loops assert passes and fails as expected when specifying a session."""
    bf = Session(load_questions=False)
    with patch.object(bf.q, 'detectLoops', create=True) as detectLoops:
        # Test success
        detectLoops.return_value = MockQuestion()
        assert_no_forwarding_loops(session=bf)
        # Test failure
        mock_df = DataFrame.from_records([{'Loop': 'found', 'More': 'data'}])
        detectLoops.return_value = MockQuestion(MockTableAnswer(mock_df))
        with pytest.raises(BatfishAssertException) as excinfo:
            assert_no_forwarding_loops(session=bf)
        # Ensure found answer is printed
        assert mock_df.to_string() in str(excinfo.value)
Exemple #3
0
    def assert_no_forwarding_loops(self, snapshot=None, soft=False, df_format="table"):
        # type: (Optional[str], bool, str) -> bool
        """Assert that there are no forwarding loops in the snapshot.

        :param snapshot: the snapshot on which to check the assertion
        :param soft: whether this assertion is soft (i.e., generates a warning but
            not a failure)
        :param df_format: How to format the Dataframe content in the output message.
            Valid options are 'table' and 'records' (each row is a key-value pairs).
        """
        return assert_no_forwarding_loops(snapshot, soft, self.session, df_format)