Skip to content

Commit

Permalink
Version 0.1.0-beta.8
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Jan 18, 2024
1 parent 12d4e34 commit a21af1d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
6 changes: 3 additions & 3 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ readme = "../README.md"
keywords = ["cli", "postgres", "parquet"]
documentation = "https://github.com/exyi/pg2parquet"
name = "pg2parquet"
version = "0.1.0-beta.7"
version = "0.1.0-beta.8"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
4 changes: 2 additions & 2 deletions py-tests/test_basic_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def test_floats(self):
"f32": pl.Float32,
"f64": pl.Float64
})
self.assertEqual(list(polars_df["f32"].cast(str)), ['1.1', 'NaN', 'inf', '-inf', '0.0'])
self.assertEqual(list(polars_df["f64"].cast(str)), ['2.2', 'NaN', 'inf', '-inf', '0.0'])
self.assertEqual(list(polars_df["f32"].cast(str)), ['1.1', 'NaN', 'inf', '-inf', '-0.0'])
self.assertEqual(list(polars_df["f64"].cast(str)), ['2.2', 'NaN', 'inf', '-inf', '-0.0'])

def test_numeric(self):
file = wrappers.create_and_export(
Expand Down
29 changes: 29 additions & 0 deletions py-tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import wrappers
import unittest

class TestCLI(unittest.TestCase):
def test_prints_version(self) -> None:
p = wrappers.run_pg2parquet(["--version"])
out = p.stdout.decode("utf-8").strip()
self.assertTrue(out.startswith("pg2parquet 0."))
self.assertEqual(1, len(out.splitlines()))

def test_help_global(self) -> None:
p = wrappers.run_pg2parquet(["--help"])
out = p.stdout.decode("utf-8").strip()
self.assertIn("export", out)
self.assertIn("Exports a PostgreSQL table or query to a Parquet file", out)
self.assertIn("--version", out)

def test_help_export(self) -> None:
p = wrappers.run_pg2parquet(["export", "--help"])
out = p.stdout.decode("utf-8").strip()
self.assertIn("--output-file", out)
self.assertIn("--table", out)

def test_h_export(self) -> None:
p = wrappers.run_pg2parquet(["export", "-h"])
out = p.stdout.decode("utf-8").strip()
self.assertIn("--output-file", out)
self.assertIn("--table", out)
self.assertLess(len(out.splitlines()), 40) # short help would better fit on a screen
24 changes: 15 additions & 9 deletions py-tests/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ def run_sql(*commands: str):
cur.execute(command)
conn.commit()

def run_pg2parquet(args: list[str]):
r = subprocess.run([ pg2parquet_binary, *args ], env={
"PGPASSWORD": pg2parquet_password,
}, capture_output=True)
if r.returncode != 0:
print(f"pg2parquet exited with code {r.returncode}. Stdout:")
print(r.stdout.decode("utf-8"))
print("Stderr:")
print(r.stderr.decode("utf-8"))
raise Exception(f"pg2parquet exited with code {r.returncode}")
return r


def run_export(name, query = None, options = []) -> pyarrow.Table:
outfile = os.path.join(output_directory, name + ".parquet")
if query is not None:
Expand All @@ -85,15 +98,8 @@ def run_export(name, query = None, options = []) -> pyarrow.Table:
"--output-file", outfile,
*options
]
r = subprocess.run([ pg2parquet_binary, *args ], env={
"PGPASSWORD": pg2parquet_password,
}, capture_output=True)
if r.returncode != 0:
print(f"pg2parquet exited with code {r.returncode}. Stdout:")
print(r.stdout.decode("utf-8"))
print("Stderr:")
print(r.stderr.decode("utf-8"))
raise Exception(f"pg2parquet exited with code {r.returncode}")

run_pg2parquet(args)

return outfile

Expand Down

0 comments on commit a21af1d

Please sign in to comment.