|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | +# you may not use this file except in compliance with the License. |
| 3 | +# You may obtain a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | + |
| 13 | +from warehouse.tuf.hash_bins import HashBins |
| 14 | + |
| 15 | + |
| 16 | +class TestHashBins: |
| 17 | + def test_basic_init(self): |
| 18 | + test_hash_bins = HashBins(32) |
| 19 | + assert test_hash_bins.number_of_bins == 32 |
| 20 | + assert test_hash_bins.prefix_len == 2 |
| 21 | + assert test_hash_bins.number_of_prefixes == 256 |
| 22 | + assert test_hash_bins.bin_size == 8 |
| 23 | + |
| 24 | + test_hash_bins = HashBins(16) |
| 25 | + assert test_hash_bins.number_of_bins == 16 |
| 26 | + assert test_hash_bins.prefix_len == 1 |
| 27 | + assert test_hash_bins.number_of_prefixes == 16 |
| 28 | + assert test_hash_bins.bin_size == 1 |
| 29 | + |
| 30 | + def test__bin_name(self): |
| 31 | + test_hash_bins = HashBins(32) |
| 32 | + assert test_hash_bins._bin_name(1, 7) == "01-07" |
| 33 | + assert test_hash_bins._bin_name(32, 39) == "20-27" |
| 34 | + |
| 35 | + def test_generate(self): |
| 36 | + test_hash_bins = HashBins(16) |
| 37 | + hash_bin_list = [ |
| 38 | + ("0", ["0"]), |
| 39 | + ("1", ["1"]), |
| 40 | + ("2", ["2"]), |
| 41 | + ("3", ["3"]), |
| 42 | + ("4", ["4"]), |
| 43 | + ("5", ["5"]), |
| 44 | + ("6", ["6"]), |
| 45 | + ("7", ["7"]), |
| 46 | + ("8", ["8"]), |
| 47 | + ("9", ["9"]), |
| 48 | + ("a", ["a"]), |
| 49 | + ("b", ["b"]), |
| 50 | + ("c", ["c"]), |
| 51 | + ("d", ["d"]), |
| 52 | + ("e", ["e"]), |
| 53 | + ("f", ["f"]), |
| 54 | + ] |
| 55 | + for i in test_hash_bins.generate(): |
| 56 | + assert i in hash_bin_list |
| 57 | + |
| 58 | + def test_get_delegate(self): |
| 59 | + test_hash_bins = HashBins(128) |
| 60 | + assert test_hash_bins.get_delegate("filepath0") == "24-25" |
| 61 | + assert test_hash_bins.get_delegate("filepath1") == "d8-d9" |
0 commit comments