Exemplo n.º 1
0
def test_update_at_wrong_line():
    load_fixture('history.rst', 'HISTORY.rst')
    res = _run(['update', '1.0.6', '--date', 'today', '--at-line', '0'])
    expect(res.exit_code).to_be_equal(1)
    expect(res.output).to_be_equal(
        '"at_line" must be greater or equal to 1.\nAborted!\n'
    )
Exemplo n.º 2
0
def test_update_with_line_too_long(history_dir, history_file):
    load_fixture_to('history.rst', history_file)
    add(
        'some very long and sophisticated message, which is too long to fit 79'
        ' characters',
        history_dir,
    )
    add(
        'next message, which also is very long, but should fit into 79'
        ' characters aaaa',
        history_dir,
    )
    add(
        'let just say Lorem ipsum dolor sit amet consectetur '
        'adipisicing elit, sed do eiusmod tempor incididunt ut labore et '
        'dolore magna aliqua. Ut enim ad minim veniam, quis nostrud '
        'exercitation ullamco',
        history_dir,
    )

    update(
        '1.0.6', history_dir, history_file, date='today', prefix='* ',
        line_length=79,
    )

    content = get_fixture_content('history_update_long_line.rst')
    with history_file.open() as src:
        file_content = src.read()
    expect(content).to_be_equal(file_content)
Exemplo n.º 3
0
def test_split_line():
    split = split_into_lines
    expect(split('cha cha cha', 1)).to_be_equal(['cha', 'cha', 'cha'])
    expect(split('cha cha cha', 2)).to_be_equal(['cha', 'cha', 'cha'])
    expect(split('cha cha cha', 3)).to_be_equal(['cha', 'cha', 'cha'])
    expect(split('cha cha cha', 6)).to_be_equal(['cha', 'cha', 'cha'])
    expect(split('cha cha cha', 7)).to_be_equal(['cha cha', 'cha'])
Exemplo n.º 4
0
def test_split_with_words_too_long():
    expect(split_into_lines('aaaaaaaaa bbb ccc', 4)).to_be_equal(
        ['aaaaaaaaa', 'bbb', 'ccc']
    )
    expect(split_into_lines('bbb ccc aaaaaaaaa ddd', 4)).to_be_equal(
        ['bbb', 'ccc', 'aaaaaaaaa', 'ddd']
    )
Exemplo n.º 5
0
    def test_basic(self):
        def fakeRequest(text):
            expect(text).is_equal('text 123')
            return []

        api = CLanguageTool(request=fakeRequest)
        expect(api.check('text 123')).is_equal([])
    def test_pull_returnSummaryWithoutSpelling(self):
        def fakeRequest(uid):
            return {}

        res = CTextRuPendingRequest(uid='uid',
                                    request=fakeRequest,
                                    spellRequired=False).pull()
        expect(res).is_type(CTextRuSummary)
    def test_pull_returnSummary(self):
        def fakeRequest(uid):
            return {'spell_check': {}}

        res = CTextRuPendingRequest(uid='uid',
                                    request=fakeRequest,
                                    spellRequired=True).pull()
        expect(res).is_type(CTextRuSummary)
Exemplo n.º 8
0
def test_update_with_special_headlines():
    load_fixture('history_special.rst', 'HISTORY.rst')
    _run(['add', 'some_message'])
    _run(['add', 'next message'])
    _run(['update', '1.0.6', '--date', 'today'])

    content = get_fixture_content('history_special_after.rst')
    file_content = get_test_file_content('HISTORY.rst')
    expect(content).to_be_equal(file_content)
    def test_pull_returnSelfIfSpellingNotReady(self):
        def fakeRequest(uid):
            expect(uid).is_equal('uid')
            return {'spell_check': ''}

        req = CTextRuPendingRequest(uid='uid',
                                    request=fakeRequest,
                                    spellRequired=True)
        expect(req.pull()).is_equal(req)
    def test_pull_returnSelfIfNone(self):
        def fakeRequest(uid):
            expect(uid).is_equal('uid')
            return None

        req = CTextRuPendingRequest(uid='uid',
                                    request=fakeRequest,
                                    spellRequired=True)
        expect(req.pull()).is_equal(req)
