def test_sync_up(self): args = parseargs(['syncup', 'tag']) print(args) self.assertEqual(args.action, Actions.SYNC_UP) self.assertEqual(args.tag, 'tag') args = parseargs(['syncup']) self.assertEqual(args.action, Actions.SYNC_UP)
def test_ssh(self): args = parseargs(['ssh', 'tag']) print(args) self.assertEqual(args.action, Actions.SSH) self.assertEqual(args.tag, 'tag') args = parseargs(['ssh']) self.assertEqual(args.action, Actions.SSH)
def test_run_plain(self): args = parseargs( ['run', '--tag', 'sometag', 'python', 'test.py', 'a', '--b=c']) print(args) self.assertEqual(args.action, Actions.RUN) self.assertEqual(args.tag, 'sometag') self.assertIsNone(args.host) self.assertIsNone(args.path) self.assertListEqual( args.command, ['python', 'test.py', 'a', '--b=c'], )
def test_run_with_host_and_path(self): args = parseargs([ 'run', '--docker=nvidia-docker', '--tag', 'sometag', '--host=some@host', '--path=/some/path', 'python', 'test.py', 'a', '--b=c' ]) print(args) self.assertEqual(args.action, Actions.RUN) self.assertEqual(args.docker, 'nvidia-docker') self.assertEqual(args.tag, 'sometag') self.assertEqual(args.host, 'some@host') self.assertEqual(args.path, '/some/path') self.assertListEqual( args.command, ['python', 'test.py', 'a', '--b=c'], )
def main(): import sys from src import utils try: # init ignore if not exist from os.path import exists if not exists(utils.path_file_ignore()): print('initiating a new .remotedignore, change it to suit your need') utils.init_ignore() from src.parser import parseargs, Actions args = parseargs(sys.argv[1:]) # register signal import signal import functools signal.signal(signal.SIGINT, functools.partial(act_quit, args=args)) func_map = { Actions.LIST: act_list, Actions.RUN: act_run, Actions.RESTART: act_restart, Actions.STOP: act_stop, Actions.REMOVE: act_remove, Actions.SSH: act_ssh, Actions.SYNC: act_sync, Actions.SYNC_UP: act_sync_up, } # call function func_map[args.action](args) except utils.errors.RemoteDockerError as e: print(e) sys.exit(1)
def test_rm_can_accept_tag(self): args = parseargs(['rm', 'tag']) self.assertEqual(args.action, Actions.REMOVE) self.assertEqual(args.tag, 'tag') self.assertFalse(args.force)
def test_stop_with_no_tag(self): args = parseargs(['stop']) self.assertIsNone(args.tag)
def test_stop_with_force(self): args = parseargs(['stop', 'tag', '--force']) self.assertEqual(args.action, Actions.STOP) self.assertEqual(args.tag, 'tag') self.assertTrue(args.force)
def test_stop_with_only_tag(self): args = parseargs(['stop', 'tag']) self.assertEqual(args.action, Actions.STOP) self.assertEqual(args.tag, 'tag') self.assertFalse(args.force)
def test_restart_with_no_tag(self): args = parseargs(['restart']) print(args) self.assertIsNone(args.tag)
def test_list(self): args = parseargs(['list']) print(args) self.assertEqual(args.action, Actions.LIST)
def test_restart_force(self): args = parseargs(['restart', 'tag', '--force']) self.assertEqual(args.action, Actions.RESTART) self.assertEqual(args.tag, 'tag') self.assertTrue(args.force)
def test_restart_with_only_tag(self): args = parseargs(['restart', 'tag']) self.assertEqual(args.action, Actions.RESTART) self.assertEqual(args.tag, 'tag') self.assertFalse(args.force)
def test_rm_with_force_true(self): args = parseargs(['rm', 'tag', '--force']) self.assertEqual(args.action, Actions.REMOVE) self.assertTrue(args.force)