def types_sequence(self) -> List[int]:
...
- def dump(self, obj: Any, format: Format = Format.TEXT) -> Optional[bytes]:
- ...
-
def get_dumper(self, obj: Any, format: Format) -> "Dumper":
...
def types_sequence(self) -> List[int]:
return self._oids
- # TODO: drop?
- def dump(self, obj: Any, format: Format = Format.TEXT) -> Optional[bytes]:
- if obj is None:
- return None
-
- return self.get_dumper(obj, format).dump(obj)
-
def get_dumper(self, obj: Any, format: Format) -> "Dumper":
key = (type(obj), format)
try:
self, objs: Iterable[Any], formats: Iterable[pq.Format]
) -> List[Optional[bytes]]: ...
def types_sequence(self) -> List[int]: ...
- def dump(
- self, obj: Any, format: pq.Format = pq.Format.TEXT
- ) -> Optional[bytes]: ...
def get_dumper(self, obj: Any, format: pq.Format) -> "Dumper": ...
def lookup_dumper(self, src: type, format: pq.Format) -> DumperType: ...
def load_row(self, row: int) -> Optional[Tuple[Any, ...]]: ...
def types_sequence(self) -> List[int]:
return self._oids
- def dump(self, obj: Any, format: Format = 0) -> Optional[bytes]:
- if obj is None:
- return None
-
- return self.get_dumper(obj, format).dump(obj)
-
def get_dumper(self, obj: Any, format: Format) -> "Dumper":
key = (type(obj), format)
try:
def test_bad_binary_array(input):
tx = Transformer()
with pytest.raises(psycopg3.DataError):
- tx.dump(input, Format.BINARY)
+ tx.get_dumper(input, Format.BINARY).dump(input)
@pytest.mark.parametrize("fmt_out", [Format.TEXT, Format.BINARY])
@pytest.mark.xfail
-def test_array_mixed_numbers():
+@pytest.mark.parametrize(
+ "array, type", [([1, 32767], "int2"), ([1, 32768], "int4")]
+)
+def test_array_mixed_numbers(array, type):
# TODO: must use the type accommodating the largest/highest precision
tx = Transformer()
- ad = tx.dump([1, 32767], Format.BINARY)
- assert ad[1] == builtins["int2"].array_oid
- ad = tx.dump([1, 32768], Format.BINARY)
- assert ad[1] == builtins["int4"].array_oid
+ dumper = tx.get_dumper(array, Format.BINARY)
+ dumper.dump(array)
+ assert dumper.oid == builtins[type].array_oid
def test_dump_int_binary():
# TODO: int binary adaptation (must choose the fitting int2,4,8)
tx = Transformer()
- tx.dump(1, Format.BINARY)
+ n = 1
+ tx.get_dumper(n, Format.BINARY).dump(n)
@pytest.mark.parametrize(
def test_dump_float_binary():
# TODO: float binary adaptation
tx = Transformer()
- tx.dump(1.0, Format.BINARY)
+ n = 1.0
+ tx.get_dumper(n, Format.BINARY).dump(n)
@pytest.mark.parametrize(
def test_dump_numeric_binary():
# TODO: numeric binary adaptation
tx = Transformer()
- tx.dump(Decimal(1), Format.BINARY)
+ n = Decimal(1)
+ tx.get_dumper(n, Format.BINARY).dump(n)
@pytest.mark.xfail