Exemplo n.º 11
0
    def test_addPost_valid(self):
        def fakeRequest(url, params):
            expect(url).is_equal('http://api.text.ru/post')
            expect(params['userkey']).is_equal('user key')
            expect(params['text']).is_equal('text 123')
            return {'text_uid': 'text id'}

        api = CTextRuAPI(key='user key', request=fakeRequest)
        expect(api.addPost('text 123')).is_equal('text id')
Exemplo n.º 12
0
def test_update_at_line():
    load_fixture('history.rst', 'HISTORY.rst')
    _run(['add', 'some_message'])
    _run(['add', 'next message'])
    _run(['update', '1.0.6', '--date', 'today', '--at-line', '1'])

    content = get_fixture_content('history_at_line_after.rst')
    file_content = get_test_file_content('HISTORY.rst')
    expect(content).to_be_equal(file_content)
Exemplo n.º 13
0
def step_impl(context, message):
    #element = context.driver.find_element_by_id('flash_message')
    #expect(element.text).to_contain(message)
    found = WebDriverWait(context.driver, WAIT_SECONDS).until(
        expected_conditions.text_to_be_present_in_element(
            (By.ID, 'flash_message'),
            message
        )
    )
    expect(found).to_be(True)
Exemplo n.º 14
0
def test_update_empty_file(history_dir, history_file):
    load_fixture_to('empty.txt', history_file)
    add('some_message', history_dir)
    add('next message', history_dir)
    update('1.0.6', history_dir, history_file, date='today', prefix='* ')

    content = get_fixture_content('empty_after.rst')
    with history_file.open() as src:
        file_content = src.read()
    expect(content.rstrip('\n')).to_be_equal(file_content.rstrip('\n'))
Exemplo n.º 15
0
def test_update_with_special_headlines(history_dir, history_file):
    load_fixture_to('history_special.rst', history_file)
    add('some_message', history_dir)
    add('next message', history_dir)
    update('1.0.6', history_dir, history_file, date='today', prefix='* ')

    content = get_fixture_content('history_special_after.rst')
    with history_file.open() as src:
        file_content = src.read()
    expect(content).to_be_equal(file_content)
Exemplo n.º 16
0
def test_load_config_when_file_doesnt_exist():
    pattern = {
        'history_dir': None,
        'history_file': None,
        'at_line': None,
        'line_length': None,
    }
    values = get_defaults_from_config_file_if_exists()
    for key, value in pattern.items():
        expect(value).to_be_equal(values.get(key))
Exemplo n.º 17
0
def step_impl(context, name):
    #element = context.driver.find_element_by_id('search_results')
    #expect(element.text).to_contain(name)
    found = WebDriverWait(context.driver, WAIT_SECONDS).until(
        expected_conditions.text_to_be_present_in_element(
            (By.ID, 'search_results'),
            name
        )
    )
    expect(found).to_be(True)
Exemplo n.º 18
0
def step_impl(context, text_string, element_name):
    element_id = 'promo_' + element_name.lower()
    #element = context.driver.find_element_by_id(element_id)
    found = WebDriverWait(context.driver, WAIT_SECONDS).until(
        expected_conditions.text_to_be_present_in_element_value(
            (By.ID, element_id),
            text_string
        )
    )
    #expect(element.get_attribute('value')).to_equal(text_string)
    expect(found).to_be(True)
Exemplo n.º 19
0
    def test_getTask_valid(self):
        response = {'result': True}

        def fakeRequest(url, params):
            expect(url).is_equal('http://api.text.ru/post')
            expect(params['userkey']).is_equal('user key')
            expect(params['uid']).is_equal('uid')
            return response

        api = CTextRuAPI(key='user key', request=fakeRequest)
        expect(api.getTask('uid')).is_equal(response)
