Exemplo n.º 1
0
    def testWithCd (self):
        ayrton.main ('''import os.path
with cd ("bin"):
    print (os.path.split (pwd ())[-1])''')
        # close stdout as per the description of setUpMockStdout()
        os.close (1)
        self.assertEqual (self.r.read (), b'bin\n')
Exemplo n.º 2
0
    def testBg (self):
        ayrton.main ('''a= find ("/usr", _bg=True, _out=None);
echo ("yes!");
echo (a.exit_code ())''')
        # close stdout as per the description of setUpMockStdout()
        os.close (1)
        self.assertEqual (self.r.read (), b'yes!\n0\n')
Exemplo n.º 3
0
 def testStdEqNone (self):
     # do the test
     ayrton.main ('echo ("foo", _out=None)')
     # close stdout as per the description of setUpMockStdout()
     os.close (1)
     # the output is empty, as it went to /dev/null
     self.assertEqual (self.r.read (), b'')
Exemplo n.º 4
0
 def testEnvironment(self):
     # NOTE: we convert envvars to str when we export() them
     ayrton.main(
         """sh (-c='echo environments works: $FOO', _env=dict (FOO='yes'))"""
     )
     tearDownMockStdOut(self)
     self.assertEqual(self.mock_stdout.read(), 'environments works: yes\n')
     self.mock_stdout.close()
Exemplo n.º 5
0
    def testStdEqCapture (self):
        # do the test
        ayrton.main ('''f= echo ("foo", _out=Capture);
print ("echo: %s" % f)''')
        # the output is empty, as it went to /dev/null
        # BUG: check why there's a second \n
        # ANS: because echo adds the first one and print adds the second one
        self.assertEqual (self.a.buffer.getvalue (), b'echo: foo\n\n')
Exemplo n.º 6
0
    def testGt (self):
        fn= tempfile.mkstemp ()[1]

        ayrton.main ('echo ("yes") > "%s"' % fn)

        contents= open (fn).read ()
        # read() does not return bytes!
        self.assertEqual (contents, 'yes\n')
        os.unlink (fn)
Exemplo n.º 7
0
 def testUnknown (self):
     try:
         ayrton.main ('''foo''')
     except CommandNotFound:
         raise
     except NameError:
         pass
     self.assertRaises (NameError, ayrton.main, '''fff()''')
     self.assertRaises (CommandNotFound, ayrton.main, '''fff()''')
Exemplo n.º 8
0
    def testLt (self):
        fd, fn= tempfile.mkstemp ()
        os.write (fd, b'42\n')
        os.close (fd)

        ayrton.main ('cat () < "%s"' % fn)

        self.assertEqual (self.a.buffer.getvalue (), b'42\n')
        os.unlink (fn)
Exemplo n.º 9
0
 def testUnknown(self):
     try:
         ayrton.main("""foo""")
     except CommandNotFound:
         raise
     except NameError:
         pass
     self.assertRaises(NameError, ayrton.main, """fff()""")
     self.assertRaises(CommandNotFound, ayrton.main, """fff()""")
Exemplo n.º 10
0
 def testUnknown (self):
     try:
         ayrton.main ('''foo''')
     except CommandNotFound:
         raise
     except NameError:
         pass
     self.assertRaises (NameError, ayrton.main, '''fff()''')
     self.assertRaises (CommandNotFound, ayrton.main, '''fff()''')
Exemplo n.º 11
0
    def testUnset (self):
        ayrton.main ('''export (TEST_ENV=42)
print (TEST_ENV)
unset ("TEST_ENV")
try:
    TEST_ENV
except NameError:
    print ("yes")''')
        self.assertEqual (self.a.buffer.getvalue (), b'42\nyes\n')
Exemplo n.º 12
0
    def Remote (self):
        """This test only succeeds if you you have password/passphrase-less access
        to localhost"""
        ayrton.main ('''with remote ('localhost', allow_agent=False) as s:
    print (SSH_CLIENT)
print (s[1].readlines ())''')
        expected1= b'''[b'127.0.0.1 '''
        expected2= b''' 22\\n']\n'''
        self.assertEqual (self.a.buffer.getvalue ()[:len (expected1)], expected1)
        self.assertEqual (self.a.buffer.getvalue ()[-len (expected2):], expected2)
Exemplo n.º 13
0
    def testStdEqCapture (self):
        # do the test
        ayrton.main ('''f= echo ("foo", _out=Capture);
print ("echo: %s" % f)''')
        # close stdout as per the description of setUpMockStdout()
        os.close (1)
        # the output is empty, as it went to /dev/null
        # BUG: check why there's a second \n
        # ANS: because echo adds the first one and print adds the second one
        self.assertEqual (self.r.read (), b'echo: foo\n\n')
Exemplo n.º 14
0
    def testLt (self):
        fd, fn= tempfile.mkstemp ()
        os.write (fd, b'42\n')
        os.close (fd)

        ayrton.main ('cat () < "%s"' % fn)

        # close stdout as per the description of setUpMockStdout()
        os.close (1)
        self.assertEqual (self.r.read (), b'42\n')
        os.unlink (fn)
Exemplo n.º 15
0
    def testUnset (self):
        ayrton.main ('''export (TEST_ENV=42)
print (TEST_ENV)
unset ("TEST_ENV")
try:
    TEST_ENV
except NameError:
    print ("yes")''')
        # close stdout as per the description of setUpMockStdout()
        os.close (1)
        self.assertEqual (self.r.read (), b'42\nyes\n')
