diff --git a/.gitignore b/.gitignore index 59ce551..9eb6c4a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,62 @@ !.vscode/extensions.json # volume data -.data \ No newline at end of file +.data + +# Testing +.pytest_cache/ +.coverage +htmlcov/ +coverage.xml +*.cover +.hypothesis/ +.tox/ +.nox/ +*.log + +# Claude settings +.claude/* + +# Poetry +dist/ +*.egg-info/ + +# Build artifacts +build/ +*.so +*.dylib +*.dll + +# IDE files +.idea/ +*.swp +*.swo +*~ +.DS_Store + +# Virtual environments +env/ +.env +.venv +ENV/ +env.bak/ +venv.bak/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# Temporary files +*.tmp +tmp/ +temp/ \ No newline at end of file diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..370e34c --- /dev/null +++ b/poetry.lock @@ -0,0 +1,282 @@ +# This file is automatically @generated by Poetry 2.1.4 and should not be changed by hand. + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +groups = ["dev"] +markers = "sys_platform == \"win32\"" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "coverage" +version = "7.6.1" +description = "Code coverage measurement for Python" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +files = [ + {file = "coverage-7.6.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:b06079abebbc0e89e6163b8e8f0e16270124c154dc6e4a47b413dd538859af16"}, + {file = "coverage-7.6.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:cf4b19715bccd7ee27b6b120e7e9dd56037b9c0681dcc1adc9ba9db3d417fa36"}, + {file = "coverage-7.6.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e61c0abb4c85b095a784ef23fdd4aede7a2628478e7baba7c5e3deba61070a02"}, + {file = "coverage-7.6.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:fd21f6ae3f08b41004dfb433fa895d858f3f5979e7762d052b12aef444e29afc"}, + {file = "coverage-7.6.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8f59d57baca39b32db42b83b2a7ba6f47ad9c394ec2076b084c3f029b7afca23"}, + {file = "coverage-7.6.1-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:a1ac0ae2b8bd743b88ed0502544847c3053d7171a3cff9228af618a068ed9c34"}, + {file = "coverage-7.6.1-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:e6a08c0be454c3b3beb105c0596ebdc2371fab6bb90c0c0297f4e58fd7e1012c"}, + {file = "coverage-7.6.1-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:f5796e664fe802da4f57a168c85359a8fbf3eab5e55cd4e4569fbacecc903959"}, + {file = "coverage-7.6.1-cp310-cp310-win32.whl", hash = "sha256:7bb65125fcbef8d989fa1dd0e8a060999497629ca5b0efbca209588a73356232"}, + {file = "coverage-7.6.1-cp310-cp310-win_amd64.whl", hash = "sha256:3115a95daa9bdba70aea750db7b96b37259a81a709223c8448fa97727d546fe0"}, + {file = "coverage-7.6.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:7dea0889685db8550f839fa202744652e87c60015029ce3f60e006f8c4462c93"}, + {file = "coverage-7.6.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ed37bd3c3b063412f7620464a9ac1314d33100329f39799255fb8d3027da50d3"}, + {file = "coverage-7.6.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d85f5e9a5f8b73e2350097c3756ef7e785f55bd71205defa0bfdaf96c31616ff"}, + {file = "coverage-7.6.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9bc572be474cafb617672c43fe989d6e48d3c83af02ce8de73fff1c6bb3c198d"}, + {file = "coverage-7.6.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0c0420b573964c760df9e9e86d1a9a622d0d27f417e1a949a8a66dd7bcee7bc6"}, + {file = "coverage-7.6.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:1f4aa8219db826ce6be7099d559f8ec311549bfc4046f7f9fe9b5cea5c581c56"}, + {file = "coverage-7.6.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:fc5a77d0c516700ebad189b587de289a20a78324bc54baee03dd486f0855d234"}, + {file = "coverage-7.6.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:b48f312cca9621272ae49008c7f613337c53fadca647d6384cc129d2996d1133"}, + {file = "coverage-7.6.1-cp311-cp311-win32.whl", hash = "sha256:1125ca0e5fd475cbbba3bb67ae20bd2c23a98fac4e32412883f9bcbaa81c314c"}, + {file = "coverage-7.6.1-cp311-cp311-win_amd64.whl", hash = "sha256:8ae539519c4c040c5ffd0632784e21b2f03fc1340752af711f33e5be83a9d6c6"}, + {file = "coverage-7.6.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:95cae0efeb032af8458fc27d191f85d1717b1d4e49f7cb226cf526ff28179778"}, + {file = "coverage-7.6.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:5621a9175cf9d0b0c84c2ef2b12e9f5f5071357c4d2ea6ca1cf01814f45d2391"}, + {file = "coverage-7.6.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:260933720fdcd75340e7dbe9060655aff3af1f0c5d20f46b57f262ab6c86a5e8"}, + {file = "coverage-7.6.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:07e2ca0ad381b91350c0ed49d52699b625aab2b44b65e1b4e02fa9df0e92ad2d"}, + {file = "coverage-7.6.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c44fee9975f04b33331cb8eb272827111efc8930cfd582e0320613263ca849ca"}, + {file = "coverage-7.6.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:877abb17e6339d96bf08e7a622d05095e72b71f8afd8a9fefc82cf30ed944163"}, + {file = "coverage-7.6.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:3e0cadcf6733c09154b461f1ca72d5416635e5e4ec4e536192180d34ec160f8a"}, + {file = "coverage-7.6.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:c3c02d12f837d9683e5ab2f3d9844dc57655b92c74e286c262e0fc54213c216d"}, + {file = "coverage-7.6.1-cp312-cp312-win32.whl", hash = "sha256:e05882b70b87a18d937ca6768ff33cc3f72847cbc4de4491c8e73880766718e5"}, + {file = "coverage-7.6.1-cp312-cp312-win_amd64.whl", hash = "sha256:b5d7b556859dd85f3a541db6a4e0167b86e7273e1cdc973e5b175166bb634fdb"}, + {file = "coverage-7.6.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:a4acd025ecc06185ba2b801f2de85546e0b8ac787cf9d3b06e7e2a69f925b106"}, + {file = "coverage-7.6.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:a6d3adcf24b624a7b778533480e32434a39ad8fa30c315208f6d3e5542aeb6e9"}, + {file = "coverage-7.6.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d0c212c49b6c10e6951362f7c6df3329f04c2b1c28499563d4035d964ab8e08c"}, + {file = "coverage-7.6.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6e81d7a3e58882450ec4186ca59a3f20a5d4440f25b1cff6f0902ad890e6748a"}, + {file = "coverage-7.6.1-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:78b260de9790fd81e69401c2dc8b17da47c8038176a79092a89cb2b7d945d060"}, + {file = "coverage-7.6.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:a78d169acd38300060b28d600344a803628c3fd585c912cacc9ea8790fe96862"}, + {file = "coverage-7.6.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:2c09f4ce52cb99dd7505cd0fc8e0e37c77b87f46bc9c1eb03fe3bc9991085388"}, + {file = "coverage-7.6.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:6878ef48d4227aace338d88c48738a4258213cd7b74fd9a3d4d7582bb1d8a155"}, + {file = "coverage-7.6.1-cp313-cp313-win32.whl", hash = "sha256:44df346d5215a8c0e360307d46ffaabe0f5d3502c8a1cefd700b34baf31d411a"}, + {file = "coverage-7.6.1-cp313-cp313-win_amd64.whl", hash = "sha256:8284cf8c0dd272a247bc154eb6c95548722dce90d098c17a883ed36e67cdb129"}, + {file = "coverage-7.6.1-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:d3296782ca4eab572a1a4eca686d8bfb00226300dcefdf43faa25b5242ab8a3e"}, + {file = "coverage-7.6.1-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:502753043567491d3ff6d08629270127e0c31d4184c4c8d98f92c26f65019962"}, + {file = "coverage-7.6.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6a89ecca80709d4076b95f89f308544ec8f7b4727e8a547913a35f16717856cb"}, + {file = "coverage-7.6.1-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a318d68e92e80af8b00fa99609796fdbcdfef3629c77c6283566c6f02c6d6704"}, + {file = "coverage-7.6.1-cp313-cp313t-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:13b0a73a0896988f053e4fbb7de6d93388e6dd292b0d87ee51d106f2c11b465b"}, + {file = "coverage-7.6.1-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:4421712dbfc5562150f7554f13dde997a2e932a6b5f352edcce948a815efee6f"}, + {file = "coverage-7.6.1-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:166811d20dfea725e2e4baa71fffd6c968a958577848d2131f39b60043400223"}, + {file = "coverage-7.6.1-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:225667980479a17db1048cb2bf8bfb39b8e5be8f164b8f6628b64f78a72cf9d3"}, + {file = "coverage-7.6.1-cp313-cp313t-win32.whl", hash = "sha256:170d444ab405852903b7d04ea9ae9b98f98ab6d7e63e1115e82620807519797f"}, + {file = "coverage-7.6.1-cp313-cp313t-win_amd64.whl", hash = "sha256:b9f222de8cded79c49bf184bdbc06630d4c58eec9459b939b4a690c82ed05657"}, + {file = "coverage-7.6.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6db04803b6c7291985a761004e9060b2bca08da6d04f26a7f2294b8623a0c1a0"}, + {file = "coverage-7.6.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:f1adfc8ac319e1a348af294106bc6a8458a0f1633cc62a1446aebc30c5fa186a"}, + {file = "coverage-7.6.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a95324a9de9650a729239daea117df21f4b9868ce32e63f8b650ebe6cef5595b"}, + {file = "coverage-7.6.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b43c03669dc4618ec25270b06ecd3ee4fa94c7f9b3c14bae6571ca00ef98b0d3"}, + {file = "coverage-7.6.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8929543a7192c13d177b770008bc4e8119f2e1f881d563fc6b6305d2d0ebe9de"}, + {file = "coverage-7.6.1-cp38-cp38-musllinux_1_2_aarch64.whl", hash = "sha256:a09ece4a69cf399510c8ab25e0950d9cf2b42f7b3cb0374f95d2e2ff594478a6"}, + {file = "coverage-7.6.1-cp38-cp38-musllinux_1_2_i686.whl", hash = "sha256:9054a0754de38d9dbd01a46621636689124d666bad1936d76c0341f7d71bf569"}, + {file = "coverage-7.6.1-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:0dbde0f4aa9a16fa4d754356a8f2e36296ff4d83994b2c9d8398aa32f222f989"}, + {file = "coverage-7.6.1-cp38-cp38-win32.whl", hash = "sha256:da511e6ad4f7323ee5702e6633085fb76c2f893aaf8ce4c51a0ba4fc07580ea7"}, + {file = "coverage-7.6.1-cp38-cp38-win_amd64.whl", hash = "sha256:3f1156e3e8f2872197af3840d8ad307a9dd18e615dc64d9ee41696f287c57ad8"}, + {file = "coverage-7.6.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:abd5fd0db5f4dc9289408aaf34908072f805ff7792632250dcb36dc591d24255"}, + {file = "coverage-7.6.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:547f45fa1a93154bd82050a7f3cddbc1a7a4dd2a9bf5cb7d06f4ae29fe94eaf8"}, + {file = "coverage-7.6.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:645786266c8f18a931b65bfcefdbf6952dd0dea98feee39bd188607a9d307ed2"}, + {file = "coverage-7.6.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9e0b2df163b8ed01d515807af24f63de04bebcecbd6c3bfeff88385789fdf75a"}, + {file = "coverage-7.6.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:609b06f178fe8e9f89ef676532760ec0b4deea15e9969bf754b37f7c40326dbc"}, + {file = "coverage-7.6.1-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:702855feff378050ae4f741045e19a32d57d19f3e0676d589df0575008ea5004"}, + {file = "coverage-7.6.1-cp39-cp39-musllinux_1_2_i686.whl", hash = "sha256:2bdb062ea438f22d99cba0d7829c2ef0af1d768d1e4a4f528087224c90b132cb"}, + {file = "coverage-7.6.1-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:9c56863d44bd1c4fe2abb8a4d6f5371d197f1ac0ebdee542f07f35895fc07f36"}, + {file = "coverage-7.6.1-cp39-cp39-win32.whl", hash = "sha256:6e2cd258d7d927d09493c8df1ce9174ad01b381d4729a9d8d4e38670ca24774c"}, + {file = "coverage-7.6.1-cp39-cp39-win_amd64.whl", hash = "sha256:06a737c882bd26d0d6ee7269b20b12f14a8704807a01056c80bb881a4b2ce6ca"}, + {file = "coverage-7.6.1-pp38.pp39.pp310-none-any.whl", hash = "sha256:e9a6e0eb86070e8ccaedfbd9d38fec54864f3125ab95419970575b42af7541df"}, + {file = "coverage-7.6.1.tar.gz", hash = "sha256:953510dfb7b12ab69d20135a0662397f077c59b1e6379a768e97c59d852ee51d"}, +] + +[package.dependencies] +tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.11.0a6\" and extra == \"toml\""} + +[package.extras] +toml = ["tomli ; python_full_version <= \"3.11.0a6\""] + +[[package]] +name = "exceptiongroup" +version = "1.3.0" +description = "Backport of PEP 654 (exception groups)" +optional = false +python-versions = ">=3.7" +groups = ["dev"] +markers = "python_version < \"3.11\"" +files = [ + {file = "exceptiongroup-1.3.0-py3-none-any.whl", hash = "sha256:4d111e6e0c13d0644cad6ddaa7ed0261a0b36971f6d23e7ec9b4b9097da78a10"}, + {file = "exceptiongroup-1.3.0.tar.gz", hash = "sha256:b241f5885f560bc56a59ee63ca4c6a8bfa46ae4ad651af316d4e81817bb9fd88"}, +] + +[package.dependencies] +typing-extensions = {version = ">=4.6.0", markers = "python_version < \"3.13\""} + +[package.extras] +test = ["pytest (>=6)"] + +[[package]] +name = "iniconfig" +version = "2.1.0" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +files = [ + {file = "iniconfig-2.1.0-py3-none-any.whl", hash = "sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760"}, + {file = "iniconfig-2.1.0.tar.gz", hash = "sha256:3abbd2e30b36733fee78f9c7f7308f2d0050e88f0087fd25c2645f63c773e1c7"}, +] + +[[package]] +name = "packaging" +version = "25.0" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +files = [ + {file = "packaging-25.0-py3-none-any.whl", hash = "sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484"}, + {file = "packaging-25.0.tar.gz", hash = "sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f"}, +] + +[[package]] +name = "pluggy" +version = "1.5.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +files = [ + {file = "pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669"}, + {file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + +[[package]] +name = "pytest" +version = "7.4.4" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.7" +groups = ["dev"] +files = [ + {file = "pytest-7.4.4-py3-none-any.whl", hash = "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"}, + {file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" +tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + +[[package]] +name = "pytest-cov" +version = "4.1.0" +description = "Pytest plugin for measuring coverage." +optional = false +python-versions = ">=3.7" +groups = ["dev"] +files = [ + {file = "pytest-cov-4.1.0.tar.gz", hash = "sha256:3904b13dfbfec47f003b8e77fd5b589cd11904a21ddf1ab38a64f204d6a10ef6"}, + {file = "pytest_cov-4.1.0-py3-none-any.whl", hash = "sha256:6ba70b9e97e69fcc3fb45bfeab2d0a138fb65c4d0d6a41ef33983ad114be8c3a"}, +] + +[package.dependencies] +coverage = {version = ">=5.2.1", extras = ["toml"]} +pytest = ">=4.6" + +[package.extras] +testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtualenv"] + +[[package]] +name = "pytest-mock" +version = "3.14.1" +description = "Thin-wrapper around the mock package for easier use with pytest" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +files = [ + {file = "pytest_mock-3.14.1-py3-none-any.whl", hash = "sha256:178aefcd11307d874b4cd3100344e7e2d888d9791a6a1d9bfe90fbc1b74fd1d0"}, + {file = "pytest_mock-3.14.1.tar.gz", hash = "sha256:159e9edac4c451ce77a5cdb9fc5d1100708d2dd4ba3c3df572f14097351af80e"}, +] + +[package.dependencies] +pytest = ">=6.2.5" + +[package.extras] +dev = ["pre-commit", "pytest-asyncio", "tox"] + +[[package]] +name = "tomli" +version = "2.2.1" +description = "A lil' TOML parser" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +markers = "python_full_version <= \"3.11.0a6\"" +files = [ + {file = "tomli-2.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249"}, + {file = "tomli-2.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:023aa114dd824ade0100497eb2318602af309e5a55595f76b626d6d9f3b7b0a6"}, + {file = "tomli-2.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ece47d672db52ac607a3d9599a9d48dcb2f2f735c6c2d1f34130085bb12b112a"}, + {file = "tomli-2.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6972ca9c9cc9f0acaa56a8ca1ff51e7af152a9f87fb64623e31d5c83700080ee"}, + {file = "tomli-2.2.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c954d2250168d28797dd4e3ac5cf812a406cd5a92674ee4c8f123c889786aa8e"}, + {file = "tomli-2.2.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:8dd28b3e155b80f4d54beb40a441d366adcfe740969820caf156c019fb5c7ec4"}, + {file = "tomli-2.2.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:e59e304978767a54663af13c07b3d1af22ddee3bb2fb0618ca1593e4f593a106"}, + {file = "tomli-2.2.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:33580bccab0338d00994d7f16f4c4ec25b776af3ffaac1ed74e0b3fc95e885a8"}, + {file = "tomli-2.2.1-cp311-cp311-win32.whl", hash = "sha256:465af0e0875402f1d226519c9904f37254b3045fc5084697cefb9bdde1ff99ff"}, + {file = "tomli-2.2.1-cp311-cp311-win_amd64.whl", hash = "sha256:2d0f2fdd22b02c6d81637a3c95f8cd77f995846af7414c5c4b8d0545afa1bc4b"}, + {file = "tomli-2.2.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:4a8f6e44de52d5e6c657c9fe83b562f5f4256d8ebbfe4ff922c495620a7f6cea"}, + {file = "tomli-2.2.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:8d57ca8095a641b8237d5b079147646153d22552f1c637fd3ba7f4b0b29167a8"}, + {file = "tomli-2.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e340144ad7ae1533cb897d406382b4b6fede8890a03738ff1683af800d54192"}, + {file = "tomli-2.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:db2b95f9de79181805df90bedc5a5ab4c165e6ec3fe99f970d0e302f384ad222"}, + {file = "tomli-2.2.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:40741994320b232529c802f8bc86da4e1aa9f413db394617b9a256ae0f9a7f77"}, + {file = "tomli-2.2.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:400e720fe168c0f8521520190686ef8ef033fb19fc493da09779e592861b78c6"}, + {file = "tomli-2.2.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:02abe224de6ae62c19f090f68da4e27b10af2b93213d36cf44e6e1c5abd19fdd"}, + {file = "tomli-2.2.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:b82ebccc8c8a36f2094e969560a1b836758481f3dc360ce9a3277c65f374285e"}, + {file = "tomli-2.2.1-cp312-cp312-win32.whl", hash = "sha256:889f80ef92701b9dbb224e49ec87c645ce5df3fa2cc548664eb8a25e03127a98"}, + {file = "tomli-2.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:7fc04e92e1d624a4a63c76474610238576942d6b8950a2d7f908a340494e67e4"}, + {file = "tomli-2.2.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f4039b9cbc3048b2416cc57ab3bda989a6fcf9b36cf8937f01a6e731b64f80d7"}, + {file = "tomli-2.2.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:286f0ca2ffeeb5b9bd4fcc8d6c330534323ec51b2f52da063b11c502da16f30c"}, + {file = "tomli-2.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a92ef1a44547e894e2a17d24e7557a5e85a9e1d0048b0b5e7541f76c5032cb13"}, + {file = "tomli-2.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9316dc65bed1684c9a98ee68759ceaed29d229e985297003e494aa825ebb0281"}, + {file = "tomli-2.2.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e85e99945e688e32d5a35c1ff38ed0b3f41f43fad8df0bdf79f72b2ba7bc5272"}, + {file = "tomli-2.2.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ac065718db92ca818f8d6141b5f66369833d4a80a9d74435a268c52bdfa73140"}, + {file = "tomli-2.2.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:d920f33822747519673ee656a4b6ac33e382eca9d331c87770faa3eef562aeb2"}, + {file = "tomli-2.2.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:a198f10c4d1b1375d7687bc25294306e551bf1abfa4eace6650070a5c1ae2744"}, + {file = "tomli-2.2.1-cp313-cp313-win32.whl", hash = "sha256:d3f5614314d758649ab2ab3a62d4f2004c825922f9e370b29416484086b264ec"}, + {file = "tomli-2.2.1-cp313-cp313-win_amd64.whl", hash = "sha256:a38aa0308e754b0e3c67e344754dff64999ff9b513e691d0e786265c93583c69"}, + {file = "tomli-2.2.1-py3-none-any.whl", hash = "sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc"}, + {file = "tomli-2.2.1.tar.gz", hash = "sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff"}, +] + +[[package]] +name = "typing-extensions" +version = "4.13.2" +description = "Backported and Experimental Type Hints for Python 3.8+" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +markers = "python_version < \"3.11\"" +files = [ + {file = "typing_extensions-4.13.2-py3-none-any.whl", hash = "sha256:a439e7c04b49fec3e5d3e2beaa21755cadbbdc391694e28ccdd36ca4a1408f8c"}, + {file = "typing_extensions-4.13.2.tar.gz", hash = "sha256:e6c81219bd689f51865d9e372991c540bda33a0379d5573cddb9a3a23f7caaef"}, +] + +[metadata] +lock-version = "2.1" +python-versions = "^3.8" +content-hash = "21d3d83e69defcf57f1fed466103c07f0e023eed086c25facaef854d0678ea59" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..042a132 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,100 @@ +[tool.poetry] +name = "tor-scraper" +version = "0.1.0" +description = "Tor network scraper and analysis tool" +authors = ["Your Name "] +readme = "README.md" +packages = [ + { include = "lib" }, + { include = "torscraper" }, +] + +[tool.poetry.dependencies] +python = "^3.8" + +[tool.poetry.group.dev.dependencies] +pytest = "^7.4.0" +pytest-cov = "^4.1.0" +pytest-mock = "^3.11.0" + +[tool.poetry.scripts] +test = "pytest:main" +tests = "pytest:main" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" + +[tool.pytest.ini_options] +minversion = "7.0" +testpaths = ["tests"] +python_files = ["test_*.py", "*_test.py"] +python_classes = ["Test*"] +python_functions = ["test_*"] +addopts = [ + "-ra", + "--strict-markers", + "--strict-config", + "--cov=lib", + "--cov=torscraper", + "--cov-branch", + "--cov-report=term-missing:skip-covered", + "--cov-report=html:htmlcov", + "--cov-report=xml:coverage.xml", + "--cov-fail-under=80", + "-vv", +] +markers = [ + "unit: Unit tests that test individual components in isolation", + "integration: Integration tests that test multiple components together", + "slow: Tests that take a long time to run (deselect with '-m \"not slow\"')", +] +filterwarnings = [ + "error", + "ignore::UserWarning", + "ignore::DeprecationWarning", +] + +[tool.coverage.run] +source = ["lib", "torscraper"] +branch = true +parallel = true +omit = [ + "*/tests/*", + "*/test_*.py", + "*/__pycache__/*", + "*/migrations/*", + "*/config/*", + "*/settings/*", + "*/manage.py", + "*/setup.py", + "*/wsgi.py", + "*/asgi.py", +] + +[tool.coverage.report] +precision = 2 +show_missing = true +skip_covered = false +skip_empty = true +exclude_lines = [ + "pragma: no cover", + "def __repr__", + "def __str__", + "raise AssertionError", + "raise NotImplementedError", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", + "if typing.TYPE_CHECKING:", + "@abstractmethod", + "@abc.abstractmethod", + "except ImportError:", + "pass", +] + +[tool.coverage.html] +directory = "htmlcov" +title = "Test Coverage Report" + +[tool.coverage.xml] +output = "coverage.xml" \ No newline at end of file diff --git a/pyproject_full.toml b/pyproject_full.toml new file mode 100644 index 0000000..b7c43ac --- /dev/null +++ b/pyproject_full.toml @@ -0,0 +1,109 @@ +[tool.poetry] +name = "tor-scraper" +version = "0.1.0" +description = "Tor network scraper and analysis tool" +authors = ["Your Name "] +readme = "README.md" +packages = [ + { include = "lib" }, + { include = "torscraper" }, +] + +[tool.poetry.dependencies] +python = "^3.8" +beautifulsoup4 = "^4.9.3" +requests = "^2.26.0" +scrapy = "^2.3.0" +elasticsearch = "^7.5.1" +flask = "^1.1.2" +numpy = "^1.19.1" +scikit-learn = "^0.23.2" +lxml = "^4.6.2" +pyyaml = "^5.3.1" + +[tool.poetry.group.dev.dependencies] +pytest = "^7.4.0" +pytest-cov = "^4.1.0" +pytest-mock = "^3.11.0" + +[tool.poetry.scripts] +test = "pytest:main" +tests = "pytest:main" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" + +[tool.pytest.ini_options] +minversion = "7.0" +testpaths = ["tests"] +python_files = ["test_*.py", "*_test.py"] +python_classes = ["Test*"] +python_functions = ["test_*"] +addopts = [ + "-ra", + "--strict-markers", + "--strict-config", + "--cov=lib", + "--cov=torscraper", + "--cov-branch", + "--cov-report=term-missing:skip-covered", + "--cov-report=html:htmlcov", + "--cov-report=xml:coverage.xml", + "--cov-fail-under=80", + "-vv", +] +markers = [ + "unit: Unit tests that test individual components in isolation", + "integration: Integration tests that test multiple components together", + "slow: Tests that take a long time to run (deselect with '-m \"not slow\"')", +] +filterwarnings = [ + "error", + "ignore::UserWarning", + "ignore::DeprecationWarning", +] + +[tool.coverage.run] +source = ["lib", "torscraper"] +branch = true +parallel = true +omit = [ + "*/tests/*", + "*/test_*.py", + "*/__pycache__/*", + "*/migrations/*", + "*/config/*", + "*/settings/*", + "*/manage.py", + "*/setup.py", + "*/wsgi.py", + "*/asgi.py", +] + +[tool.coverage.report] +precision = 2 +show_missing = true +skip_covered = false +skip_empty = true +exclude_lines = [ + "pragma: no cover", + "def __repr__", + "def __str__", + "raise AssertionError", + "raise NotImplementedError", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", + "if typing.TYPE_CHECKING:", + "@abstractmethod", + "@abc.abstractmethod", + "except ImportError:", + "pass", +] + +[tool.coverage.html] +directory = "htmlcov" +title = "Test Coverage Report" + +[tool.coverage.xml] +output = "coverage.xml" \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..73d90cd --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +# Test package initialization diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..6ee8819 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,387 @@ +""" +Shared pytest fixtures and configuration for all tests. +""" +import os +import sys +import json +import tempfile +import shutil +from pathlib import Path +from unittest.mock import Mock, MagicMock +from datetime import datetime, timedelta +from typing import Generator, Dict, Any, List + +import pytest + +# Add project root to Python path +PROJECT_ROOT = Path(__file__).parent.parent +sys.path.insert(0, str(PROJECT_ROOT)) + + +# ==================== Directory and File Fixtures ==================== + +@pytest.fixture +def temp_dir() -> Generator[Path, None, None]: + """Create a temporary directory for test files.""" + temp_path = Path(tempfile.mkdtemp()) + yield temp_path + shutil.rmtree(temp_path) + + +@pytest.fixture +def temp_file(temp_dir: Path) -> Generator[Path, None, None]: + """Create a temporary file for testing.""" + temp_file_path = temp_dir / "test_file.txt" + temp_file_path.write_text("test content") + yield temp_file_path + + +@pytest.fixture +def sample_html_file(temp_dir: Path) -> Path: + """Create a sample HTML file for testing.""" + html_content = """ + + + Test Page + +