Exemplo n.º 20
0
    def test_addPost_errorRaiseException(self):
        def fakeRequest(url, params):
            return {'error_code': 321, 'error_desc': 'description'}

        api = CTextRuAPI(key='user key', request=fakeRequest)
        try:
            api.addPost('text 123')
        except Exception as e:
            expect(str(e)).is_equal('(Text.Ru) Error #321: description')
        else:
            raise Exception('Exception expected')
Exemplo n.º 21
0
def test_get_config_from_file():
    load_fixture('setup.cfg', 'empty.txt')
    pattern = {
        'history_dir': None,
        'history_file': None,
        'at_line': None,
        'line_length': None,
    }
    values = get_defaults_from_config_file_if_exists()
    for key, value in pattern.items():
        expect(value).to_be_equal(values.get(key))
Exemplo n.º 22
0
def test_load_config_from_setup_cfg():
    load_fixture('setup.cfg', 'setup.cfg')
    pattern = {
        'history_dir': None,
        'history_file': 'HISTORY.rst',
        'at_line': '42',
        'line_length': '92',
    }
    values = get_defaults_from_config_file_if_exists()
    for key, value in pattern.items():
        expect(value).to_be_equal(values.get(key))
Exemplo n.º 23
0
def test_pyhistory_when_not_in_history_file_directory():
    load_fixture('history.rst', 'HISTORY.rst')

    original_working_dir = os.getcwd()
    os.makedirs('one/two')
    os.chdir('one/two')

    _run(['add', 'some_message'])
    _run(['add', 'next message'])

    expect(len(os.listdir(os.getcwd()))).to_be_equal(0)

    result = _run(['list'])
    expect(result.output).to_be_equal(_join_lines(
        ['', '* some_message', '* next message', ''])
    )

    os.chdir(original_working_dir)
    result = _run(['list'])
    expect(result.output).to_be_equal(_join_lines(
        ['', '* some_message', '* next message', ''])
    )

    os.chdir('one/two')
    _run(['update', '1.0.6', '--date', 'today'])
    os.chdir(original_working_dir)

    content = get_fixture_content('history_after.rst')
    file_content = get_test_file_content('HISTORY.rst')
    expect(content).to_be_equal(file_content)
Exemplo n.º 24
0
def test_list_long_line():
    load_fixture('history.rst', 'HISTORY.rst')

    result = _run([
        'add', 'some very long and sophisticated message, which is too '
        'long to fit 79 characters'
    ])

    result = _run(['list'])
    expect(result.output).to_be_equal(
        '\n'
        '* some very long and sophisticated message, which is too long to '
        'fit 79\n'
        '  characters\n'
        '\n'
    )
Exemplo n.º 25
0
def test_assert_raises(meth, value, arg):
    """Test that method raises an assertion error when evaluated for
    comparables.
    """
    with raises_assertion() as exc:
        expect(value, meth(*arg.args, **arg.kargs))

    with raises_assertion() as exc:
        meth(value, *arg.args, **arg.kargs)

    with raises_assertion() as exc:
        opts = arg.kargs.copy()
        opts.update({'msg': 'TEST CUSTOM MESSAGE'})
        meth(value, *arg.args, **opts)

    assert opts['msg'] in str(exc.value)
Exemplo n.º 26
0
def test_assert_raises(meth, value, arg):
    """Test that method raises an assertion error when evaluated for
    comparables.
    """
    with raises_assertion() as exc:
        expect(value, meth(*arg.args, **arg.kargs))

    with raises_assertion() as exc:
        meth(value, *arg.args, **arg.kargs)

    with raises_assertion() as exc:
        opts = arg.kargs.copy()
        opts.update({'msg': 'TEST CUSTOM MESSAGE'})
        meth(value, *arg.args, **opts)

    assert opts['msg'] in str(exc.value)
