Esempio 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')
Esempio 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')
Esempio 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'')
Esempio 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()
Esempio 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')
Esempio 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)
Esempio 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()''')
Esempio 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)
Esempio 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()""")
Esempio 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()''')
Esempio 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')
Esempio 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)
Esempio 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')
Esempio 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)
Esempio 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')
Esempio 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)
Esempio 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')
Esempio 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)
Esempio 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)
Esempio 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']) ] )
Esempio 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''')
Esempio 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)
Esempio 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 ()
Esempio n. 24
0
 def __testSimpleReturn (self):
     self.assertEqual (ayrton.main ('''return 50'''), 50)
Esempio n. 25
0
 def testSimpleFor (self):
     ayrton.main ('''for a in (1, 2): pass''')
Esempio n. 26
0
 def testTupleAssign (self):
     ayrton.main ('''(a, b)= (1, 2)''')
Esempio 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()
Esempio n. 28
0
 def testSimpleFor (self):
     ayrton.main ('''for a in (1, 2): pass''')
Esempio n. 29
0
    def testDefFun1 (self):
        ayrton.main ('''def foo ():
    true= 42
true ()''')
Esempio n. 30
0
    def testAssign (self):
        ayrton.main ('''a= lambda x: x
a (1)''')
Esempio n. 31
0
    def testFromImportAs (self):
        ayrton.main ('''from random import seed as foo
foo ()''')
Esempio n. 32
0
    def testFromImport (self):
        ayrton.main ('''from random import seed;
seed ()''')
Esempio n. 33
0
 def testSimpleCase (self):
     ayrton.main ('true ()')
Esempio n. 34
0
 def testTupleAssign (self):
     ayrton.main ('''(a, b)= (1, 2)''')
Esempio 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 ()
Esempio n. 36
0
    def testDefFunFails1 (self):
        ayrton.main ('''option ('errexit')
def foo ():
    false= lambda: True
    false ()''')
Esempio n. 37
0
 def __testSimpleReturn (self):
     self.assertEqual (ayrton.main ('''return 50'''), 50)