Test Header

+

Test paragraph content.

+ Onion Link + + + """ + html_file = temp_dir / "test.html" + html_file.write_text(html_content) + return html_file + + +# ==================== Configuration Fixtures ==================== + +@pytest.fixture +def test_config() -> Dict[str, Any]: + """Provide test configuration settings.""" + return { + "database": { + "host": "localhost", + "port": 3306, + "user": "test_user", + "password": "test_pass", + "database": "test_db" + }, + "elasticsearch": { + "host": "localhost", + "port": 9200, + "index": "test_index" + }, + "tor": { + "proxy_host": "127.0.0.1", + "proxy_port": 9050, + "control_port": 9051 + }, + "scraper": { + "timeout": 30, + "max_retries": 3, + "user_agent": "Test Bot 1.0" + }, + "paths": { + "data_dir": "/tmp/test_data", + "log_dir": "/tmp/test_logs", + "cache_dir": "/tmp/test_cache" + } + } + + +@pytest.fixture +def env_vars(monkeypatch) -> None: + """Set up test environment variables.""" + test_env = { + "DATABASE_URL": "mysql://test_user:test_pass@localhost:3306/test_db", + "ELASTICSEARCH_URL": "http://localhost:9200", + "TOR_PROXY": "socks5://127.0.0.1:9050", + "DEBUG": "True", + "TESTING": "True" + } + for key, value in test_env.items(): + monkeypatch.setenv(key, value) + + +# ==================== Mock Objects Fixtures ==================== + +@pytest.fixture +def mock_database() -> Mock: + """Create a mock database connection.""" + mock_db = Mock() + mock_db.execute.return_value = Mock() + mock_db.fetchall.return_value = [] + mock_db.fetchone.return_value = None + mock_db.commit.return_value = None + mock_db.rollback.return_value = None + return mock_db + + +@pytest.fixture +def mock_elasticsearch() -> Mock: + """Create a mock Elasticsearch client.""" + mock_es = Mock() + mock_es.index.return_value = {"_id": "test_id", "result": "created"} + mock_es.search.return_value = { + "hits": { + "total": {"value": 0}, + "hits": [] + } + } + mock_es.ping.return_value = True + return mock_es + + +@pytest.fixture +def mock_tor_session() -> Mock: + """Create a mock Tor session.""" + mock_session = Mock() + mock_response = Mock() + mock_response.status_code = 200 + mock_response.text = "Test content" + mock_response.content = b"Test content" + mock_response.headers = {"Content-Type": "text/html"} + mock_session.get.return_value = mock_response + mock_session.post.return_value = mock_response + return mock_session + + +# ==================== Data Fixtures ==================== + +@pytest.fixture +def sample_onion_data() -> Dict[str, Any]: + """Provide sample onion site data.""" + return { + "domain": "test123onion.onion", + "url": "http://test123onion.onion", + "title": "Test Onion Site", + "description": "A test onion site for unit testing", + "last_seen": datetime.now().isoformat(), + "first_seen": (datetime.now() - timedelta(days=30)).isoformat(), + "status": "online", + "language": "en", + "category": "test", + "ports": [80, 443], + "services": ["http", "https"], + "ssh_fingerprint": None, + "bitcoin_addresses": [], + "email_addresses": [], + "phone_numbers": [], + "social_media": [], + "metadata": { + "server": "nginx", + "powered_by": "unknown", + "generator": None + } + } + + +@pytest.fixture +def sample_bitcoin_addresses() -> List[str]: + """Provide sample Bitcoin addresses for testing.""" + return [ + "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", # Genesis block address + "3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy", # P2SH address + "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq", # Bech32 address + ] + + +@pytest.fixture +def sample_email_addresses() -> List[str]: + """Provide sample email addresses for testing.""" + return [ + "test@example.com", + "admin@test.onion", + "user123@protonmail.com", + "contact@securemail.onion" + ] + + +@pytest.fixture +def sample_banned_words() -> List[str]: + """Provide sample banned words for testing.""" + return [ + "illegal", + "banned", + "prohibited", + "restricted" + ] + + +# ==================== Network Fixtures ==================== + +@pytest.fixture +def mock_port_scanner() -> Mock: + """Create a mock port scanner.""" + mock_scanner = Mock() + mock_scanner.scan.return_value = { + "scan": { + "127.0.0.1": { + "tcp": { + 80: {"state": "open", "name": "http"}, + 443: {"state": "open", "name": "https"}, + 22: {"state": "closed", "name": "ssh"} + } + } + } + } + return mock_scanner + + +@pytest.fixture +def mock_whatweb_output() -> Dict[str, Any]: + """Provide mock WhatWeb output.""" + return { + "target": "http://test.onion", + "plugins": { + "HTTPServer": {"string": ["nginx/1.18.0"]}, + "Country": {"string": ["RESERVED"]}, + "IP": {"string": ["127.0.0.1"]}, + "Title": {"string": ["Test Page"]}, + "X-Powered-By": {"string": ["PHP/7.4.3"]}, + "WordPress": {"version": ["5.8.1"]} + } + } + + +# ==================== Time and Date Fixtures ==================== + +@pytest.fixture +def frozen_time(monkeypatch) -> datetime: + """Freeze time for consistent testing.""" + frozen = datetime(2024, 1, 1, 12, 0, 0) + + class MockDatetime: + @classmethod + def now(cls): + return frozen + + @classmethod + def utcnow(cls): + return frozen + + monkeypatch.setattr("datetime.datetime", MockDatetime) + return frozen + + +# ==================== Cleanup Fixtures ==================== + +@pytest.fixture(autouse=True) +def cleanup_test_files(request): + """Automatically clean up test files after each test.""" + # Setup + test_files = [] + + def register_cleanup(filepath): + test_files.append(filepath) + + request.addfinalizer(lambda: [ + os.unlink(f) for f in test_files if os.path.exists(f) + ]) + + return register_cleanup + + +# ==================== Parametrized Test Helpers ==================== + +def pytest_generate_tests(metafunc): + """ + Custom test generation for parametrized tests. + + This allows tests to use custom markers for parametrization. + """ + if "onion_url" in metafunc.fixturenames: + metafunc.parametrize("onion_url", [ + "http://test.onion", + "https://secure.onion", + "http://3g2upl4pq3kufc4m.onion", # DuckDuckGo onion + ]) + + if "http_status" in metafunc.fixturenames: + metafunc.parametrize("http_status", [200, 404, 500, 503]) + + +# ==================== Assertion Helpers ==================== + +class AssertionHelpers: + """Helper methods for common test assertions.""" + + @staticmethod + def assert_valid_onion_url(url: str) -> None: + """Assert that a URL is a valid onion address.""" + assert url.endswith(".onion") or ".onion/" in url + assert url.startswith(("http://", "https://")) + + @staticmethod + def assert_valid_bitcoin_address(address: str) -> None: + """Assert that a string is a valid Bitcoin address format.""" + assert len(address) in [26, 34, 42, 62] # Various Bitcoin address lengths + assert address[0] in ["1", "3", "b"] # Valid first characters + + @staticmethod + def assert_valid_email(email: str) -> None: + """Assert that a string is a valid email format.""" + assert "@" in email + assert "." in email.split("@")[1] + + +@pytest.fixture +def assert_helpers() -> AssertionHelpers: + """Provide assertion helper methods.""" + return AssertionHelpers() + + +# ==================== Performance Testing ==================== + +@pytest.fixture +def benchmark_timer(): + """Simple benchmark timer for performance tests.""" + import time + + class Timer: + def __init__(self): + self.start_time = None + self.end_time = None + + def start(self): + self.start_time = time.time() + + def stop(self): + self.end_time = time.time() + + @property + def elapsed(self): + if self.start_time and self.end_time: + return self.end_time - self.start_time + return None + + return Timer() + + +# ==================== Database Fixtures ==================== + +@pytest.fixture +def sample_database_schema() -> str: + """Provide sample database schema for testing.""" + return """ + CREATE TABLE IF NOT EXISTS domains ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + domain VARCHAR(255) UNIQUE NOT NULL, + title TEXT, + status VARCHAR(50), + first_seen DATETIME, + last_seen DATETIME, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP + ); + + CREATE TABLE IF NOT EXISTS pages ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + domain_id INTEGER, + url TEXT NOT NULL, + content TEXT, + scraped_at DATETIME, + FOREIGN KEY (domain_id) REFERENCES domains(id) + ); + """ \ No newline at end of file diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 0000000..05065e8 --- /dev/null +++ b/tests/integration/__init__.py @@ -0,0 +1 @@ +# Integration test package initialization \ No newline at end of file diff --git a/tests/test_setup_validation.py b/tests/test_setup_validation.py new file mode 100644 index 0000000..de868ee --- /dev/null +++ b/tests/test_setup_validation.py @@ -0,0 +1,116 @@ +""" +Validation tests to ensure the testing infrastructure is properly configured. +""" +import sys +from pathlib import Path + +import pytest + + +class TestSetupValidation: + """Validate that the testing infrastructure is properly configured.""" + + def test_project_imports(self): + """Test that project modules can be imported.""" + # Test core library imports + import lib + assert lib is not None + + # Test torscraper imports + import torscraper + assert torscraper is not None + + def test_fixtures_available(self, temp_dir, test_config, mock_database): + """Test that pytest fixtures are available and working.""" + assert temp_dir.exists() + assert temp_dir.is_dir() + + assert isinstance(test_config, dict) + assert "database" in test_config + assert "elasticsearch" in test_config + + assert mock_database is not None + assert hasattr(mock_database, "execute") + + def test_markers_defined(self, request): + """Test that custom markers are properly defined.""" + markers = request.config.getini("markers") + marker_names = [m.split(":")[0].strip() for m in markers] + + assert "unit" in marker_names + assert "integration" in marker_names + assert "slow" in marker_names + + @pytest.mark.unit + def test_unit_marker(self): + """Test that unit marker works.""" + assert True + + @pytest.mark.integration + def test_integration_marker(self): + """Test that integration marker works.""" + assert True + + @pytest.mark.slow + def test_slow_marker(self): + """Test that slow marker works.""" + assert True + + def test_temp_file_creation(self, temp_file): + """Test temporary file fixture.""" + assert temp_file.exists() + assert temp_file.read_text() == "test content" + + def test_mock_elasticsearch(self, mock_elasticsearch): + """Test mock Elasticsearch fixture.""" + assert mock_elasticsearch.ping() is True + + result = mock_elasticsearch.index(index="test", body={"data": "test"}) + assert result["result"] == "created" + + def test_sample_data_fixtures(self, sample_onion_data, sample_bitcoin_addresses): + """Test sample data fixtures.""" + assert sample_onion_data["domain"] == "test123onion.onion" + assert sample_onion_data["status"] == "online" + + assert len(sample_bitcoin_addresses) == 3 + assert sample_bitcoin_addresses[0].startswith("1") + + def test_assertion_helpers(self, assert_helpers): + """Test assertion helper methods.""" + assert_helpers.assert_valid_onion_url("http://test.onion") + assert_helpers.assert_valid_onion_url("https://secure.onion/page") + + with pytest.raises(AssertionError): + assert_helpers.assert_valid_onion_url("http://example.com") + + assert_helpers.assert_valid_email("test@example.com") + + with pytest.raises(AssertionError): + assert_helpers.assert_valid_email("invalid-email") + + def test_benchmark_timer(self, benchmark_timer): + """Test benchmark timer fixture.""" + import time + + benchmark_timer.start() + time.sleep(0.01) # Sleep for 10ms + benchmark_timer.stop() + + assert benchmark_timer.elapsed is not None + assert benchmark_timer.elapsed >= 0.01 + assert benchmark_timer.elapsed < 0.1 # Should be less than 100ms + + def test_coverage_configured(self): + """Test that coverage is properly configured.""" + try: + import pytest_cov + assert pytest_cov is not None + except ImportError: + # Coverage not installed yet, that's OK for validation + pass + + def test_python_path_configured(self): + """Test that Python path includes project root.""" + project_root = str(Path(__file__).parent.parent) + assert project_root in sys.path \ No newline at end of file diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..4a87602 --- /dev/null +++ b/tests/unit/__init__.py @@ -0,0 +1 @@ +# Unit test package initialization \ No newline at end of file