Exemplo n.º 27
0
def _test_update_at_line(history_dir, history_file, at_line, fixture_name):
    load_fixture_to('history.rst', history_file)
    add('some_message', history_dir)
    add('next message', history_dir)
    update(
        '1.0.6',
        history_dir,
        history_file,
        date='today',
        at_line=at_line,
        prefix='* ',
    )

    content = get_fixture_content(fixture_name)
    with history_file.open() as src:
        file_content = src.read()
    expect(content).to_be_equal(file_content)
Exemplo n.º 28
0
def test_update_with_line_too_long():
    load_fixture('history.rst', 'HISTORY.rst')
    _run([
        'add', 'some very long and sophisticated message, which is too '
        'long to fit 79 characters'
    ])
    _run([
        'add', 'next message, which also is very long, but should fit '
        'into 79 characters aaaa'
    ])
    _run([
        'add', 'let just say Lorem ipsum dolor sit amet consectetur '
        'adipisicing elit, sed do eiusmod tempor incididunt ut labore et '
        'dolore magna aliqua. Ut enim ad minim veniam, quis nostrud '
        'exercitation ullamco'
    ])

    _run(['update', '1.0.6', '--date', 'today'])

    content = get_fixture_content('history_update_long_line.rst')
    file_content = get_test_file_content('HISTORY.rst')
    expect(content).to_be_equal(file_content)
Exemplo n.º 29
0
    def test_basic(self):
        summary = CtqsErrors([{
            'kind': 'A',
            'message': 'error 1'
        }, {
            'kind': 'B',
            'message': 'error 2'
        }, {
            'kind': 'A',
            'message': 'error 3'
        }])
        expect(summary.asText()).is_equal('''
A

- error 1

- error 3

B

- error 2
    '''.strip())
Exemplo n.º 30
0
def test_delete(history_dir, history_file):
    load_fixture_to('history.rst', history_file)

    add('some_message', history_dir)
    add('next message', history_dir)

    expect(list_(history_dir)).to_be_equal(
        {1: 'some_message\n', 2: 'next message\n'}
    )

    delete([1], history_dir)
    expect(list_(history_dir)).to_be_equal({1: 'next message\n'})

    add('test', history_dir)
    add('test2', history_dir)

    expected_output = {1: 'next message\n', 2: 'test\n', 3: 'test2\n'}
    expect(list_(history_dir)).to_be_equal(expected_output)
    delete([10], history_dir)
    expect(list_(history_dir)).to_be_equal(expected_output)

    delete([2, 3, 5, 101], history_dir)
    expect(list_(history_dir)).to_be_equal({1: 'next message\n'})
Exemplo n.º 31
0
def test_delete_long_lines():
    load_fixture('history.rst', 'HISTORY.rst')

    _run([
        'add', 'some very long and sophisticated message, which is too '
        'long to fit 79 characters'
    ])
    messages = [
        'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine',
    ]
    for message in messages:
        _run(['add', message])
    _run([
        'add', 'next message, which also is very long, and should not '
        'fit into 79 characters'
    ])

    result = _run(['delete'])
    expect(result.output).to_be_equal(
        '\n'
        '1. some very long and sophisticated message, which is too long '
        'to fit 79\n'
        '   characters\n'
        '2. two\n'
        '3. three\n'
        '4. four\n'
        '5. five\n'
        '6. six\n'
        '7. seven\n'
        '8. eight\n'
        '9. nine\n'
        '10. next message, which also is very long, and should not fit '
        'into 79\n'
        '    characters\n'
        '\n'
        '(Delete by choosing entries numbers.)\n'
    )
Exemplo n.º 32
0
    def test_singleMatch(self):
        def fakeRequest(text):
            return [{
                'message': 'message',
                'replacements': [],
                'context': {
                    'text': 'text tupo text',
                    'offset': 5,
                    'length': 4
                },
                'rule': {
                    'category': {
                        'name': 'error'
                    }
                }
            }]

        api = CLanguageTool(request=fakeRequest)
        expect(api.check('')).is_equal([{
            'kind':
            'error',
            'message':
            '"text <b>tupo</b> text" - message.'
        }])
