Skip to content

Commit

Permalink
Merge branch 'hexxter-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ScheintodX committed Nov 17, 2015
2 parents a0088ab + 8394d04 commit f4b6e7a
Showing 1 changed file with 53 additions and 38 deletions.
91 changes: 53 additions & 38 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,56 @@
import unittest
import sys
from Sh import Sh,sh

"""
This is how it should work
Note that we use operator overloading for | and __str__ and command
chaining in order to get a cleaner syntax.
"""

def printer( arg ):
print( arg )

"""
Nomal shell operation with pipes and no hustles
"""
print( "Inline pipe" )
result = Sh( "ls . | grep Sh.py" )
result = Sh( "ls", "." ) | Sh( "grep", "Sh.py" )
print( result )

"""
Pipe a String in the shell pipe. This is nice and a must have!!22!
"""
print( "string to pipe" )
result = "blah" | Sh( "sed -e 's/ah/ub/'" )
result = "blah" | Sh( "sed", "-e", "'s/ah/ub/'" )
print( result )

"""
Pipe into function.
I don't know if this could work or even is a good idea
"""
print( "pipe to function" )
Sh( "ls ." ) | printer
Sh( "ls", "." ) | printer

print( "Adding args" )
result = Sh( "ls" ).arg( "-a" ).arg( "." )
print( result )

import logging


class TestSh(unittest.TestCase):
"""
This is how it should work
Note that we use operator overloading for | and __str__ and command
chaining in order to get a cleaner syntax.
"""

def setUp(self):
pass

def test_normal(self):
"""
Nomal shell operation with pipes and no hustles
"""

log.info( "Inline pipe" )
result = Sh( "ls . | grep Sh.py" )
#result = Sh( "ls", "." ) | Sh( "grep", "Sh.py" )
#log.info( result )
self.assertEqual( str(result), "Sh.py\n")

def test_string_pipe(self):
"""
Pipe a String in the shell pipe. This is nice and a must have!!22!
"""

log.info( "string to pipe" )
result = "blah" | Sh( "sed -e 's/ah/ub/'" )
#result = "blah" | Sh( "sed", "-e", "'s/ah/ub/'" )
#log.info( result )

def test_pipe_func(self):
"""
Pipe into function.
I don't know if this could work or even is a good idea
"""
pass
#log.info( "pipe to function" )
#Sh( "ls /" ) | print
#Sh( "ls", "/" ) | print

#log.info( "Adding args" )
#result = Sh( "ls" ).arg( "-a" ).arg( "/" )
#log.info( result )

if __name__ == '__main__':

log = logging.getLogger("TestSh")
log.setLevel(logging.DEBUG)
unittest.main()

0 comments on commit f4b6e7a

Please sign in to comment.