From 284f3972844ea124c0cd9ee5500e99440bb96aac Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sun, 31 Aug 2025 01:09:37 +0200 Subject: g2h: Add file page Also move helpers to dedicated files. --- tests/file_test.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/file_test.py (limited to 'tests/file_test.py') diff --git a/tests/file_test.py b/tests/file_test.py new file mode 100644 index 0000000..838df71 --- /dev/null +++ b/tests/file_test.py @@ -0,0 +1,26 @@ +import os +import pytest + +from unittest.mock import Mock + +from g2h.file import sanitize_file_name, tree_join + +def test_sanitize_not_necessary(): + assert(sanitize_file_name('foo', None) == 'foo') + +def test_sanitize_success(): + assert(sanitize_file_name('.test', []) == '_test') + +def test_sanitize_collissions(): + entries = [] + for i in range(1, 10): + entry = Mock() + entry.name = '_' * i + 'test' + entries.append(entry) + with pytest.raises(RuntimeError): + sanitize_file_name('.test', entries) + +def test_tree_join(): + commit = Mock() + commit.hexsha = '123' + assert(tree_join(commit, 'test') == os.path.join('123', 't', 'test')) -- cgit v1.2.3