def setup_method(self): self.config = Config(pathlib.Path('doesnt-matter')) self.red_fg = self.config.get_color('some', 'red', with_reset=False) self.yellow_fg = self.config.get_color('some', 'yellow+bold') self.white_fg = self.config.get_color('some', 'white')
def setup_method(self): self.config = Config(pathlib.Path('doesnt-matter')) self.pp = Processor(self.config, 'mount')
class term_module_tester: def setup_method(self): self.config = Config(pathlib.Path('doesnt-matter')) self.red_fg = self.config.get_color('some', 'red', with_reset=False) self.yellow_fg = self.config.get_color('some', 'yellow+bold') self.white_fg = self.config.get_color('some', 'white') def fg2bg_test(self): assert fg2bg(self.red_fg) == '\x1b[41m' def pos_to_offset_0_test(self): line = 'Hello Africa' colored = self.yellow_fg + line + self.config.color.reset #print('{}'.format(repr(colored))) pos = pos_to_offset(colored, 0) assert pos == 13 assert colored[pos] == 'H' pos = pos_to_offset(colored, 6) assert pos == 19 assert colored[pos] == 'A' pos = pos_to_offset(colored, len(line) - 1) assert pos == 24 assert colored[pos] == 'a' def pos_to_offset_1_test(self): line = 'Hello Africa' colored = self.white_fg + ' ' + self.yellow_fg + line + self.config.color.reset pos = pos_to_offset(colored, 1) assert pos == 23 assert colored[pos] == 'H' def bg_highlight_1_test(self): self.reg_bg = fg2bg(self.red_fg) line = 'Hello Africa' line = self.yellow_fg + line + self.config.color.reset pos = pos_to_offset(line, 0) assert line[pos] == 'H' line = line[:pos] + self.reg_bg + line[pos:pos+1] + self.config.color.normal_bg \ + line[pos+1:] assert line == '\x1b[0m\x1b[33m\x1b[1m\x1b[41mH\x1b[48mello Africa\x1b[0m' pos = pos_to_offset(line, 6) assert line[pos] == 'A' line = line[:pos] + self.reg_bg + line[pos:pos+1] + self.config.color.normal_bg \ + line[pos+1:] assert line == '\x1b[0m\x1b[33m\x1b[1m\x1b[41mH\x1b[48mello \x1b[41mA\x1b[48mfrica\x1b[0m' pos = pos_to_offset(line, 11) assert line[pos] == 'a' line = line[:pos] + self.reg_bg + line[pos:pos+1] + self.config.color.normal_bg \ + line[pos+1:] assert line == '\x1b[0m\x1b[33m\x1b[1m\x1b[41mH\x1b[48mello \x1b[41mA\x1b[48mfric\x1b[41ma\x1b[48m\x1b[0m' def _format_range_as_to_columns(self, count, columns): result = '' line = '' for i in column_formatter(count, columns): if i == -1: #print(line) result += line + '\n' line = '' else: line += '{} '.format(i) return result def test_column_formatter_0(self): for i in column_formatter(0, 1): self.assertFalse() def column_formatter_1_2_test(self): expected = '0 \n' result = self._format_range_as_to_columns(1, 2) assert expected == result def column_formatter_10_4_test(self): expected = '0 3 6 9 \n1 4 7 \n2 5 8 \n' result = self._format_range_as_to_columns(10, 4) assert expected == result def column_formatter_10_3_test(self): expected = '0 4 8 \n1 5 9 \n2 6 \n3 7 \n' result = self._format_range_as_to_columns(10, 3) assert expected == result
def get_color_value_test(self): cfg = Config(make_data_filename('sample.conf')) assert cfg.get_color('red', 'red') == '\x1b[0m\x1b[31m' assert cfg.get_color('red', 'red', with_reset=False) == '\x1b[31m' assert cfg.get_color('error', 'normal') == '\x1b[0m\x1b[31m\x1b[1m' assert cfg.get_color('error', 'normal', with_reset=False) == '\x1b[31m\x1b[1m' assert cfg.get_color('not-existed', 'normal') == '\x1b[0m\x1b[38m' assert cfg.get_color('some-int', 'reset') == '\x1b[0m\x1b[38;5;123m' assert cfg.get_color('none', 'none') == '' # Try TrueColor specs assert cfg.get_color('true_rgb_red', 'red') == '\x1b[0m\x1b[38;2;255;0;0m' assert cfg.get_color('true_rgb_green', 'red') == '\x1b[0m\x1b[38;2;0;255;0m' assert cfg.get_color('true_rgb_blue', 'red') == '\x1b[0m\x1b[38;2;0;0;255m' with pytest.raises(TypeError): cfg.get_color('red')
def get_bool_value_test(self): cfg = Config(make_data_filename('sample.conf')) assert cfg.get_bool('not-existed') is None assert cfg.get_bool('not-existed', True) == True assert cfg.get_bool('not-existed', False) == False assert cfg.get_bool('true-bool-key-1') == True assert cfg.get_bool('false-bool-key-1') == False assert cfg.get_bool('true-bool-key-2') == True assert cfg.get_bool('false-bool-key-2') == False with pytest.raises(ValueError): cfg.get_bool('some-int')
def get_int_value_test(self): cfg = Config(make_data_filename('sample.conf')) assert cfg.get_int('some-int') == 123 assert cfg.get_int('not-existed', 123) == 123 with pytest.raises(ValueError): cfg.get_int('not-an-int', 123)
def get_string_value_test(self): cfg = Config(make_data_filename('sample.conf')) assert cfg.get_string('some') == 'value' assert cfg.get_string('not-existed', 'default') == 'default' assert cfg.get_string('some-int') == '123'
def not_exitsted_file_test(self): cfg = Config(make_data_filename('not-existed-file')) assert cfg.get_string('not-existed', 'default') == 'default' assert cfg.get_int('not-existed', 123) == 123