Exemplo n.º 33
0
def test_add_list_and_clear(history_dir, history_file):
    add('some_message', history_dir)
    expect(list_(history_dir)).to_be_equal({1: 'some_message\n'})

    add('next message', history_dir)

    expect(list_(history_dir)).to_be_equal(
        {1: 'some_message\n', 2: 'next message\n'}
    )

    clear(history_dir)
    expect(list_(history_dir)).to_be_equal({})
Exemplo n.º 34
0
 def fakeRequest(url, params):
     expect(url).is_equal('http://api.text.ru/post')
     expect(params['userkey']).is_equal('user key')
     expect(params['text']).is_equal('text 123')
     return {'text_uid': 'text id'}
Exemplo n.º 35
0
def test_expect_chaining():
    assert expect(True).Boolean()(assert_truthy)
    assert expect(True, v.Boolean(), assert_truthy).Truthy()
Exemplo n.º 36
0
def test_expect_predicates_raises(value, predicates):
    """Test that Expect handles multiple predicates that returns boolean
    values.
    """
    with raises_assertion():
        assert expect(value, *predicates)
Exemplo n.º 37
0
def test_expect_multiple_assertions(value, assertions):
    """Test that Expect handles multiple assertions."""
    assert expect(value, *assertions)
Exemplo n.º 38
0
def test_expect_chain_method_proxy():
    for method in [method for method in dir(v)
                   if method[0].isupper() or method[:2] in ('to', 'is')]:
        assert getattr(v, method) is getattr(expect(None), method).assertion
Exemplo n.º 39
0
def test_assert_method(meth, value, arg):
    """Test that method passes when evaluated for comparables."""
    assert expect(value, meth(*arg.args, **arg.kargs))
    assert meth(value, *arg.args, **arg.kargs)
Exemplo n.º 40
0
def test_expect_predicates(value, predicates):
    """Test that Expect handles multiple predicates that returns boolean
    values.
    """
    assert expect(value, *predicates)
Exemplo n.º 41
0
def test_expect_predicates_return_none():
    assert expect(True, assert_truthy)
Exemplo n.º 42
0
 (v.IsNone, v.is_none),
 (v.IsNotNone, v.to_not_be_none),
 (v.IsNotNone, v.is_not_none),
 (v.Truthy, v.to_be_truthy),
 (v.Truthy, v.is_truthy),
 (v.Falsy, v.to_be_falsy),
 (v.Falsy, v.is_falsy),
 (v.Not, v.not_),
 (v.Not, v.does_not),
 (v.Not, v.to_fail),
 (v.Not, v.fails),
 (v.Predicate, v.does),
 (v.Predicate, v.to_pass),
 (v.Predicate, v.passes),
 (v.All, v.all_),
 (v.All, v.expect(None).all.assertion),
 (v.All, v.does_all),
 (v.All, v.passes_all),
 (v.NotAll, v.not_all),
 (v.NotAll, v.does_not_all),
 (v.NotAll, v.fails_all),
 (v.Any, v.any_),
 (v.Any, v.expect(None).any.assertion),
 (v.Any, v.does_any),
 (v.Any, v.passes_any),
 (v.NotAny, v.not_any),
 (v.NotAny, v.does_not_any),
 (v.NotAny, v.fails_any),
 (v.Greater, v.to_be_greater),
 (v.Greater, v.to_be_greater_than),
 (v.Greater, v.is_greater),
Exemplo n.º 43
0
    def test_getTask_NoneIfBusy(self):
        def fakeRequest(url, params):
            return {'error_code': 144}

        api = CTextRuAPI(key='user key', request=fakeRequest)
        expect(api.getTask('uid')).is_equal(None)
Exemplo n.º 44
0
 def fakeRequest(url, params):
     expect(url).is_equal('http://api.text.ru/post')
     expect(params['userkey']).is_equal('user key')
     expect(params['uid']).is_equal('uid')
     return response
