#!/usr/bin/env python import enum import itertools import json import os import re import subprocess import sys from dataclasses import KW_ONLY, dataclass, field from functools import partial, partialmethod from operator import itemgetter from time import sleep import defl from defl import CLIError, DotDict, Null, Path, Undefined, cl, log, ShQu from defl._run_ import * from defl._assert_ import Assert from defl._typing_ import * from defl.testing_ import Tester from defl.threadPool_ import ThreadPool tester = Tester(name=__file__) @tester.add() def test(): r = ShQu('ls -a').cli Assert(r) == ['ls -a'] @tester.add() def test(): r = ShQu(['ls', '-a']).cli Assert(r) == ['ls', '-a'] @tester.add() def test(): r = ShQu(['ls -a']).cli Assert(r) == ['ls -a'] @tester.add() def test(): r = ShQu([b'ls -a']).cli Assert(r) == ['ls -a'] @tester.add() def test(): r = ShQu([b'a a', b'b b']).cli Assert(r) == ['a a', 'b b'] @tester.add() def test(): r = ShQu(['ls', 'a a']).bash().cli Assert(r) == ['bash', '-c', "ls 'a a'"] @tester.add() def test(): r = ShQu('ls -a').bash().cli Assert(r) == ['bash', '-c', "'ls -a'"] @tester.add() def test(): r = ShQu(['ls', '-a']).bash().cli Assert(r) == ['bash', '-c', 'ls -a'] @tester.add() def test(): r = ShQu(['ls -a']).bash().cli Assert(r) == ['bash', '-c', "'ls -a'"] @tester.add() def test(): r = ShQu(['ls', 'a a']).decode() Assert(r) == ['ls', 'a a'] @tester.add() def test(): r = ShQu(['ls', 'a a']) + ShQu(['ls', 'b']) r = r.decode() Assert(r) == "ls 'a a' ; ls b" @tester.add() def test(): r = (ShQu(['ls', 'a a']) + ShQu(['ls', 'b'])).bash().decode() Assert(r) == ['bash', '-c', "ls 'a a' ; ls b"] @tester.add() def test(): r = ShQu(['ls', ShQu(['ls', ShQu(['ls', 'a a'])])]).decode() Assert(r) == ['ls', "ls 'ls '\"'\"'a a'\"'\"''"] @tester.add() def test(): r = ShQu(['a', 'b', 'c']) + ['d', 'e', 'f'] Assert(r.command) == ['a', 'b', 'c', ShQu.SQS.Join, 'd', 'e', 'f'] Assert(r.cli) == 'a b c ; d e f' @tester.add() def test(): r = ShQu(['a', 'b', 'c']) + 'd' Assert(r.command) == ['a', 'b', 'c', ShQu.SQS.Join, 'd'] Assert(r.cli) == 'a b c ; d' @tester.add() def test(): r = ShQu(['a', 'b', 'c']) > 'd' Assert(r.command) == ['a', 'b', 'c', ShQu.SQS.Redirect, 'd'] Assert(r.cli) == 'a b c > d' @tester.add() def test(): r = ShQu(['a', 'b', 'c']) > 'd d' Assert(r.command) == ['a', 'b', 'c', ShQu.SQS.Redirect, 'd d'] Assert(r.cli) == "a b c > 'd d'" @tester.add() def test(): r = ShQu(['a', b'b', 'c']) > 'd d' Assert(r.command) == ['a', b'b', 'c', ShQu.SQS.Redirect, 'd d'] Assert(r.cli) == "a b c > 'd d'" @tester.add() def test(): r = ShQu([['a'], ['b'], ['c']]) Assert(r.command[0].command) == ['a'] Assert(r.command[1].command) == ['b'] Assert(r.command[2].command) == ['c'] @tester.add() def test(): r = ShQu([[['a'], ['b']], [['c'], ['d']]]) Assert(r.command[0].command[0].command) == ['a'] Assert(r.command[0].command[1].command) == ['b'] Assert(r.command[1].command[0].command) == ['c'] Assert(r.command[1].command[1].command) == ['d'] Assert(r.cli) == ['a b', 'c d'] @tester.add() def test(): r = ShQu([[['a a'], ['b b']], [['c c'], ['d d']]]) Assert(r.command[0].command[0].command) == ['a a'] Assert(r.command[0].command[1].command) == ['b b'] Assert(r.command[1].command[0].command) == ['c c'] Assert(r.command[1].command[1].command) == ['d d'] Assert(r.cli) == ["''\"'\"'a a'\"'\"'' ''\"'\"'b b'\"'\"''", "''\"'\"'c c'\"'\"'' ''\"'\"'d d'\"'\"''"] log.info(tester.run()) tester.exitWithStatus() # for i in ch: # print(defl.printTable([[y for y in x] for x in ch], squareFill=T))