<commit_before>#!/usr/bin/env python
import sys, tempfile, os, shutil, tempfile, subprocess
from StringIO import StringIO
import unittest
from zeroinstall.injector import model, qdom, config
from zeroinstall.support import ro_rmtree, basedir
from zeroinstall.zerostore import Stores

stores = Stores()

mydir = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.dirname(mydir))
import support

hello_uri = 'http://0install.net/tests/GNU-Hello.xml'

mydir = os.path.realpath(os.path.dirname(__file__))

hello_selections = os.path.join(mydir, 'selections.xml')
local_bad_version = os.path.join(mydir, 'bad-version.xml')
local_hello_path = os.path.join(mydir, 'hello2', 'hello2.xml')
local_cprog_command_path = os.path.join(mydir, 'cprog', 'cprog-command.xml')
local_cprog_path = os.path.join(mydir, 'cprog', 'cprog.xml')
local_pinned_path = os.path.join(mydir, 'pinned-version', 'pinned-version.xml')
top_build_deps = os.path.join(mydir, 'top-build-deps.xml')

compile_bin = os.path.join(mydir, '0compile-coverage')
assert os.path.exists(compile_bin)

if 'DISPLAY' in os.environ:
	del os.environ['DISPLAY']

zi_command = [os.environ['0COMPILE_0INSTALL']]

# Ensure it's cached now, to avoid extra output during the tests
if subprocess.call(zi_command + ['--source', '-c', 'download', hello_uri]):
	raise Exception("Failed to download hello world test program")

def compile(*args, **kwargs):
	run(*([sys.executable, compile_bin] + list(args)), **kwargs)

def run(*args, **kwargs):
	if not isinstance(args[0], basestring):
		args = args[0] + list(args[1:])
	child = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
	got, unused = child.communicate()
	code = child.wait()
	if code != kwargs.get('expect_status', 0):
		raise Exception("Exit status %d:\n%s" % (code, got))

	expected = kwargs.get('expect', '')
	if expected is not None: # pass None to explicily suppress check
		if expected:
			if expected.lower() not in got.lower():
				raise Exception("Expected '%s', got '%s'" % (expected, got))
		elif got:
			raise Exception("Expected nothing, got '%s'" % got)

# Detect accidental network access
os.environ['http_proxy'] = 'localhost:1111'<commit_msg>Ensure that ROX-Lib is downloaded before running the tests<commit_after>#!/usr/bin/env python
import sys, tempfile, os, shutil, tempfile, subprocess
from StringIO import StringIO
import unittest
from zeroinstall.injector import model, qdom, config
from zeroinstall.support import ro_rmtree, basedir
from zeroinstall.zerostore import Stores

stores = Stores()

mydir = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.dirname(mydir))
import support

hello_uri = 'http://0install.net/tests/GNU-Hello.xml'

mydir = os.path.realpath(os.path.dirname(__file__))

hello_selections = os.path.join(mydir, 'selections.xml')
local_bad_version = os.path.join(mydir, 'bad-version.xml')
local_hello_path = os.path.join(mydir, 'hello2', 'hello2.xml')
local_cprog_command_path = os.path.join(mydir, 'cprog', 'cprog-command.xml')
local_cprog_path = os.path.join(mydir, 'cprog', 'cprog.xml')
local_pinned_path = os.path.join(mydir, 'pinned-version', 'pinned-version.xml')
top_build_deps = os.path.join(mydir, 'top-build-deps.xml')

compile_bin = os.path.join(mydir, '0compile-coverage')
assert os.path.exists(compile_bin)

if 'DISPLAY' in os.environ:
	del os.environ['DISPLAY']

zi_command = [os.environ['0COMPILE_0INSTALL']]

# Ensure it's cached now, to avoid extra output during the tests
if subprocess.call(zi_command + ['--source', '-c', 'download', hello_uri]):
	raise Exception("Failed to download hello world test program")
if subprocess.call(zi_command + ['-c', 'download', '--version=2.0.6', 'http://rox.sourceforge.net/2005/interfaces/ROX-Lib']):
	raise Exception("Failed to download ROX-Lib test program")

def compile(*args, **kwargs):
	run(*([sys.executable, compile_bin] + list(args)), **kwargs)

def run(*args, **kwargs):
	if not isinstance(args[0], basestring):
		args = args[0] + list(args[1:])
	child = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
	got, unused = child.communicate()
	code = child.wait()
	if code != kwargs.get('expect_status', 0):
		raise Exception("Exit status %d:\n%s" % (code, got))

	expected = kwargs.get('expect', '')
	if expected is not None: # pass None to explicily suppress check
		if expected:
			if expected.lower() not in got.lower():
				raise Exception("Expected '%s', got '%s'" % (expected, got))
		elif got:
			raise Exception("Expected nothing, got '%s'" % got)

# Detect accidental network access
os.environ['http_proxy'] = 'localhost:1111'
{'fraction_non_alphanumeric': 0.1531648304169367, 'fraction_numerical': 0.007993087059840137, 'mean_word_length': 5.576704545454546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2090410', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1603, 'n_words': 388}