Commit 17679119 authored by Yannick Kirschhoffer's avatar Yannick Kirschhoffer

Add terminal detection and tests.

parent f5dbfd4d
#!/usr/bin/env python3
import argparse
import sys
from docker_ascii_map import __version__
from docker_ascii_map.docker_config import ConfigParser
import params
from docker_ascii_map.ascii_render import Renderer
parser = argparse.ArgumentParser(description='Display the docker host contents on a visual map.')
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
parser.add_argument('-c', '--color', action='store_const', const='color', help='Use color in map display')
parser.add_argument('-m', '--mono', action='store_const', const='mono', help='Render the map in monochrome')
from docker_ascii_map.docker_config import ConfigParser
if __name__ == '__main__':
args = parser.parse_args()
color_mode = args.color and not args.mono
color_mode = params.get_input_parameters()[0]
config_parser = ConfigParser()
renderer = Renderer()
......
import argparse
import os
from typing import Tuple
from docker_ascii_map import __version__
def get_input_parameters() -> Tuple[bool]:
parser = argparse.ArgumentParser(description='Display the docker host contents on a visual map.')
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
parser.add_argument('-c', '--color', action='store_const', const='color', help='Use color in map display')
parser.add_argument('-m', '--mono', action='store_const', const='mono', help='Render the map in monochrome')
terminal = os.getenv('TERM')
args = parser.parse_args()
color_mode = False
if terminal:
color_mode = 'color' in terminal
if args.color:
color_mode = True
if args.mono:
color_mode = False
return color_mode, None
import unittest
from argparse import ArgumentParser
from unittest.mock import patch
import params
class Args:
def __init__(self, mono=None, color=None):
self.mono = mono
self.color = color
class ParametersTests(unittest.TestCase):
def test_monoterm(self):
with patch('os.getenv', return_value='vt100') as mock_getenv:
with patch.object(ArgumentParser, 'parse_args', return_value=Args()) as mock_parse:
r = params.get_input_parameters()
self.assertEqual(False, r[0])
def test_colorterm(self):
with patch('os.getenv', return_value='xterm-256color') as mock_getenv:
with patch.object(ArgumentParser, 'parse_args', return_value=Args()) as mock_parse:
r = params.get_input_parameters()
self.assertEqual(True, r[0])
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment