diff --git a/py-gtfsort/pyproject.toml b/py-gtfsort/pyproject.toml index 5c42003..43f9e73 100644 --- a/py-gtfsort/pyproject.toml +++ b/py-gtfsort/pyproject.toml @@ -23,3 +23,12 @@ homepage = "https://github.com/alejandrogz/gtfsort" [tool.maturin] features = ["pyo3/extension-module"] +[tool.hatch.envs.default] +dependencies = [ + "pandas", + "pytest", +] + +[tool.hatch.envs.default.scripts] +test = "pytest {args:test}" + diff --git a/py-gtfsort/test/gtfsort.py b/py-gtfsort/test/gtfsort.py deleted file mode 100755 index d371e0b..0000000 --- a/py-gtfsort/test/gtfsort.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 - -import gtfsortpy -from typing import Tuple - -NTHREADS = 4 - -def get_test_file() -> Tuple[str]: - tmp = gtfsortpy.get_test_file() - out = tmp + '.sorted' - return (tmp, out) - -def main(): - tmp, out = get_test_file() - gtfsortpy.sort(tmp, out, NTHREADS) - - -if __name__ == '__main__': - main() - diff --git a/py-gtfsort/test/test_gtfsort.py b/py-gtfsort/test/test_gtfsort.py new file mode 100755 index 0000000..362bb2f --- /dev/null +++ b/py-gtfsort/test/test_gtfsort.py @@ -0,0 +1,43 @@ +import gtfsortpy +import os +import pandas as pd +import pytest +from typing import Tuple +import unittest + +NTHREADS = 4 + +def get_test_file() -> Tuple[str]: + tmp = gtfsortpy.get_test_file() + out = tmp + '.sorted' + return (tmp, out) + +def main(): + tmp, out = get_test_file() + status = gtfsortpy.sort(tmp, out, NTHREADS) + return status + +class TestGtf(unittest.TestCase): + + def setUp(self): + self.tmp, self.out = get_test_file() + self.status = gtfsortpy.sort(self.tmp, self.out, NTHREADS) + + def test_file_creation(self): + self.assertTrue(os.path.isfile(self.out)) + + def test_status_output(self): + self.assertIsNotNone(self.status) + + def test_sorted_file_line_count(self): + expected_line_count = 333875 + with open(self.out, 'r') as f: + line_count = len(f.readlines()) + + self.assertEqual(line_count, expected_line_count) + + def test_sorted_file_order(self): + rule = ['GL456221.1', 'chr1', 'chr2', 'chr3', 'chr5', 'chrM'] + chrom_order = pd.read_csv(self.out, sep='\t', usecols=[0], header=None)[0].unique().tolist() + + self.assertEqual(chrom_order, rule)