def testSubclassesOfKeyAndValuePassAssertion(self): class A: pass class B(A): pass dct = {B(): B()} precondition.AssertDictType(dct, A, A)
def ParseRow(header, row): """Parses a single row of osquery output. Args: header: A parsed header describing the row format. row: A row in a "parsed JSON" representation. Returns: A parsed `rdf_osquery.OsqueryRow` instance. """ precondition.AssertDictType(row, Text, Text) result = rdf_osquery.OsqueryRow() for column in header.columns: result.values.append(row[column.name]) return result
def WriteRow(self, values: Dict[Text, Text]): """Writes a single row to the underlying buffer. Args: values: A dictionary mapping column names to values to be inserted into the CSV output. """ precondition.AssertDictType(values, Text, Text) row = [] for column in self._columns: try: value = values[column] except KeyError: raise ValueError("Row does not contain required column `%s`" % column) row.append(value) self._writer.WriteRow(row)
def WriteBlobs(self, blob_id_data_map): precondition.AssertDictType(blob_id_data_map, rdf_objects.BlobID, bytes) return self.delegate.WriteBlobs(blob_id_data_map)
def testNotADictIncorrect(self): with self.assertRaises(TypeError): dct = [(1, "foo"), (2, "bar"), (3, "baz")] precondition.AssertDictType(dct, int, str)
def testIntStringDictCorrect(self): del self # Unused. dct = {1: "foo", 2: "bar", 3: "baz"} precondition.AssertDictType(dct, int, str)
def testWrongValueType(self): with self.assertRaises(TypeError): dct = {"foo": 1, "bar": 2, "baz": 3.14} precondition.AssertDictType(dct, str)
def testWrongKeyType(self): dct = {"foo": 1, b"bar": 2, "baz": 3} with self.assertRaises(TypeError): precondition.AssertDictType(dct, str, int)
def testSubclassesOfDictPassAssertion(self): dct = collections.UserDict({1: "foo", 2: "bar", 3: "baz"}) precondition.AssertDictType(dct, int, str)