def test_no_undefined_references_no_session(): """Confirm no-undefined-references assert passes and fails as expected when not specifying a session.""" with patch.object(bfq, 'undefinedReferences', create=True) as undefinedReferences: # Test success undefinedReferences.return_value = MockQuestion() assert_no_undefined_references() # Test failure mock_df = DataFrame.from_records( [{'UndefRef': 'found', 'More': 'data'}]) undefinedReferences.return_value = MockQuestion( MockTableAnswer(mock_df)) with pytest.raises(BatfishAssertException) as excinfo: assert_no_undefined_references() # Ensure found answer is printed assert mock_df.to_string() in str(excinfo.value)
def test_no_undefined_references(): """Confirm no-undefined-references assert passes and fails as expected when specifying a session.""" bf = Session(load_questions=False) with patch.object(bf.q, "undefinedReferences", create=True) as undefinedReferences: # Test success undefinedReferences.return_value = MockQuestion() assert_no_undefined_references(session=bf) # Test failure mock_df = DataFrame.from_records([{ "UndefRef": "found", "More": "data" }]) undefinedReferences.return_value = MockQuestion( MockTableAnswer(mock_df)) with pytest.raises(BatfishAssertException) as excinfo: assert_no_undefined_references(session=bf) # Ensure found answer is printed assert mock_df.to_string() in str(excinfo.value)
def assert_no_undefined_references(self, snapshot=None, soft=False, df_format="table"): # type: (Optional[str], bool, str) -> bool """Assert that there are no undefined references present 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_undefined_references(snapshot, soft, self.session, df_format)