Exemplo n.º 16
0
    def testLtGt (self):
        fd, fn1= tempfile.mkstemp ()
        os.write (fd, b'42\n')
        os.close (fd)
        fn2= tempfile.mkstemp ()[1]

        ayrton.main ('cat () < "%s" > "%s"' % (fn1, fn2))

        contents= open (fn2).read ()
        # read() does not return bytes!
        self.assertEqual (contents, '42\n')

        os.unlink (fn1)
        os.unlink (fn2)
Exemplo n.º 17
0
    def testIterable (self):
        self.maxDiff= None
        ayrton.main ('''lines_read= 0

for line in echo ('yes'):
    if line=='yes':
        print ('yes!')
    else:
        print (repr (line))

    lines_read+= 1

print (lines_read)''')
        tearDownMockStdOut (self)
        self.assertEqual (self.mock_stdout.read (), 'yes!\n1\n')
Exemplo n.º 18
0
    def testIterable(self):
        ans = ayrton.main('''lines_read= 0

for line in echo ('yes'):
    if line=='yes':
        lines_read+= 1

exit (lines_read)''')

        self.assertEqual(ans, 1)
Exemplo n.º 19
0
    def testIterable (self):
        ans= ayrton.main ('''lines_read= 0

for line in echo ('yes'):
    if line=='yes':
        lines_read+= 1

exit (lines_read)''')

        self.assertEqual (ans, 1)
Exemplo n.º 20
0
    def __testRemote (self):
        """This test only succeeds if you you have password/passphrase-less access
        to localhost"""
        output= ayrton.main ('''with remote ('127.0.0.1', allow_agent=False) as s:
    print (USER)

value= s[1].readlines ()

# close the fd's, otherwise the test does not finish because the paramiko.Client() is waiting
# this means even more that the current remote() API sucks
s[0].close ()
s[1].close ()
s[2].close ()

return value''')

        self.assertEqual ( output, [ ('%s\n' % os.environ['USER']) ] )
Exemplo n.º 21
0
    def __testRemoteReturn (self):
        """This test only succeeds if you you have password/passphrase-less access
        to localhost"""
        output= ayrton.main ('''with remote ('127.0.0.1', allow_agent=False, _debug=True) as s:
    return 42

# close the fd's, otherwise the test does not finish because the paramiko.Client() is waiting
# this means even more that the current remote() API sucks
s[0].close ()
s[1].close ()
#s[2].close ()

try:
    return foo
except Exception as e:
    return e''')

        self.assertEqual (output, '''42\n''')
Exemplo n.º 22
0
    def __testRemoteEnv (self):
        """This test only succeeds if you you have password/passphrase-less access
        to localhost"""
        output= ayrton.main ('''with remote ('127.0.0.1', allow_agent=False) as s:
    print (SSH_CLIENT)

value= s[1].readlines ()

# close the fd's, otherwise the test does not finish because the paramiko.Client() is waiting
# this means even more that the current remote() API sucks
s[0].close ()
s[1].close ()
s[2].close ()

return value''')

        expected1= '''127.0.0.1 '''
        expected2= ''' 22\n'''
        self.assertEqual (output[0][:len (expected1)], expected1)
        self.assertEqual (output[0][-len (expected2):], expected2)
Exemplo n.º 23
0
 def testOrderedOptions (self):
     ayrton.main ("""echo (-l=True, --more=55, --ordered_options='yes!')""")
     tearDownMockStdOut (self)
     self.assertEqual (self.mock_stdout.read (), '-l --more 55 --ordered_options yes!\n')
     self.mock_stdout.close ()
Exemplo n.º 24
0
 def __testSimpleReturn (self):
     self.assertEqual (ayrton.main ('''return 50'''), 50)
Exemplo n.º 25
0
 def testSimpleFor (self):
     ayrton.main ('''for a in (1, 2): pass''')
Exemplo n.º 26
0
 def testTupleAssign (self):
     ayrton.main ('''(a, b)= (1, 2)''')
Exemplo n.º 27
0
 def testOrderedOptions(self):
     ayrton.main("""echo (-l=True, --more=55, --ordered_options='yes!')""")
     tearDownMockStdOut(self)
     self.assertEqual(self.mock_stdout.read(),
                      '-l --more 55 --ordered_options yes!\n')
     self.mock_stdout.close()
Exemplo n.º 28
0
 def testSimpleFor (self):
     ayrton.main ('''for a in (1, 2): pass''')
Exemplo n.º 29
0
    def testDefFun1 (self):
        ayrton.main ('''def foo ():
    true= 42
true ()''')
Exemplo n.º 30
0
    def testAssign (self):
        ayrton.main ('''a= lambda x: x
a (1)''')
Exemplo n.º 31
0
    def testFromImportAs (self):
        ayrton.main ('''from random import seed as foo
foo ()''')
Exemplo n.º 32
0
    def testFromImport (self):
        ayrton.main ('''from random import seed;
seed ()''')
Exemplo n.º 33
0
 def testSimpleCase (self):
     ayrton.main ('true ()')
Exemplo n.º 34
0
 def testTupleAssign (self):
     ayrton.main ('''(a, b)= (1, 2)''')
Exemplo n.º 35
0
 def testEnvironment (self):
     # NOTE: we convert envvars to str when we export() them
     ayrton.main ("""sh (-c='echo environments works: $FOO', _env=dict (FOO='yes'))""")
     tearDownMockStdOut (self)
     self.assertEqual (self.mock_stdout.read (), 'environments works: yes\n')
     self.mock_stdout.close ()
Exemplo n.º 36
0
    def testDefFunFails1 (self):
        ayrton.main ('''option ('errexit')
def foo ():
    false= lambda: True
    false ()''')
Exemplo n.º 37
0
 def __testSimpleReturn (self):
     self.assertEqual (ayrton.main ('''return 50'''), 50)