コード例 #1
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_can_be_added():
    urls1 = utils.URLs(('http://foo:123', 'http://bar:456'))
    urls2 = utils.URLs(('http://bar', 'http://baz'))
    assert urls1 + urls2 == ('http://foo:123', 'http://bar:456', 'http://bar',
                             'http://baz')
    assert urls1 + ('http://bar', ) == ('http://foo:123', 'http://bar:456',
                                        'http://bar')
    assert urls1 + 'http://baz' == ('http://foo:123', 'http://bar:456',
                                    'http://baz')
コード例 #2
0
def test_URLs_replace():
    cb = mock.MagicMock()
    urls = utils.URLs(('http://foo:123', 'http://bar:456'),
                      callback=cb)
    urls.replace(['http://asdf', 'http://quux'])
    assert urls == ['http://asdf', 'http://quux']
    assert cb.call_args_list == [mock.call(urls)]
コード例 #3
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_deduplicates_when_inserting():
    urls = utils.URLs(('http://foo:123', 'http://bar:456'))
    urls.insert(1, 'http://foo:123')
    urls.insert(0, 'http://bar:456')
    urls.insert(0, 'http://foo:123')
    urls.insert(1, 'http://bar:456')
    assert urls == ['http://foo:123', 'http://bar:456']
コード例 #4
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_equality():
    urls = utils.URLs(('http://foo:123', 'http://bar:456'))
    assert urls == ('http://foo:123', 'http://bar:456')
    assert urls == ['http://foo:123', 'http://bar:456']
    assert urls != ['http://foo:124', 'http://bar:456']
    assert urls != 'http://bar:456'
    assert urls != 5
    assert urls != None
コード例 #5
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_validates_changed_urls():
    urls = utils.URLs('http://foo:123')
    with pytest.raises(errors.URLError) as e:
        urls[0] = 'http://bar:456:789'
    assert str(e.value) == 'http://bar:456:789: Invalid URL'
コード例 #6
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_calls_callback_after_clearing():
    cb = mock.MagicMock()
    urls = utils.URLs(('http://foo:123', 'http://bar:456'), callback=cb)
    urls.clear()
    cb.assert_called_once_with(urls)
コード例 #7
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_calls_callback_after_inserting():
    cb = mock.MagicMock()
    urls = utils.URLs(('http://foo:123', 'http://bar:456'), callback=cb)
    urls.insert(0, 'http://baz:789')
    cb.assert_called_once_with(urls)
コード例 #8
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_is_equal_to_any_combination_of_the_same_urls():
    urls = utils.URLs(('http://foo:123', 'http://bar:456', 'http://baz:789'))
    assert urls == ('http://foo:123', 'http://bar:456', 'http://baz:789')
    assert urls == ('http://bar:456', 'http://foo:123', 'http://baz:789')
    assert urls == ('http://bar:456', 'http://foo:123', 'http://baz:789')
    assert urls == ('http://foo:123', 'http://baz:789', 'http://bar:456')
コード例 #9
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_is_equal_to_iterables():
    urls = utils.URLs(('http://foo:123', 'http://bar:456'))
    assert urls == ['http://foo:123', 'http://bar:456']
    assert urls == ('http://foo:123', 'http://bar:456')
コード例 #10
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_is_equal_to_URLs_instances():
    t1 = utils.URLs(('http://foo:123', 'http://bar:456'))
    t2 = utils.URLs(('http://foo:123', 'http://bar:456'))
    assert t1 == t2
    t2 = utils.URLs(('http://foo:123', 'http://baz:789'))
    assert t1 != t2
コード例 #11
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_validates_inserted_urls():
    urls = utils.URLs(('http://foo:123', 'http://bar:456'))
    with pytest.raises(errors.URLError) as e:
        urls.insert(1, 'http://baz:789:abc')
    assert str(e.value) == 'http://baz:789:abc: Invalid URL'
コード例 #12
0
def test_URLs_interprets_empty_string_as_empty_list():
    urls = utils.URLs('')
    assert urls == ()
コード例 #13
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_validates_initial_urls():
    with pytest.raises(errors.URLError) as e:
        utils.URLs(('http://foo:123', 'http://bar:456:789'))
    assert str(e.value) == 'http://bar:456:789: Invalid URL'
コード例 #14
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_deduplicates_when_setting():
    urls = utils.URLs(('http://foo:123', 'http://bar:456'))
    urls.append('http://foo:123')
    urls.append('http://bar:456')
    urls.extend(('http://foo:123', 'http://bar:456'))
    assert urls == ['http://foo:123', 'http://bar:456']
コード例 #15
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_deduplicates_when_initializing():
    urls = utils.URLs(('http://foo:123', 'http://bar:456', 'http://foo:123'))
    assert urls == ['http://foo:123', 'http://bar:456']
コード例 #16
0
ファイル: test_utils.py プロジェクト: cargo12/torf
def test_URLs_accepts_string_or_iterable():
    urls = utils.URLs('http://foo:123')
    assert urls == utils.URLs(('http://foo:123', ))
    assert urls == utils.URLs(['http://foo:123'])
コード例 #17
0
def test_URLs_does_not_empty_when_replacing_with_invalid_URLs():
    urls = utils.URLs(('http://foo:123', 'http://bar:456'))
    with pytest.raises(errors.URLError):
        urls.replace(('http://baz:789:abc', ))
    assert urls == ('http://foo:123', 'http://bar:456')
コード例 #18
0
def test_URLs_validates_appended_urls():
    urls = utils.URLs('http://foo:123')
    with pytest.raises(errors.URLError) as e:
        urls.append('http://bar:456:789')
    assert str(e.value) == 'http://bar:456:789: Invalid URL'
    assert urls == ('http://foo:123', )