import os, sys
try:
    import sybprocess
except ImportError:
    # user private copy for old Python versions
    import MonetDBtesting.subprocess26 as subprocess

def client(cmd, input = None):
    clt = subprocess.Popen(cmd,
                           shell = True,
                           stdin = subprocess.PIPE,
                           stdout = subprocess.PIPE,
                           stderr = subprocess.PIPE,
                           universal_newlines = True)
    out, err = clt.communicate(input)
    sys.stdout.write(out)
    sys.stderr.write(err)

def main():
    xq_client = os.getenv('XQUERY_CLIENT')
    client('%s --input=my-document --collection=my-collection' % xq_client,
           '<document>test document</document>')
    client('%s -s "pf:documents()"' % xq_client)
    client('%s -s "pf:del-doc(\'my-document\')"' % xq_client)

main()

import os, sys
try:
    import sybprocess
except ImportError:
    # user private copy for old Python versions
    import MonetDBtesting.subprocess26 as subprocess

def client(cmd, input = None):
    clt = subprocess.Popen(cmd,
                           stdin = subprocess.PIPE,
                           stdout = subprocess.PIPE,
                           stderr = subprocess.PIPE,
                           universal_newlines = True)
    out, err = clt.communicate(input)
    sys.stdout.write(out)
    sys.stderr.write(err)

def main():
    xq_client = os.getenv('XQUERY_CLIENT').split()
    client(xq_client + ['--input=my-document', '--collection=my-collection'],
           '<document>test document</document>')
    client(xq_client + ['-s', 'for $doc in pf:documents() where $doc/@url = "my-document" return $doc'])
    client(xq_client + ['-s', 'pf:del-doc("my-document")'])

main()

Make test independent of whatever else is in the database. Also, use a different way of calling subprocess.Popen so that we can use quotes and dollars without having to do difficult cross-architectural escaping.
Make test independent of whatever else is in the database.
Also, use a different way of calling subprocess.Popen so that we can
use quotes and dollars without having to do difficult
cross-architectural escaping.

  import os, sys
  try:
      import sybprocess
  except ImportError:
      # user private copy for old Python versions
      import MonetDBtesting.subprocess26 as subprocess
  
  def client(cmd, input = None):
      clt = subprocess.Popen(cmd,
-                            shell = True,
                             stdin = subprocess.PIPE,
                             stdout = subprocess.PIPE,
                             stderr = subprocess.PIPE,
                             universal_newlines = True)
      out, err = clt.communicate(input)
      sys.stdout.write(out)
      sys.stderr.write(err)
  
  def main():
-     xq_client = os.getenv('XQUERY_CLIENT')
+     xq_client = os.getenv('XQUERY_CLIENT').split()
-     client('%s --input=my-document --collection=my-collection' % xq_client,
+     client(xq_client + ['--input=my-document', '--collection=my-collection'],
             '<document>test document</document>')
-     client('%s -s "pf:documents()"' % xq_client)
-     client('%s -s "pf:del-doc(\'my-document\')"' % xq_client)
+     client(xq_client + ['-s', 'for $doc in pf:documents() where $doc/@url = "my-document" return $doc'])
+     client(xq_client + ['-s', 'pf:del-doc("my-document")'])
  
  main()
  
Make test independent of whatever else is in the database. Also, use a different way of calling subprocess.Popen so that we can use quotes and dollars without having to do difficult cross-architectural escaping.
## Code Before:
import os, sys
try:
    import sybprocess
except ImportError:
    # user private copy for old Python versions
    import MonetDBtesting.subprocess26 as subprocess

def client(cmd, input = None):
    clt = subprocess.Popen(cmd,
                           shell = True,
                           stdin = subprocess.PIPE,
                           stdout = subprocess.PIPE,
                           stderr = subprocess.PIPE,
                           universal_newlines = True)
    out, err = clt.communicate(input)
    sys.stdout.write(out)
    sys.stderr.write(err)

def main():
    xq_client = os.getenv('XQUERY_CLIENT')
    client('%s --input=my-document --collection=my-collection' % xq_client,
           '<document>test document</document>')
    client('%s -s "pf:documents()"' % xq_client)
    client('%s -s "pf:del-doc(\'my-document\')"' % xq_client)

main()

## Instruction:
Make test independent of whatever else is in the database. Also, use a different way of calling subprocess.Popen so that we can use quotes and dollars without having to do difficult cross-architectural escaping.
## Code After:
import os, sys
try:
    import sybprocess
except ImportError:
    # user private copy for old Python versions
    import MonetDBtesting.subprocess26 as subprocess

def client(cmd, input = None):
    clt = subprocess.Popen(cmd,
                           stdin = subprocess.PIPE,
                           stdout = subprocess.PIPE,
                           stderr = subprocess.PIPE,
                           universal_newlines = True)
    out, err = clt.communicate(input)
    sys.stdout.write(out)
    sys.stderr.write(err)

def main():
    xq_client = os.getenv('XQUERY_CLIENT').split()
    client(xq_client + ['--input=my-document', '--collection=my-collection'],
           '<document>test document</document>')
    client(xq_client + ['-s', 'for $doc in pf:documents() where $doc/@url = "my-document" return $doc'])
    client(xq_client + ['-s', 'pf:del-doc("my-document")'])

main()
