Esempio n. 1
0
def test_virtual_env_segment_text_is_empty_when_deactivated():
    os.unsetenv('VIRTUAL_ENV')
    if 'VIRTUAL_ENV' in os.environ:  # when running tests in a virtualenv
        del os.environ['VIRTUAL_ENV']
    colors.load_theme()

    assert virtual_env.segment() == {'text': '', 'style': colors.style('mute')}
Esempio n. 2
0
def test_current_working_path_segment_contains_text_and_style():
    colors.load_theme()
    os.chdir(str(Path('/tmp')))

    segment = current_working_path.segment()

    assert segment == {'text': '/tmp', 'style': colors.style('info')}
Esempio n. 3
0
def test_virtual_env_segment_text_is_empty_when_activated():
    os.environ['VIRTUAL_ENV'] = '/path/to/virtual/env'
    colors.load_theme()

    assert virtual_env.segment() == {
        'text': 'env',
        'style': colors.style('mute')
    }
Esempio n. 4
0
def test_repository_active_branch_segment_contains_text_and_style():
    colors.load_theme()

    with tempfile.TemporaryDirectory() as tmp_repo:
        empty_repo = git.Repo.init(tmp_repo)
        segment = repository.ActiveBranch(tmp_repo).segment()

        assert segment == {'text': 'master', 'style': colors.style('mute')}
Esempio n. 5
0
def test_repository_is_dirty_segment_contains_text_and_style():
    colors.load_theme()

    with tempfile.TemporaryDirectory() as tmp_repo:
        empty_repo = git.Repo.init(tmp_repo)
        new_file = tempfile.NamedTemporaryFile(dir=tmp_repo)

        segment = repository.IsDirty(tmp_repo).segment()
        assert segment == {'text': '*', 'style': colors.style('mute')}

        new_file.close()
Esempio n. 6
0
        'git_is_dirty': repository.IsDirty(os.getcwd()).segment(),
        'virtual_env': virtual_env.segment(),
        'prompt_symbol': prompt_symbol.segment(args.last_command_status)
    }

    if args.json:
        [print(jsonify(segment)) for segment in segments.values()]
        return [jsonify(segment) for segment in segments.values()]
    else:
        segments_with_style = {}
        [segments_with_style.update({name: "{style}{text}".format(**segment)}) for name, segment in segments.items()]
        print(layout().format(**segments_with_style), end='')


def fetch(segment):
    return segment.get('style') + segment.get('text')


def jsonify(segment):
    return json.dumps(segment, sort_keys=True).replace('\\u00', '\\x')


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Process shell variables.')
    parser.add_argument('--last-command-status', dest='last_command_status', type=int,
                        help='last command\'s exit status')
    parser.add_argument('--json', action='store_true', help='return prompt as a JSON segments with colors')

    colors.load_theme()
    prompt(parser.parse_args())
Esempio n. 7
0
def test_current_working_path_color_is_info():
    colors.load_theme()
    os.chdir(str(Path('/tmp')))

    assert fetch(
        current_working_path.segment()) in colorful.info('/tmp').styled_string
Esempio n. 8
0
def test_prompt_symbol_is_colored_for_failed_command():
    colors.load_theme()

    symbol = prompt.fetch(prompt_symbol.segment(constants.FAIL))

    assert symbol in colorful.danger('❯').styled_string
Esempio n. 9
0
def test_prompt_symbol_is_colored_for_successful_command():
    colors.load_theme()
    
    symbol = prompt.fetch(prompt_symbol.segment(constants.SUCCESS))

    assert symbol in colorful.primary('❯').styled_string
Esempio n. 10
0
def test_prompt_symbol_segment_contains_text_and_style():
    colors.load_theme()
    segment = prompt_symbol.segment()

    assert segment == {'text': '❯', 'style': colors.style('primary')}
Esempio n. 11
0
def test_prompt_symbol_segment_contains_text_and_danger_color_when_last_command_failed(
):
    colors.load_theme()
    segment = prompt_symbol.segment(last_command_status=constants.FAIL)

    assert segment == {'text': '❯', 'style': colors.style('danger')}
Esempio n. 12
0
def test_prompt_symbol_segment_contains_text_and_primary_color_when_last_command_succeed(
):
    colors.load_theme()
    segment = prompt_symbol.segment(last_command_status=constants.SUCCESS)

    assert segment == {'text': '❯', 'style': colors.style('primary')}