Exemplo n.º 45
0
def test_list_empty(history_dir, history_file):
    expect(list_(history_dir)).to_be_equal({})
Exemplo n.º 46
0
def test_update_at_negative_line():
    load_fixture('history.rst', 'HISTORY.rst')
    result = _run(['update', '1.0.6', '--date', 'today', '--at-line', '-1'])
    expect(result.exit_code).to_be_equal(1)
Exemplo n.º 47
0
def test_expect_multiple_assertions(value, assertions):
    """Test that Expect handles multiple assertions."""
    assert expect(value, *assertions)
 def fakeRequest(uid):
     expect(uid).is_equal('uid')
     return None
Exemplo n.º 49
0
def test_expect_predicates_raises(value, predicates):
    """Test that Expect handles multiple predicates that returns boolean
    values.
    """
    with raises_assertion():
        assert expect(value, *predicates)
 def fakeRequest(uid):
     expect(uid).is_equal('uid')
     return {'spell_check': ''}
Exemplo n.º 51
0
def test_expect_chaining():
    assert expect(True).Boolean()(assert_truthy)
    assert expect(True, v.Boolean(), assert_truthy).Truthy()
Exemplo n.º 52
0
def test_assert_method(meth, value, arg):
    """Test that method passes when evaluated for comparables."""
    assert expect(value, meth(*arg.args, **arg.kargs))
    assert meth(value, *arg.args, **arg.kargs)
Exemplo n.º 53
0
def test_expect_chain_invalid_method(method):
    with pytest.raises(AttributeError):
        getattr(expect(None), method)
Exemplo n.º 54
0
def step_impl(context, message):
    """ Check the document title for a message """
    expect(context.driver.title).to_contain(message)
Exemplo n.º 55
0
def test_expect_predicates_return_none():
    assert expect(True, assert_truthy)
Exemplo n.º 56
0
def test_expect_chain_invalid_method(method):
    with pytest.raises(AttributeError):
        getattr(expect(None), method)
Exemplo n.º 57
0
def test_expect_predicates(value, predicates):
    """Test that Expect handles multiple predicates that returns boolean
    values.
    """
    assert expect(value, *predicates)
Exemplo n.º 58
0
def test_expect_chain_method_proxy():
    for method in [
            method for method in dir(v)
            if method[0].isupper() or method[:2] in ('to', 'is')
    ]:
        assert getattr(v, method) is getattr(expect(None), method).assertion
Exemplo n.º 59
0
 (v.IsNone, v.is_none),
 (v.IsNotNone, v.to_not_be_none),
 (v.IsNotNone, v.is_not_none),
 (v.Truthy, v.to_be_truthy),
 (v.Truthy, v.is_truthy),
 (v.Falsy, v.to_be_falsy),
 (v.Falsy, v.is_falsy),
 (v.Not, v.not_),
 (v.Not, v.does_not),
 (v.Not, v.to_fail),
 (v.Not, v.fails),
 (v.Predicate, v.does),
 (v.Predicate, v.to_pass),
 (v.Predicate, v.passes),
 (v.All, v.all_),
 (v.All, v.expect(None).all.assertion),
 (v.All, v.does_all),
 (v.All, v.passes_all),
 (v.NotAll, v.not_all),
 (v.NotAll, v.does_not_all),
 (v.NotAll, v.fails_all),
 (v.Any, v.any_),
 (v.Any, v.expect(None).any.assertion),
 (v.Any, v.does_any),
 (v.Any, v.passes_any),
 (v.NotAny, v.not_any),
 (v.NotAny, v.does_not_any),
 (v.NotAny, v.fails_any),
 (v.Greater, v.to_be_greater),
 (v.Greater, v.to_be_greater_than),
 (v.Greater, v.is_greater),
Exemplo n.º 60
0
def step_impl(context, name):
    element = context.driver.find_element_by_id('search_results')
    error_msg = "I should not see '%s' in '%s'" % (name, element.text)
    expect(element.text).to_not_contain(name)