uaf.git

uaf

~
git clone https://github.com/debuman/uaf.git

tests/test_utils.py (2932B)

      1 """Tests for ap_scanner.utils."""
      2 
      3 from ap_scanner.utils import (
      4     ALL_CHANNELS,
      5     CHANNELS_2G,
      6     CHANNELS_5G,
      7     CHANNELS_6G,
      8     channel_band,
      9     channel_to_freq,
     10     freq_to_channel,
     11     parse_channels_arg,
     12 )
     13 
     14 
     15 # --- freq_to_channel ---
     16 
     17 def test_freq_to_channel_2g_ch1():
     18     assert freq_to_channel(2412) == 1
     19 
     20 
     21 def test_freq_to_channel_2g_ch6():
     22     assert freq_to_channel(2437) == 6
     23 
     24 
     25 def test_freq_to_channel_2g_ch11():
     26     assert freq_to_channel(2462) == 11
     27 
     28 
     29 def test_freq_to_channel_5g_ch36():
     30     assert freq_to_channel(5180) == 36
     31 
     32 
     33 def test_freq_to_channel_5g_ch48():
     34     assert freq_to_channel(5240) == 48
     35 
     36 
     37 def test_freq_to_channel_5g_ch149():
     38     assert freq_to_channel(5745) == 149
     39 
     40 
     41 def test_freq_to_channel_unknown():
     42     assert freq_to_channel(0) == 0
     43 
     44 
     45 # --- channel_to_freq ---
     46 
     47 def test_channel_to_freq_2g():
     48     assert channel_to_freq(1) == 2412
     49     assert channel_to_freq(6) == 2437
     50 
     51 
     52 def test_channel_to_freq_5g():
     53     assert channel_to_freq(36) == 5180
     54     assert channel_to_freq(165) == 5825
     55 
     56 
     57 def test_channel_to_freq_invalid():
     58     assert channel_to_freq(999) == 0
     59 
     60 
     61 # --- channel_band ---
     62 
     63 def test_channel_band_2g():
     64     assert channel_band(1) == "2.4"
     65     assert channel_band(6) == "2.4"
     66     assert channel_band(11) == "2.4"
     67 
     68 
     69 def test_channel_band_5g():
     70     assert channel_band(36) == "5"
     71     assert channel_band(149) == "5"
     72     assert channel_band(165) == "5"
     73 
     74 
     75 def test_channel_band_6g_with_freq():
     76     # Channel 1 at 5955 MHz is 6GHz, not 2.4GHz
     77     assert channel_band(1, freq=5955) == "6"
     78     assert channel_band(37, freq=6135) == "6"
     79 
     80 
     81 def test_channel_band_disambiguate_by_freq():
     82     # Channel 1 without freq defaults to 2.4GHz
     83     assert channel_band(1) == "2.4"
     84     # Channel 1 with 2.4GHz freq
     85     assert channel_band(1, freq=2412) == "2.4"
     86     # Channel 1 with 6GHz freq
     87     assert channel_band(1, freq=5955) == "6"
     88 
     89 
     90 def test_freq_to_channel_6g():
     91     assert freq_to_channel(5955) == 1
     92     assert freq_to_channel(6135) == 37
     93 
     94 
     95 def test_channels_6g_contains_common():
     96     for ch in [1, 5, 9, 13, 37, 53, 149, 233]:
     97         assert ch in CHANNELS_6G
     98 
     99 
    100 # --- parse_channels_arg ---
    101 
    102 def test_parse_channels_single():
    103     result = parse_channels_arg("6")
    104     assert result == [6]
    105 
    106 
    107 def test_parse_channels_list():
    108     result = parse_channels_arg("1,6,11")
    109     assert result == [1, 6, 11]
    110 
    111 
    112 def test_parse_channels_range():
    113     result = parse_channels_arg("36-48")
    114     assert result == [36, 40, 44, 48]
    115 
    116 
    117 def test_parse_channels_mixed():
    118     result = parse_channels_arg("1,6,36-48")
    119     assert result == [1, 6, 36, 40, 44, 48]
    120 
    121 
    122 def test_parse_channels_invalid_falls_back():
    123     result = parse_channels_arg("999")
    124     assert result == ALL_CHANNELS
    125 
    126 
    127 # --- Channel lists ---
    128 
    129 def test_channels_2g_range():
    130     assert CHANNELS_2G == list(range(1, 15))
    131 
    132 
    133 def test_channels_5g_contains_common():
    134     for ch in [36, 40, 44, 48, 149, 153, 157, 161, 165]:
    135         assert ch in CHANNELS_5G