def test_strip_ansi(): ''' Test strip_ansi() removes console color codes from a string. ''' text = 'This is just a ' + red('test.') plain_text = 'This is just a test.' assert plain_text == strip_ansi(text)
def test_strip_ansi_returns_same_string_for_plain_text(): ''' Test strip_ansi() returns the same string if it's plain text. ''' text = 'This is just a test.' plain_text = 'This is just a test.' assert plain_text == strip_ansi(text)
def test_resolve_dotenv_file_loads_dotenv_file_if_it_exists(load_dotenv_mock, info_m): ''' Test .env file is loaded if it exists. ''' dotenv_path = '.env' with patch('boss.core.fs.exists', side_effect=lambda p: p == dotenv_path): resolve_dotenv_file('') load_dotenv_mock.assert_called_with(dotenv_path) msg = strip_ansi(info_m.call_args[0][0]) assert msg == 'Resolving env file: .env'
def test_resolve_dotenv_file_loads_stage_specific_env_file(load_dotenv_m, info_m): ''' Test .env file is loaded if it exists. ''' stage = 'production' def exists(p): return p == '.env.production' with patch('boss.core.fs.exists', side_effect=exists): resolve_dotenv_file('', stage) load_dotenv_m.assert_called_with('.env.production') msg = strip_ansi(info_m.call_args[0][0]) assert msg == 'Resolving env file: .env.production'
def test_resolve_dotenv_file_loads_env_file_if_stage_specific_file_doesnt_exist( load_dotenv_m, info_m): ''' Test .env file is loaded as a fallback option, if stage is provided but stage specific env file doesn't exist. ''' stage = 'production' def exists(p): return p == '.env' with patch('boss.core.fs.exists', side_effect=exists): resolve_dotenv_file('', stage) load_dotenv_m.assert_called_with('.env') msg = strip_ansi(info_m.call_args[0][0]) assert msg == 'Resolving env file: .env'
def test_strip_ansi_with_empty_string_and_none(): ''' Test strip_ansi() with empty string and None as inputs. ''' assert strip_ansi('') == '' assert strip_ansi(None) is None
def test_strip_ansi(): text = 'This is just a ' + red('test.') plain_text = 'This is just a test.' assert plain_text == strip_ansi(text)
def glob(path, remote=True): ''' Glob a directory path to get the list of files. ''' with hide('everything'): result = runner.run('ls -1 {}'.format(path), remote=remote) return strip_ansi(result).split()