<commit_before>import os
from shutil import which

import pytest

from cwltool.utils import onWindows

from .util import get_data, get_main_output, needs_docker

try:
    from galaxy.tools import deps  # type: ignore
except ImportError:
    deps = None

@needs_docker
@pytest.mark.skipif(not deps, reason="galaxy-lib is not installed")
def test_biocontainers() -> None:
    wflow = get_data("tests/seqtk_seq.cwl")
    job = get_data("tests/seqtk_seq_job.json")
    error_code, _, _ = get_main_output(["--beta-use-biocontainers", wflow, job])

    assert error_code == 0

@pytest.mark.skipif(onWindows(), reason="bioconda currently not working on MS Windows")
@pytest.mark.skipif(not deps, reason="galaxy-lib is not installed")
def test_bioconda() -> None:
    wflow = get_data("tests/seqtk_seq.cwl")
    job = get_data("tests/seqtk_seq_job.json")
    error_code, _, stderr = get_main_output(
        ["--beta-conda-dependencies", "--debug", wflow, job]
    )

    assert error_code == 0, stderr

@pytest.mark.skipif(not which("modulecmd"), reason="modulecmd not installed")
def test_modules() -> None:
    wflow = get_data("tests/random_lines.cwl")
    job = get_data("tests/random_lines_job.json")
    os.environ["MODULEPATH"] = os.path.join(
        os.getcwd(), "tests/test_deps_env/modulefiles"
    )
    error_code, _, stderr = get_main_output(
        [
            "--beta-dependency-resolvers-configuration",
            "tests/test_deps_env_modules_resolvers_conf.yml",
            "--debug",
            wflow,
            job,
        ]
    )

    assert error_code == 0, stderr
<commit_msg>test_dependencies: fix import of galaxy tool_util<commit_after>import os
from shutil import which
from types import ModuleType
from typing import Any, Optional

import pytest

from cwltool.utils import onWindows

from .util import get_data, get_main_output, needs_docker

deps = None  # type: Optional[ModuleType]
try:
    from galaxy.tool_util import deps
except ImportError:
    pass

@needs_docker
@pytest.mark.skipif(not deps, reason="galaxy-lib is not installed")
def test_biocontainers() -> None:
    wflow = get_data("tests/seqtk_seq.cwl")
    job = get_data("tests/seqtk_seq_job.json")
    error_code, _, _ = get_main_output(["--beta-use-biocontainers", wflow, job])

    assert error_code == 0

@pytest.mark.skipif(onWindows(), reason="bioconda currently not working on MS Windows")
@pytest.mark.skipif(not deps, reason="galaxy-lib is not installed")
def test_bioconda() -> None:
    wflow = get_data("tests/seqtk_seq.cwl")
    job = get_data("tests/seqtk_seq_job.json")
    error_code, _, stderr = get_main_output(
        ["--beta-conda-dependencies", "--debug", wflow, job]
    )

    assert error_code == 0, stderr

@pytest.mark.skipif(not deps, reason="galaxy-lib is not installed")
@pytest.mark.skipif(not which("modulecmd"), reason="modulecmd not installed")
def test_modules() -> None:
    wflow = get_data("tests/random_lines.cwl")
    job = get_data("tests/random_lines_job.json")
    os.environ["MODULEPATH"] = os.path.join(
        os.getcwd(), "tests/test_deps_env/modulefiles"
    )
    error_code, _, stderr = get_main_output(
        [
            "--beta-dependency-resolvers-configuration",
            "tests/test_deps_env_modules_resolvers_conf.yml",
            "--debug",
            wflow,
            job,
        ]
    )

    assert error_code == 0, stderr
<|endoftext|>


<commit_before>from nose.tools import assert_true, assert_false, assert_equal, assert_list_equal, raises
from .schema import *

def test_nullable_dependency():
    """test nullable unique foreign key"""

    # Thing C has a nullable dependency on B whose primary key is composite
    a = ThingA()
    b = ThingB()
    c = ThingC()

    # clear previous contents if any.
    c.delete_quick()
    b.delete_quick()
    a.delete_quick()

    a.insert(dict(a=a) for a in range(7))

    b.insert1(dict(b1=1, b2=1, b3=100))
    b.insert1(dict(b1=1, b2=2, b3=100))

    # missing foreign key attributes = ok
    c.insert1(dict(a=0))
    c.insert1(dict(a=1, b1=33))
    c.insert1(dict(a=2, b2=77))

    # unique foreign key attributes = ok
    c.insert1(dict(a=3, b1=1, b2=1))
    c.insert1(dict(a=4, b1=1, b2=2))

    assert_true(len(c) == len(c.fetch()) == 5)

@raises(dj.errors.DuplicateError)
def test_unique_dependency():
    """test nullable unique foreign key"""

    # Thing C has a nullable dependency on B whose primary key is composite
    a = ThingA()
    b = ThingB()
    c = ThingC()

    # clear previous contents if any.
    c.delete_quick()
    b.delete_quick()
    a.delete_quick()

    a.insert(dict(a=a) for a in range(7))

    b.insert1(dict(b1=1, b2=1, b3=100))
    b.insert1(dict(b1=1, b2=2, b3=100))

    c.insert1(dict(a=0, b1=1, b2=1))
    # duplicate foreign key attributes = not ok
    c.insert1(dict(a=1, b1=1, b2=1))
<commit_msg>add a test for unite_master_parts<commit_after>from nose.tools import assert_true, raises, assert_equal
from .schema import *
from datajoint.dependencies import unite_master_parts

def test_unite_master_parts():
    assert_equal(unite_master_parts(
        ['`s`.`a`', '`s`.`a__q`', '`s`.`b`', '`s`.`c`', '`s`.`c__q`', '`s`.`b__q`', '`s`.`d`', '`s`.`a__r`']),
        ['`s`.`a`', '`s`.`a__q`', '`s`.`a__r`', '`s`.`b`', '`s`.`b__q`', '`s`.`c`', '`s`.`c__q`', '`s`.`d`'])

def test_nullable_dependency():
    """test nullable unique foreign key"""
    # Thing C has a nullable dependency on B whose primary key is composite
    a = ThingA()
    b = ThingB()
    c = ThingC()

    # clear previous contents if any.
    c.delete_quick()
    b.delete_quick()
    a.delete_quick()

    a.insert(dict(a=a) for a in range(7))

    b.insert1(dict(b1=1, b2=1, b3=100))
    b.insert1(dict(b1=1, b2=2, b3=100))

    # missing foreign key attributes = ok
    c.insert1(dict(a=0))
    c.insert1(dict(a=1, b1=33))
    c.insert1(dict(a=2, b2=77))

    # unique foreign key attributes = ok
    c.insert1(dict(a=3, b1=1, b2=1))
    c.insert1(dict(a=4, b1=1, b2=2))

    assert_true(len(c) == len(c.fetch()) == 5)

@raises(dj.errors.DuplicateError)
def test_unique_dependency():
    """test nullable unique foreign key"""

    # Thing C has a nullable dependency on B whose primary key is composite
    a = ThingA()
    b = ThingB()
    c = ThingC()

    # clear previous contents if any.
    c.delete_quick()
    b.delete_quick()
    a.delete_quick()

    a.insert(dict(a=a) for a in range(7))

    b.insert1(dict(b1=1, b2=1, b3=100))
    b.insert1(dict(b1=1, b2=2, b3=100))

    c.insert1(dict(a=0, b1=1, b2=1))
    # duplicate foreign key attributes = not ok
    c.insert1(dict(a=1, b1=1, b2=1))
<|endoftext|>


<commit_before>import unittest
import os
import datetime
import re
import django
import logging
import mock
import paramiko
import subprocess
from urllib2 import URLError
from requests.exceptions import ConnectionError
from distutils import dir_util
from shutil import rmtree
from time import sleep
from django_docker_engine.docker_utils import DockerClientWrapper, DockerContainerSpec

logging.basicConfig()
logger = logging.getLogger(__name__)

class LiveDockerTests(unittest.TestCase):

    def setUp(self):
        # Docker Engine's clock stops when the computer goes to sleep,
        # and restarts where it left off when it wakes up.
        # https://github.com/docker/for-mac/issues/17
        # This gets it back in sync with reality.
        subprocess.call('docker run --rm --privileged alpine hwclock -s'.split(' '))

        # mkdtemp is the obvious way to do this, but
        # the resulting directory is not visible to Docker.
        base = '/tmp/django-docker-tests'
        self.tmp = os.path.join(
            base,
            re.sub(r'\W', '_', str(datetime.datetime.now())))
        self.mkdir_on_host(self.tmp)
        self.client_wrapper = DockerClientWrapper()
        self.test_label = self.client_wrapper.root_label + '.test'
        self.initial_containers = self.client_wrapper.list()
        self.initial_tmp = self.ls_tmp()

        # There may be containers running which are not "my containers".
        self.assertEqual(0, self.count_containers())

    def docker_host(self):
        return os.environ.get('DOCKER_HOST')

    def docker_host_ip(self):
        return re.search(
            r'^tcp://(\d+\.\d+\.\d+\.\d+):\d+$',
            self.docker_host()
        ).group(1)

    def remote_exec(self, command):
        host_ip = self.docker_host_ip()
        key = paramiko.RSAKey.from_private_key_file(LiveDockerTests.PEM)
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        client.connect(hostname=host_ip, username='ec2-user', pkey=key)
        client.exec_command(command)

    PEM = 'django_docker_cloudformation.pem'

    # These *_on_host methods are in a sense duplicates of the helper methods
    # in docker_utils.py, but I think here it makes sense to have explicit
    # if-thens, rather than hiding it with polymorphism.

    def rmdir_on_host(self, path):
        if self.docker_host():
            self.remote_exec('rm -rf {}'.format(path))
        else:
            rmtree(self.tmp)

    def mkdir_on_host(self, path):
        if self.docker_host():
            self.remote_exec('mkdir -p {}'.format(path))
        else:
            dir_util.mkpath(path)

    def write_to_host(self, content, path):
        if self.docker_host():
            self.remote_exec("cat > {} <<'END'\n{}\nEND".format(path, content))
        else:
            with open(path, 'w') as file:
                file.write(content)
                file.write('\n')  # For consistency with heredoc

    # Other supporting methods for tests:

    def timestamp(self):
        return re.sub(r'\W', '_', str(datetime.datetime.now()))

    def count_containers(self):
        return len(self.client_wrapper.list(
            filters={'label': self.test_label}
        ))

    def assert_loads_immediately(self, url, content, client=django.test.Client()):
        response = client.get(url)
        # TODO: check status: confirm response.status_code != 200:
        self.assertIn(content, response.content)

    def assert_loads_eventually(self, url, content, client=django.test.Client()):
        for i in xrange(10):
            try:
                response = client.get(url)
                if response.status_code == 200:
                    self.assertIn(content, response.content)
                return
            except (ConnectionError, URLError):
                pass
            sleep(1)
        self.fail('Never got 200')

    def ls_tmp(self):
        try:
            return sorted(os.listdir('/tmp/django-docker'))
        except OSError:
            return []

class LiveDockerTestsDirty(LiveDockerTests):

    def test_container_spec_with_extra_directories_bad(self):
        # This test leaves temp files around so we can't make
        # the same tearDown assertions that we do for other tests.
        container_name = self.timestamp()
        test_dirs = ["/test", "coffee"]
        with self.assertRaises(AssertionError) as context:
            self.client_wrapper.run(
                DockerContainerSpec(
                    image_name='nginx:1.10.3-alpine',
                    container_name=container_name,
                    input={'foo': 'bar'},
                    container_input_path='/usr/share/nginx/html/index.html',
                    extra_directories=test_dirs,
                    labels={self.test_label: 'true'}
                )
            )
        self.assertEqual(
            context.exception.message,
            "Specified path: `coffee` is not absolute"
        )

class LiveDockerTestsClean(LiveDockerTests):

    def tearDown(self):
        self.rmdir_on_host(self.tmp)
        self.client_wrapper.purge_by_label(self.test_label)

        self.assertEqual(self.initial_containers, self.client_wrapper.list())
        self.assertEqual(self.initial_tmp, self.ls_tmp())

    # Utils for accessing remote docker engine:

    # Tests at the top are low level;
    # Tests at the bottom are at higher levels of abstraction.

    def test_at_a_minimum(self):
        # A no-op, but if the tests stall, it may be
        # helpful to see if they are even starting.
        self.assertTrue(True)

    def test_container_spec_no_input(self):
        url = self.client_wrapper.run(DockerContainerSpec(
            image_name='nginx:1.10.3-alpine',
            container_name=self.timestamp(),
            labels={self.test_label: 'true'}
        ))
        # TODO: self.assert_loads_immediately(url, 'Please wait')
        self.assert_loads_eventually(url, 'Welcome to nginx!')

    def test_container_spec_with_input(self):
        url = self.client_wrapper.run(DockerContainerSpec(
            image_name='nginx:1.10.3-alpine',
            container_name=self.timestamp(),
            labels={self.test_label: 'true'},
            input={'foo': 'bar'},
            container_input_path='/usr/share/nginx/html/index.html'
        ))
        self.assert_loads_eventually(url, '{"foo": "bar"}')

    def test_container_spec_with_extra_directories_good(self):
        container_name = self.timestamp()

        test_dirs = ["/test", "/coffee"]
        self.client_wrapper.run(
            DockerContainerSpec(
                image_name='nginx:1.10.3-alpine',
                container_name=container_name,
                input={'foo': 'bar'},
                container_input_path='/usr/share/nginx/html/index.html',
                extra_directories=test_dirs,
                labels={self.test_label: 'true'}
            )
        )

    def test_purge(self):
        """
        WARNING: I think this is prone to race conditions.
        If you get an error, try just giving it more time.
        """
        self.assertEqual(0, self.count_containers())
        ls_tmp_orig = self.ls_tmp()

        url = self.client_wrapper.run(DockerContainerSpec(
            image_name='nginx:1.10.3-alpine',
            container_name=self.timestamp(),
            labels={self.test_label: 'true'}
        ))
        self.assertEqual(1, self.count_containers())
        self.assert_loads_eventually(url, 'Welcome to nginx!')
        self.assertGreater(self.ls_tmp(), ls_tmp_orig)

        self.client_wrapper.purge_inactive(5)
        self.assertEqual(1, self.count_containers())
        # Even without activity, it should not be purged if younger than the limit.

        sleep(2)

        self.assert_loads_eventually(url, 'Welcome to nginx!')

        # Be careful of race conditions if developing locally:
        # I had to give a bit more time for the same test to pass with remote Docker.
        self.client_wrapper.purge_inactive(4)
        sleep(2)

        self.assertEqual(1, self.count_containers())
        # With a tighter time limit, recent activity should keep it alive.

        sleep(2)

        self.client_wrapper.purge_inactive(0)
        self.assertEqual(0, self.count_containers())
        # But with an even tighter limit, it should be purged.

class MockDockerTests(unittest.TestCase):
    def test_pull(self):
        with mock.patch.object(
            DockerClientWrapper()._containers_manager._images_client, "pull"
        ) as pull_mock:
            DockerClientWrapper().pull("cool_image")
            self.assertTrue(pull_mock.called)
<commit_msg>Remove blank lines. Flake8<commit_after>import unittest
import os
import datetime
import re
import django
import logging
import mock
import paramiko
import subprocess
from urllib2 import URLError
from requests.exceptions import ConnectionError
from distutils import dir_util
from shutil import rmtree
from time import sleep
from django_docker_engine.docker_utils import DockerClientWrapper, DockerContainerSpec

logging.basicConfig()
logger = logging.getLogger(__name__)

class LiveDockerTests(unittest.TestCase):

    def setUp(self):
        # Docker Engine's clock stops when the computer goes to sleep,
        # and restarts where it left off when it wakes up.
        # https://github.com/docker/for-mac/issues/17
        # This gets it back in sync with reality.
        subprocess.call('docker run --rm --privileged alpine hwclock -s'.split(' '))

        # mkdtemp is the obvious way to do this, but
        # the resulting directory is not visible to Docker.
        base = '/tmp/django-docker-tests'
        self.tmp = os.path.join(
            base,
            re.sub(r'\W', '_', str(datetime.datetime.now())))
        self.mkdir_on_host(self.tmp)
        self.client_wrapper = DockerClientWrapper()
        self.test_label = self.client_wrapper.root_label + '.test'
        self.initial_containers = self.client_wrapper.list()
        self.initial_tmp = self.ls_tmp()

        # There may be containers running which are not "my containers".
        self.assertEqual(0, self.count_containers())

    def docker_host(self):
        return os.environ.get('DOCKER_HOST')

    def docker_host_ip(self):
        return re.search(
            r'^tcp://(\d+\.\d+\.\d+\.\d+):\d+$',
            self.docker_host()
        ).group(1)

    def remote_exec(self, command):
        host_ip = self.docker_host_ip()
        key = paramiko.RSAKey.from_private_key_file(LiveDockerTests.PEM)
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        client.connect(hostname=host_ip, username='ec2-user', pkey=key)
        client.exec_command(command)

    PEM = 'django_docker_cloudformation.pem'

    # These *_on_host methods are in a sense duplicates of the helper methods
    # in docker_utils.py, but I think here it makes sense to have explicit
    # if-thens, rather than hiding it with polymorphism.

    def rmdir_on_host(self, path):
        if self.docker_host():
            self.remote_exec('rm -rf {}'.format(path))
        else:
            rmtree(self.tmp)

    def mkdir_on_host(self, path):
        if self.docker_host():
            self.remote_exec('mkdir -p {}'.format(path))
        else:
            dir_util.mkpath(path)

    def write_to_host(self, content, path):
        if self.docker_host():
            self.remote_exec("cat > {} <<'END'\n{}\nEND".format(path, content))
        else:
            with open(path, 'w') as file:
                file.write(content)
                file.write('\n')  # For consistency with heredoc

    # Other supporting methods for tests:
    def timestamp(self):
        return re.sub(r'\W', '_', str(datetime.datetime.now()))

    def count_containers(self):
        return len(self.client_wrapper.list(
            filters={'label': self.test_label}
        ))

    def assert_loads_immediately(self, url, content, client=django.test.Client()):
        response = client.get(url)
        # TODO: check status: confirm response.status_code != 200:
        self.assertIn(content, response.content)

    def assert_loads_eventually(self, url, content, client=django.test.Client()):
        for i in xrange(10):
            try:
                response = client.get(url)
                if response.status_code == 200:
                    self.assertIn(content, response.content)
                return
            except (ConnectionError, URLError):
                pass
            sleep(1)
        self.fail('Never got 200')

    def ls_tmp(self):
        try:
            return sorted(os.listdir('/tmp/django-docker'))
        except OSError:
            return []

class LiveDockerTestsDirty(LiveDockerTests):
    # This test leaves temp files around so we can't make
    # the same tearDown assertions that we do for other tests.

    def test_container_spec_with_extra_directories_bad(self):
        container_name = self.timestamp()
        test_dirs = ["/test", "coffee"]
        with self.assertRaises(AssertionError) as context:
            self.client_wrapper.run(
                DockerContainerSpec(
                    image_name='nginx:1.10.3-alpine',
                    container_name=container_name,
                    input={'foo': 'bar'},
                    container_input_path='/usr/share/nginx/html/index.html',
                    extra_directories=test_dirs,
                    labels={self.test_label: 'true'}
                )
            )
        self.assertEqual(
            context.exception.message,
            "Specified path: `coffee` is not absolute"
        )

class LiveDockerTestsClean(LiveDockerTests):

    def tearDown(self):
        self.rmdir_on_host(self.tmp)
        self.client_wrapper.purge_by_label(self.test_label)

        self.assertEqual(self.initial_containers, self.client_wrapper.list())
        self.assertEqual(self.initial_tmp, self.ls_tmp())

    # Tests at the top are low level;
    # Tests at the bottom are at higher levels of abstraction.

    def test_at_a_minimum(self):
        # A no-op, but if the tests stall, it may be
        # helpful to see if they are even starting.
        self.assertTrue(True)

    def test_container_spec_no_input(self):
        url = self.client_wrapper.run(DockerContainerSpec(
            image_name='nginx:1.10.3-alpine',
            container_name=self.timestamp(),
            labels={self.test_label: 'true'}
        ))
        # TODO: self.assert_loads_immediately(url, 'Please wait')
        self.assert_loads_eventually(url, 'Welcome to nginx!')

    def test_container_spec_with_input(self):
        url = self.client_wrapper.run(DockerContainerSpec(
            image_name='nginx:1.10.3-alpine',
            container_name=self.timestamp(),
            labels={self.test_label: 'true'},
            input={'foo': 'bar'},
            container_input_path='/usr/share/nginx/html/index.html'
        ))
        self.assert_loads_eventually(url, '{"foo": "bar"}')

    def test_container_spec_with_extra_directories_good(self):
        container_name = self.timestamp()

        test_dirs = ["/test", "/coffee"]
        self.client_wrapper.run(
            DockerContainerSpec(
                image_name='nginx:1.10.3-alpine',
                container_name=container_name,
                input={'foo': 'bar'},
                container_input_path='/usr/share/nginx/html/index.html',
                extra_directories=test_dirs,
                labels={self.test_label: 'true'}
            )
        )

    def test_purge(self):
        """
        WARNING: I think this is prone to race conditions.
        If you get an error, try just giving it more time.
        """
        self.assertEqual(0, self.count_containers())
        ls_tmp_orig = self.ls_tmp()

        url = self.client_wrapper.run(DockerContainerSpec(
            image_name='nginx:1.10.3-alpine',
            container_name=self.timestamp(),
            labels={self.test_label: 'true'}
        ))
        self.assertEqual(1, self.count_containers())
        self.assert_loads_eventually(url, 'Welcome to nginx!')
        self.assertGreater(self.ls_tmp(), ls_tmp_orig)

        self.client_wrapper.purge_inactive(5)
        self.assertEqual(1, self.count_containers())
        # Even without activity, it should not be purged if younger than the limit.

        sleep(2)

        self.assert_loads_eventually(url, 'Welcome to nginx!')

        # Be careful of race conditions if developing locally:
        # I had to give a bit more time for the same test to pass with remote Docker.
        self.client_wrapper.purge_inactive(4)
        sleep(2)

        self.assertEqual(1, self.count_containers())
        # With a tighter time limit, recent activity should keep it alive.

        sleep(2)

        self.client_wrapper.purge_inactive(0)
        self.assertEqual(0, self.count_containers())
        # But with an even tighter limit, it should be purged.

class MockDockerTests(unittest.TestCase):
    def test_pull(self):
        with mock.patch.object(
            DockerClientWrapper()._containers_manager._images_client, "pull"
        ) as pull_mock:
            DockerClientWrapper().pull("cool_image")
            self.assertTrue(pull_mock.called)
<|endoftext|>


<commit_before># -*- coding: utf-8 -*-
"""
    Pygments tests with example files
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import os
import pprint
import difflib
import cPickle as pickle

from pygments.lexers import get_lexer_for_filename, get_lexer_by_name
from pygments.token import Error
from pygments.util import ClassNotFound, b

STORE_OUTPUT = False

# generate methods
def test_example_files():
    testdir = os.path.dirname(__file__)
    outdir = os.path.join(testdir, 'examplefiles', 'output')
    if STORE_OUTPUT and not os.path.isdir(outdir):
        os.makedirs(outdir)
    for fn in os.listdir(os.path.join(testdir, 'examplefiles')):
        if fn.startswith('.') or fn.endswith('#'):
            continue

        absfn = os.path.join(testdir, 'examplefiles', fn)
        if not os.path.isfile(absfn):
            continue
        outfn = os.path.join(outdir, fn)

        try:
            lx = get_lexer_for_filename(absfn)
        except ClassNotFound:
            if "_" not in fn:
                raise AssertionError('file %r has no registered extension, '
                                     'nor is of the form <lexer>_filename '
                                     'for overriding, thus no lexer found.'
                                    % fn)
            try:
                name, rest = fn.split("_", 1)
                lx = get_lexer_by_name(name)
            except ClassNotFound:
                raise AssertionError('no lexer found for file %r' % fn)
        yield check_lexer, lx, absfn, outfn

def check_lexer(lx, absfn, outfn):
    text = open(absfn, 'rb').read()
    text = text.replace(b('\r\n'), b('\n'))
    text = text.strip(b('\n')) + b('\n')
    try:
        text = text.decode('utf-8')
    except UnicodeError:
        text = text.decode('latin1')
    ntext = []
    tokens = []
    for type, val in lx.get_tokens(text):
        ntext.append(val)
        assert type != Error, 'lexer %s generated error token for %s' % \
                (lx, absfn)
        tokens.append((type, val))
    if u''.join(ntext) != text:
        print '\n'.join(difflib.unified_diff(u''.join(ntext).splitlines(),
                                             text.splitlines()))
        raise AssertionError('round trip failed for ' + absfn)

    # check output against previous run if enabled
    if STORE_OUTPUT:
        # no previous output -- store it
        if not os.path.isfile(outfn):
            fp = open(outfn, 'wb')
            try:
                pickle.dump(tokens, fp)
            finally:
                fp.close()
            return
        # otherwise load it and compare
        fp = open(outfn, 'rb')
        try:
            stored_tokens = pickle.load(fp)
        finally:
            fp.close()
        if stored_tokens != tokens:
            f1 = pprint.pformat(stored_tokens)
            f2 = pprint.pformat(tokens)
            print '\n'.join(difflib.unified_diff(f1.splitlines(),
                                                 f2.splitlines()))
            assert False, absfn
<commit_msg>Show more info about error token failures.<commit_after># -*- coding: utf-8 -*-
"""
    Pygments tests with example files
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import os
import pprint
import difflib
import cPickle as pickle

from pygments.lexers import get_lexer_for_filename, get_lexer_by_name
from pygments.token import Error
from pygments.util import ClassNotFound, b

STORE_OUTPUT = False

# generate methods
def test_example_files():
    testdir = os.path.dirname(__file__)
    outdir = os.path.join(testdir, 'examplefiles', 'output')
    if STORE_OUTPUT and not os.path.isdir(outdir):
        os.makedirs(outdir)
    for fn in os.listdir(os.path.join(testdir, 'examplefiles')):
        if fn.startswith('.') or fn.endswith('#'):
            continue

        absfn = os.path.join(testdir, 'examplefiles', fn)
        if not os.path.isfile(absfn):
            continue
        outfn = os.path.join(outdir, fn)

        try:
            lx = get_lexer_for_filename(absfn)
        except ClassNotFound:
            if "_" not in fn:
                raise AssertionError('file %r has no registered extension, '
                                     'nor is of the form <lexer>_filename '
                                     'for overriding, thus no lexer found.'
                                    % fn)
            try:
                name, rest = fn.split("_", 1)
                lx = get_lexer_by_name(name)
            except ClassNotFound:
                raise AssertionError('no lexer found for file %r' % fn)
        yield check_lexer, lx, absfn, outfn

def check_lexer(lx, absfn, outfn):
    text = open(absfn, 'rb').read()
    text = text.replace(b('\r\n'), b('\n'))
    text = text.strip(b('\n')) + b('\n')
    try:
        text = text.decode('utf-8')
    except UnicodeError:
        text = text.decode('latin1')
    ntext = []
    tokens = []
    for type, val in lx.get_tokens(text):
        ntext.append(val)
        assert type != Error, \
            'lexer %s generated error token for %s: %r at position %d' % \
            (lx, absfn, val, len(u''.join(ntext)))
        tokens.append((type, val))
    if u''.join(ntext) != text:
        print '\n'.join(difflib.unified_diff(u''.join(ntext).splitlines(),
                                             text.splitlines()))
        raise AssertionError('round trip failed for ' + absfn)

    # check output against previous run if enabled
    if STORE_OUTPUT:
        # no previous output -- store it
        if not os.path.isfile(outfn):
            fp = open(outfn, 'wb')
            try:
                pickle.dump(tokens, fp)
            finally:
                fp.close()
            return
        # otherwise load it and compare
        fp = open(outfn, 'rb')
        try:
            stored_tokens = pickle.load(fp)
        finally:
            fp.close()
        if stored_tokens != tokens:
            f1 = pprint.pformat(stored_tokens)
            f2 = pprint.pformat(tokens)
            print '\n'.join(difflib.unified_diff(f1.splitlines(),
                                                 f2.splitlines()))
            assert False, absfn
<|endoftext|>


<commit_before>from arpa.models.simple import ARPAModelSimple

def test_new_model_counts():
    lm = ARPAModelSimple()
    assert lm.counts() == []

def test_new_model_len():
    lm = ARPAModelSimple()
    assert len(lm) == 0

def test_new_model_order():
    lm = ARPAModelSimple()
    assert lm.order() is None

def test_new_model_vocabulary():
    lm = ARPAModelSimple()
    assert lm.vocabulary() == []
<commit_msg>test for "foo" in lm<commit_after>from arpa.models.simple import ARPAModelSimple

def test_new_model_contains():
    lm = ARPAModelSimple()
    lm.add_entry(["foo"], 1.0)
    assert "foo" in lm

def test_new_model_counts():
    lm = ARPAModelSimple()
    assert lm.counts() == []

def test_new_model_len():
    lm = ARPAModelSimple()
    assert len(lm) == 0

def test_new_model_order():
    lm = ARPAModelSimple()
    assert lm.order() is None

def test_new_model_vocabulary():
    lm = ARPAModelSimple()
    assert lm.vocabulary() == []
<|endoftext|>


<commit_before>import io
import random

from .common import *

class TestRandomInput(TestCase):

    def test_random_input(self):
        random_data = ''.join(map(chr, [random.randint(0, 127) for _ in range(1024)])).encode('latin-1')
        with self.assertRaises(av.AVError):
            av.open(io.BytesIO(random_data))
<commit_msg>Remove the random input test, as it is flawed.<commit_after><|endoftext|>


<commit_before>#!/usr/bin/python3

import sys
import os

try:
    from bin import ldmlfonts
except ImportError:
    sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'bin')))
    from bin import ldmlfonts

def setup_module():
    ldmlfonts.read_font_data('Script2Font.csv')

def test_arabic_africa():
    assert ldmlfonts.suggestions['Arab_NG'][0] == 'Harmattan'

def test_arabic_asia():
    assert ldmlfonts.suggestions['Arab_PK'][0] == 'Awami Nastaliq'

def test_arabic():
    assert ldmlfonts.suggestions['Arab'][0] == 'Scheherazade'

def test_coptic():
    assert ldmlfonts.suggestions['Copt'][1] == 'Sophia Nubian'

def test_aa():
    assert ldmlfonts.find_fonts('aa')[0] == 'Charis SIL'

def test_aa_arab():
    assert ldmlfonts.find_fonts('aa-Arab')[0] == 'Scheherazade'

def test_cop():
    assert ldmlfonts.find_fonts('cop')[0] == 'NotoSansCoptic'

def test_cop_arab():
    assert ldmlfonts.find_fonts('cop-Arab')[0] == 'Scheherazade'

def test_cop_grek():
    assert ldmlfonts.find_fonts('cop-Grek')[0] == 'Gentium Plus'

def test_el():
    assert ldmlfonts.find_fonts('el')[0] == 'Gentium Plus'

def test_ha():
    assert ldmlfonts.find_fonts('ha')[0] == 'Charis SIL'

def test_ha_arab():
    assert ldmlfonts.find_fonts('ha-Arab')[0] == 'Harmattan'

def test_ha_cm():
    assert ldmlfonts.find_fonts('ha-CM')[0] == 'Harmattan'

def test_ha_sd():
    assert ldmlfonts.find_fonts('ha-SD')[0] == 'Scheherazade'
<commit_msg>Update module name due to filename changes<commit_after>#!/usr/bin/python3

import sys
import os

try:
    from bin import sldraddfonts
except ImportError:
    sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'bin')))
    from bin import sldraddfonts

def setup_module():
    sldraddfonts.read_font_data('Script2Font.csv')

def test_arabic_africa():
    assert sldraddfonts.suggestions['Arab_NG'][0] == 'Harmattan'

def test_arabic_asia():
    assert sldraddfonts.suggestions['Arab_PK'][0] == 'Awami Nastaliq'

def test_arabic():
    assert sldraddfonts.suggestions['Arab'][0] == 'Scheherazade'

def test_coptic():
    assert sldraddfonts.suggestions['Copt'][1] == 'Sophia Nubian'

def test_aa():
    assert sldraddfonts.find_fonts('aa')[0] == 'Charis SIL'

def test_aa_arab():
    assert sldraddfonts.find_fonts('aa-Arab')[0] == 'Scheherazade'

def test_cop():
    assert sldraddfonts.find_fonts('cop')[0] == 'NotoSansCoptic'

def test_cop_arab():
    assert sldraddfonts.find_fonts('cop-Arab')[0] == 'Scheherazade'

def test_cop_grek():
    assert sldraddfonts.find_fonts('cop-Grek')[0] == 'Gentium Plus'

def test_el():
    assert sldraddfonts.find_fonts('el')[0] == 'Gentium Plus'

def test_ha():
    assert sldraddfonts.find_fonts('ha')[0] == 'Charis SIL'

def test_ha_arab():
    assert sldraddfonts.find_fonts('ha-Arab')[0] == 'Harmattan'

def test_ha_cm():
    assert sldraddfonts.find_fonts('ha-CM')[0] == 'Harmattan'

def test_ha_sd():
    assert sldraddfonts.find_fonts('ha-SD')[0] == 'Scheherazade'
<|endoftext|>


<commit_before>import os

from tornado.testing import AsyncTestCase, gen_test

from scrapydd.spiderplugin import SpiderPluginManager
from scrapydd.config import Config
from scrapydd.models import init_database, SpiderPluginParameterDatatype

TETS_PACKAGE_PATH = os.path.join(os.path.dirname(__file__), 'test_plugin',
                                 'dist',
                                 'test_plugin-1.0-py3.6.egg')

class SpiderPluginManagerTest(AsyncTestCase):
    @classmethod
    def setUpClass(cls):
        os.environ['ASYNC_TEST_TIMEOUT'] = '500'
        if os.path.exists('test.db'):
            os.remove('test.db')
        config = Config(values={'database_url': 'sqlite:///test.db'})
        init_database(config)

    @gen_test(timeout=120)
    def test_add_sys_plugin(self):
        target = SpiderPluginManager()
        plugin_name = 'test_plugin'
        f_egg = open(TETS_PACKAGE_PATH, 'rb')
        actual = yield target.get_plugin_info(f_egg, plugin_name)
        self.assertEqual('test_plugin', actual.get('name'))
        self.assertIsNotNone(actual.get('parameters'))
        parameters = actual.get('parameters')
        self.assertEqual(1, len(parameters.keys()))
        self.assertTrue('ENABLED' in parameters)
        enabled_parameter = parameters['ENABLED']
        self.assertEqual('bool', enabled_parameter['type'])
        self.assertEqual(True, enabled_parameter['required'])

    @gen_test(timeout=120)
    def test_plugin_execute(self):
        target = SpiderPluginManager()
        plugin_name = 'test_plugin'
        f_egg = open(TETS_PACKAGE_PATH, 'rb')
        yield target.add_sys_plugin(f_egg, plugin_name)
        saved = target.get_plugin(plugin_name)
        self.assertIsNotNone(saved)
        self.assertEqual(saved.name, plugin_name)
        self.assertEqual(len(saved.parameters), 1)
        parameter = saved.parameters[0]
        self.assertEqual(parameter.key, 'ENABLED')
        self.assertEqual(parameter.datatype,
                         SpiderPluginParameterDatatype.bool)
        self.assertEqual(parameter.required, True)
        self.assertEqual(parameter.default_value, 'True')
<commit_msg>skip plugin tests<commit_after>import os
from unittest import skip
from tornado.testing import AsyncTestCase, gen_test
from scrapydd.spiderplugin import SpiderPluginManager
from scrapydd.config import Config
from scrapydd.models import init_database, SpiderPluginParameterDatatype

TETS_PACKAGE_PATH = os.path.join(os.path.dirname(__file__), 'test_plugin',
                                 'dist',
                                 'test_plugin-1.0-py3.6.egg')

class SpiderPluginManagerTest(AsyncTestCase):
    @classmethod
    def setUpClass(cls):
        os.environ['ASYNC_TEST_TIMEOUT'] = '500'
        if os.path.exists('test.db'):
            os.remove('test.db')
        config = Config(values={'database_url': 'sqlite:///test.db'})
        init_database(config)

    @gen_test(timeout=120)
    @skip
    def test_add_sys_plugin(self):
        target = SpiderPluginManager()
        plugin_name = 'test_plugin'
        f_egg = open(TETS_PACKAGE_PATH, 'rb')
        actual = yield target.get_plugin_info(f_egg, plugin_name)
        self.assertEqual('test_plugin', actual.get('name'))
        self.assertIsNotNone(actual.get('parameters'))
        parameters = actual.get('parameters')
        self.assertEqual(1, len(parameters.keys()))
        self.assertTrue('ENABLED' in parameters)
        enabled_parameter = parameters['ENABLED']
        self.assertEqual('bool', enabled_parameter['type'])
        self.assertEqual(True, enabled_parameter['required'])

    @gen_test(timeout=120)
    @skip
    def test_plugin_execute(self):
        target = SpiderPluginManager()
        plugin_name = 'test_plugin'
        f_egg = open(TETS_PACKAGE_PATH, 'rb')
        yield target.add_sys_plugin(f_egg, plugin_name)
        saved = target.get_plugin(plugin_name)
        self.assertIsNotNone(saved)
        self.assertEqual(saved.name, plugin_name)
        self.assertEqual(len(saved.parameters), 1)
        parameter = saved.parameters[0]
        self.assertEqual(parameter.key, 'ENABLED')
        self.assertEqual(parameter.datatype,
                         SpiderPluginParameterDatatype.bool)
        self.assertEqual(parameter.required, True)
        self.assertEqual(parameter.default_value, 'True')
<|endoftext|>


<commit_before>"""
Some handy constants for other tests to share and enjoy.
"""

from dbus import PROPERTIES_IFACE

HT_CONTACT = 1
HT_ROOM = 2

CHANNEL = "org.freedesktop.Telepathy.Channel"
CHANNEL_IFACE_GROUP = CHANNEL + ".Interface.Group"
CHANNEL_IFACE_HOLD = CHANNEL + ".Interface.Hold"
CHANNEL_IFACE_MEDIA_SIGNALLING = CHANNEL + ".Interface.MediaSignalling"
CHANNEL_TYPE_TEXT = CHANNEL + ".Type.Text"
CHANNEL_TYPE_TUBES = CHANNEL + ".Type.Tubes"
CHANNEL_IFACE_TUBE = CHANNEL + ".Interface.Tube.DRAFT"
CHANNEL_TYPE_STREAM_TUBE = CHANNEL + ".Type.StreamTube.DRAFT"
CHANNEL_TYPE_DBUS_TUBE = CHANNEL + ".Type.DBusTube.DRAFT"
CHANNEL_TYPE_STREAMED_MEDIA = CHANNEL + ".Type.StreamedMedia"
CHANNEL_TYPE_TEXT = CHANNEL + ".Type.Text"

TP_AWKWARD_PROPERTIES = "org.freedesktop.Telepathy.Properties"
PROPERTY_FLAG_READ = 1
PROPERTY_FLAG_WRITE = 2

CHANNEL_TYPE = CHANNEL + '.ChannelType'
TARGET_HANDLE_TYPE = CHANNEL + '.TargetHandleType'
TARGET_HANDLE = CHANNEL + '.TargetHandle'
TARGET_ID = CHANNEL + '.TargetID'
REQUESTED = CHANNEL + '.Requested'
INITIATOR_HANDLE = CHANNEL + '.InitiatorHandle'
INITIATOR_ID = CHANNEL + '.InitiatorID'
INTERFACES = CHANNEL + '.Interfaces'

CONN = "org.freedesktop.Telepathy.Connection"
CONN_IFACE_CONTACTS = CONN + '.Interface.Contacts'
CONN_IFACE_CONTACT_CAPA = CONN + '.Interface.ContactCapabilities.DRAFT'
CONN_IFACE_REQUESTS = CONN + '.Interface.Requests'

ERROR = 'org.freedesktop.Telepathy.Error'
INVALID_ARGUMENT = ERROR + '.InvalidArgument'
NOT_IMPLEMENTED = ERROR + '.NotImplemented'
NOT_AVAILABLE = ERROR + '.NotAvailable'
PERMISSION_DENIED = ERROR + '.PermissionDenied'

TUBE_PARAMETERS = CHANNEL_IFACE_TUBE + '.Parameters'
TUBE_STATE = CHANNEL_IFACE_TUBE + '.State'
STREAM_TUBE_SERVICE = CHANNEL_TYPE_STREAM_TUBE + '.Service'
DBUS_TUBE_SERVICE_NAME = CHANNEL_TYPE_DBUS_TUBE + '.ServiceName'
DBUS_TUBE_DBUS_NAMES = CHANNEL_TYPE_DBUS_TUBE + '.DBusNames'

TUBE_CHANNEL_STATE_LOCAL_PENDING = 0
TUBE_CHANNEL_STATE_REMOTE_PENDING = 1
TUBE_CHANNEL_STATE_OPEN = 2
TUBE_CHANNEL_STATE_NOT_OFFERED = 3

MEDIA_STREAM_TYPE_AUDIO = 0
MEDIA_STREAM_TYPE_VIDEO = 1

SOCKET_ADDRESS_TYPE_UNIX = 0
SOCKET_ADDRESS_TYPE_ABSTRACT_UNIX = 1
SOCKET_ADDRESS_TYPE_IPV4 = 2
SOCKET_ADDRESS_TYPE_IPV6 = 3

SOCKET_ACCESS_CONTROL_LOCALHOST = 0
SOCKET_ACCESS_CONTROL_PORT = 1
SOCKET_ACCESS_CONTROL_NETMASK = 2
SOCKET_ACCESS_CONTROL_CREDENTIALS = 3

TUBE_STATE_LOCAL_PENDING = 0
TUBE_STATE_REMOTE_PENDING = 1
TUBE_STATE_OPEN = 2
TUBE_STATE_NOT_OFFERED = 3

TUBE_TYPE_DBUS = 0
TUBE_TYPE_STREAM = 1

MEDIA_STREAM_DIRECTION_NONE = 0
MEDIA_STREAM_DIRECTION_SEND = 1
MEDIA_STREAM_DIRECTION_RECEIVE = 2
MEDIA_STREAM_DIRECTION_BIDIRECTIONAL = 3

MEDIA_STREAM_PENDING_LOCAL_SEND = 1
MEDIA_STREAM_PENDING_REMOTE_SEND = 2

MEDIA_STREAM_TYPE_AUDIO = 0
MEDIA_STREAM_TYPE_VIDEO = 1

MEDIA_STREAM_STATE_DISCONNECTED = 0
MEDIA_STREAM_STATE_CONNECTING = 1
MEDIA_STREAM_STATE_CONNECTED = 2

MEDIA_STREAM_DIRECTION_NONE = 0
MEDIA_STREAM_DIRECTION_SEND = 1
MEDIA_STREAM_DIRECTION_RECEIVE = 2
MEDIA_STREAM_DIRECTION_BIDIRECTIONAL = 3
<commit_msg>Add GroupChangeReasons to constants.py<commit_after>"""
Some handy constants for other tests to share and enjoy.
"""

from dbus import PROPERTIES_IFACE

HT_CONTACT = 1
HT_ROOM = 2

CHANNEL = "org.freedesktop.Telepathy.Channel"
CHANNEL_IFACE_GROUP = CHANNEL + ".Interface.Group"
CHANNEL_IFACE_HOLD = CHANNEL + ".Interface.Hold"
CHANNEL_IFACE_MEDIA_SIGNALLING = CHANNEL + ".Interface.MediaSignalling"
CHANNEL_TYPE_TEXT = CHANNEL + ".Type.Text"
CHANNEL_TYPE_TUBES = CHANNEL + ".Type.Tubes"
CHANNEL_IFACE_TUBE = CHANNEL + ".Interface.Tube.DRAFT"
CHANNEL_TYPE_STREAM_TUBE = CHANNEL + ".Type.StreamTube.DRAFT"
CHANNEL_TYPE_DBUS_TUBE = CHANNEL + ".Type.DBusTube.DRAFT"
CHANNEL_TYPE_STREAMED_MEDIA = CHANNEL + ".Type.StreamedMedia"
CHANNEL_TYPE_TEXT = CHANNEL + ".Type.Text"

TP_AWKWARD_PROPERTIES = "org.freedesktop.Telepathy.Properties"
PROPERTY_FLAG_READ = 1
PROPERTY_FLAG_WRITE = 2

CHANNEL_TYPE = CHANNEL + '.ChannelType'
TARGET_HANDLE_TYPE = CHANNEL + '.TargetHandleType'
TARGET_HANDLE = CHANNEL + '.TargetHandle'
TARGET_ID = CHANNEL + '.TargetID'
REQUESTED = CHANNEL + '.Requested'
INITIATOR_HANDLE = CHANNEL + '.InitiatorHandle'
INITIATOR_ID = CHANNEL + '.InitiatorID'
INTERFACES = CHANNEL + '.Interfaces'

CONN = "org.freedesktop.Telepathy.Connection"
CONN_IFACE_CONTACTS = CONN + '.Interface.Contacts'
CONN_IFACE_CONTACT_CAPA = CONN + '.Interface.ContactCapabilities.DRAFT'
CONN_IFACE_REQUESTS = CONN + '.Interface.Requests'

ERROR = 'org.freedesktop.Telepathy.Error'
INVALID_ARGUMENT = ERROR + '.InvalidArgument'
NOT_IMPLEMENTED = ERROR + '.NotImplemented'
NOT_AVAILABLE = ERROR + '.NotAvailable'
PERMISSION_DENIED = ERROR + '.PermissionDenied'

TUBE_PARAMETERS = CHANNEL_IFACE_TUBE + '.Parameters'
TUBE_STATE = CHANNEL_IFACE_TUBE + '.State'
STREAM_TUBE_SERVICE = CHANNEL_TYPE_STREAM_TUBE + '.Service'
DBUS_TUBE_SERVICE_NAME = CHANNEL_TYPE_DBUS_TUBE + '.ServiceName'
DBUS_TUBE_DBUS_NAMES = CHANNEL_TYPE_DBUS_TUBE + '.DBusNames'

TUBE_CHANNEL_STATE_LOCAL_PENDING = 0
TUBE_CHANNEL_STATE_REMOTE_PENDING = 1
TUBE_CHANNEL_STATE_OPEN = 2
TUBE_CHANNEL_STATE_NOT_OFFERED = 3

MEDIA_STREAM_TYPE_AUDIO = 0
MEDIA_STREAM_TYPE_VIDEO = 1

SOCKET_ADDRESS_TYPE_UNIX = 0
SOCKET_ADDRESS_TYPE_ABSTRACT_UNIX = 1
SOCKET_ADDRESS_TYPE_IPV4 = 2
SOCKET_ADDRESS_TYPE_IPV6 = 3

SOCKET_ACCESS_CONTROL_LOCALHOST = 0
SOCKET_ACCESS_CONTROL_PORT = 1
SOCKET_ACCESS_CONTROL_NETMASK = 2
SOCKET_ACCESS_CONTROL_CREDENTIALS = 3

TUBE_STATE_LOCAL_PENDING = 0
TUBE_STATE_REMOTE_PENDING = 1
TUBE_STATE_OPEN = 2
TUBE_STATE_NOT_OFFERED = 3

TUBE_TYPE_DBUS = 0
TUBE_TYPE_STREAM = 1

MEDIA_STREAM_DIRECTION_NONE = 0
MEDIA_STREAM_DIRECTION_SEND = 1
MEDIA_STREAM_DIRECTION_RECEIVE = 2
MEDIA_STREAM_DIRECTION_BIDIRECTIONAL = 3

MEDIA_STREAM_PENDING_LOCAL_SEND = 1
MEDIA_STREAM_PENDING_REMOTE_SEND = 2

MEDIA_STREAM_TYPE_AUDIO = 0
MEDIA_STREAM_TYPE_VIDEO = 1

MEDIA_STREAM_STATE_DISCONNECTED = 0
MEDIA_STREAM_STATE_CONNECTING = 1
MEDIA_STREAM_STATE_CONNECTED = 2

MEDIA_STREAM_DIRECTION_NONE = 0
MEDIA_STREAM_DIRECTION_SEND = 1
MEDIA_STREAM_DIRECTION_RECEIVE = 2
MEDIA_STREAM_DIRECTION_BIDIRECTIONAL = 3

GC_REASON_NONE = 0
GC_REASON_OFFLINE = 1
GC_REASON_KICKED = 2
GC_REASON_BUSY = 3
GC_REASON_INVITED = 4
GC_REASON_BANNED = 5
GC_REASON_ERROR = 6
GC_REASON_INVALID_CONTACT = 7
GC_REASON_NO_ANSWER = 8
GC_REASON_RENAMED = 9
GC_REASON_PERMISSION_DENIED = 10
GC_REASON_SEPARATED = 11
<|endoftext|>


<commit_before># Django settings for ``deploy`` project.
import django.conf.global_settings as DEFAULT_SETTINGS

# Add the parent to the path, to access files in ``../scipy_central/``
import os, sys
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)

DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS
DATABASES = {
    'default': {
        'ENGINE':   '', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME':     '', # Or path to database file if using sqlite3.
        'USER':     '', # Not used with sqlite3.
        'PASSWORD': '', # Not used with sqlite3.
        'HOST':     '', # Set to empty string for localhost. Not used with sqlite3.
        'PORT':     '', # Set to empty string for default. Not used with sqlite3.
    }
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Toronto'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
if DEBUG:
    MEDIA_ROOT = os.path.dirname(__file__) + os.sep + 'media' + os.sep
else:
    # For production: you'll want to copy the <base>/media/* files to your
    # static location and modify this path to match your server.
    MEDIA_ROOT = '<your path here>'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '3h%1b@kab#&f4o!!%8&_(-p@6mqm&(04vc_%*y$h+c$6j-s2rg'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'deploy.urls'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates')),
)

# To get access to some global variables used in the templates
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
    'scipy_central.context_processors.global_template_variables',
	'django.core.context_processors.request',
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    # Humanize some data entries
    'django.contrib.humanize',

    # 3rd party apps:
    'haystack',
    'registration',
    'south',
	"widget_tweaks",

    #  Local apps
    'scipy_central.filestorage',
    'scipy_central.pages',
    'scipy_central.person',
    'scipy_central.submission',
    'scipy_central.tagging',
    'scipy_central.screenshot',
    'scipy_central.pagehit',
)

# Authentication related:
AUTH_PROFILE_MODULE = 'person.UserProfile'
# Link the user is redirected to if not logged in and they try to perform
# a function that only logged in users can do
LOGIN_URL = '/user/login/'

# django-registration required setting
ACCOUNT_ACTIVATION_DAYS = 7
REGISTRATION_OPEN = True    # permit users to create new accounts

# For users that have cookies disabled: sorry, you can't use this site
CSRF_FAILURE_VIEW = 'scipy_central.pages.views.csrf_failure'

# These settings define and modify the behaviour of the entire website.
# SciPy Central = SPC.
SPC = {
    # Delete unconfirmed submission after this number of days
    'unvalidated_subs_deleted_after': ACCOUNT_ACTIVATION_DAYS,

    # We only support Mercurial at the moment. Code can support git and
    # other version control systems in the future.
    # Do not change this once files have been added.
    'revisioning_backend': 'hg',

    # Can be left as '', but then we will search for the executable everytime
    # we need to access the repo. Rather specify the full path to the
    # revision control system executable.
    'revisioning_executable': '',

    # Where should files from each submission be stored?
    # Files are stored using revision control in directories as follows:
    #
    # <storage><submission_primary_key>/<submission_slug>.py
    # <storage><submission_primary_key>/LICENSE.txt
    # where <storage> is the variable defined next, as should always end
    # with ``os.sep``
    #
    # Must end with a trailing ``os.sep`` character
    'storage_dir': MEDIA_ROOT + 'code' + os.sep,

    # Image storage directories. Do not change these settings. They are used
    # in the Sphinx extension to ensure user does not resize image beyond
    # the maximum width or height.
    'raw_image_dir': 'raw-images/%Y%m' + os.sep,
    'resized_image_dir': 'images/%Y%m' + os.sep,

    # Where are ZIP files staged? User's upload ZIP files; only the submission
    # is created, we retrieve the staged ZIP file and handle it appropriately
    # The staged files are then deleted. i.e. this is like a "tempdir"
    #
    'ZIP_staging': MEDIA_ROOT + 'zip-staging',

    # Where should logfiles be written? If DEBUG != True, then you are
    # responsible that this location is valid and exists. Overwrite the
    # location in ``local_settings.py`` below.
    'logfile_location': 'logfile.log',

    # Comments are compiled (using Sphinx) in this location. Again, you are
    # required to sure this location exists for production servers.
    'comment_compile_dir': 'compile',

    # Default name of license file (e.g. 'COPYING.TXT')
    'license_filename': 'LICENSE.TXT',

    # Short link URL root (must end with a trailing slash).
    'short_URL_root': 'http://scpyce.org/',

    # Page hit horizon in days. Lists of views are sorted by the number of page
    # views over the past NNN days (the horizon).
    'hit_horizon': 60,

    # Number of entries per page is search output and table outputs
    'entries_per_page': 20,

    # SciPy Central version
    'version': 0.30,

    # Library submission maximum size (in bytes)
    'library_max_size': 25 * 1024 * 1024,

    # Image (screenshots) maximum size (in bytes)
    'image_max_size': 2 * 1024 * 1024,

    # We will strip out directories from common revision control systems
    # when users upload (ZIP) files
    'common_rcs_dirs': ['.hg', '.git', '.bzr', '.svn',],
}

# All about ``local_settings.py``
# ===============================

# Use ``local_settings.py`` to store variables that you don't want visible to
# revision control systems, or for settings that differ between production and
# development servers.
# The default variables that are expected are listed in the ``ImportError``
# part of the exception below.
this_dir = __file__[0:__file__.find('settings.py')]
try:
    execfile(this_dir + os.sep + 'local_settings.py')
except IOError:
    # See https://docs.djangoproject.com/en/1.3/ref/settings for EMAIL settings
    EMAIL_HOST = ''
    EMAIL_HOST_USER = ''
    EMAIL_HOST_PASSWORD = ''
    # Visitors will receive email from this address e.g. "admin@example.org"
    SERVER_EMAIL = ''
    DEFAULT_FROM_EMAIL = SERVER_EMAIL

    # Where should JQuery be served from?
    JQUERY_URL = 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'
    JQUERYUI_URL = 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js'
    JQUERYUI_CSS = 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.css'

    # If you use Piwik, Google Analytics, etc: add the code snippet here that
    # will be placed as the last entry in the closing </head> tag.
    ANALYTICS_SNIPPET = ''

    # You can also overwrite keys from ``SPC`` in the ``local_settings.py`` file

# Put all the search settings in a single file
execfile(this_dir + os.sep + 'search_settings.py')

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error. See
#
# http://docs.djangoproject.com/en/dev/topics/logging for details
LOGGING = {
    'version': 1,

    'disable_existing_loggers': False,

    'formatters': {
        'verbose': {
            'format': ('%(asctime)s,%(levelname)s,%(filename)s,%(lineno)d,'
                       '[%(funcName)s(...)] : %(message)s')
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },

    'handlers': {
        'null': {
            'level':'DEBUG',
            'class':'django.utils.log.NullHandler',
        },

        'console':{
            'level':'DEBUG',
            'class':'logging.StreamHandler',
            'formatter': 'simple'
        },

        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        },

        'file': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'formatter': 'verbose',
            # Inputs to the ``logging.handlers.RotatingFileHandler`` class
            'filename': SPC['logfile_location'],
        },
    },

    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        'scipycentral': {
            'handlers': ['file', 'mail_admins'],
            'level': 'DEBUG',
            'propagate': True,
        },
    }
}
<commit_msg>DEV: MEDIA_URL to STATIC_URL for serving static files<commit_after># Django settings for ``deploy`` project.
import django.conf.global_settings as DEFAULT_SETTINGS

# Add the parent to the path, to access files in ``../scipy_central/``
import os, sys
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)

DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS
DATABASES = {
    'default': {
        'ENGINE':   '', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME':     '', # Or path to database file if using sqlite3.
        'USER':     '', # Not used with sqlite3.
        'PASSWORD': '', # Not used with sqlite3.
        'HOST':     '', # Set to empty string for localhost. Not used with sqlite3.
        'PORT':     '', # Set to empty string for default. Not used with sqlite3.
    }
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Toronto'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"

MEDIA_ROOT = '<your path here>'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
# Example: "/home/media/media.lawrence.com/media/"
if DEBUG:
    STATIC_ROOT = os.path.dirname(__file__) + os.sep + 'staticfiles' + os.sep
else:
    # For production: you'll want to copy the <base>/static/* files to your
    # static location and modify this path to match your server.
    STATIC_ROOT = '<your path here>'

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'

# Additional locations of static files
STATICFILES_DIRS = (
    os.path.dirname(__file__) + os.sep + 'media' + os.sep,
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '3h%1b@kab#&f4o!!%8&_(-p@6mqm&(04vc_%*y$h+c$6j-s2rg'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'deploy.urls'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates')),
)

# To get access to some global variables used in the templates
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
    'scipy_central.context_processors.global_template_variables',
	'django.core.context_processors.request',
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    # Humanize some data entries
    'django.contrib.humanize',

    # 3rd party apps:
    'haystack',
    'registration',
    'south',
	"widget_tweaks",

    #  Local apps
    'scipy_central.filestorage',
    'scipy_central.pages',
    'scipy_central.person',
    'scipy_central.submission',
    'scipy_central.tagging',
    'scipy_central.screenshot',
    'scipy_central.pagehit',
)

# Authentication related:
AUTH_PROFILE_MODULE = 'person.UserProfile'
# Link the user is redirected to if not logged in and they try to perform
# a function that only logged in users can do
LOGIN_URL = '/user/login/'

# django-registration required setting
ACCOUNT_ACTIVATION_DAYS = 7
REGISTRATION_OPEN = True    # permit users to create new accounts

# For users that have cookies disabled: sorry, you can't use this site
CSRF_FAILURE_VIEW = 'scipy_central.pages.views.csrf_failure'

# These settings define and modify the behaviour of the entire website.
# SciPy Central = SPC.
SPC = {
    # Delete unconfirmed submission after this number of days
    'unvalidated_subs_deleted_after': ACCOUNT_ACTIVATION_DAYS,

    # We only support Mercurial at the moment. Code can support git and
    # other version control systems in the future.
    # Do not change this once files have been added.
    'revisioning_backend': 'hg',

    # Can be left as '', but then we will search for the executable everytime
    # we need to access the repo. Rather specify the full path to the
    # revision control system executable.
    'revisioning_executable': '',

    # Where should files from each submission be stored?
    # Files are stored using revision control in directories as follows:
    #
    # <storage><submission_primary_key>/<submission_slug>.py
    # <storage><submission_primary_key>/LICENSE.txt
    # where <storage> is the variable defined next, as should always end
    # with ``os.sep``
    #
    # Must end with a trailing ``os.sep`` character
    'storage_dir': STATIC_ROOT + 'code' + os.sep,

    # Image storage directories. Do not change these settings. They are used
    # in the Sphinx extension to ensure user does not resize image beyond
    # the maximum width or height.
    'raw_image_dir': 'raw-images/%Y%m' + os.sep,
    'resized_image_dir': 'images/%Y%m' + os.sep,

    # Where are ZIP files staged? User's upload ZIP files; only the submission
    # is created, we retrieve the staged ZIP file and handle it appropriately
    # The staged files are then deleted. i.e. this is like a "tempdir"
    #
    'ZIP_staging': STATIC_ROOT + 'zip-staging',

    # Where should logfiles be written? If DEBUG != True, then you are
    # responsible that this location is valid and exists. Overwrite the
    # location in ``local_settings.py`` below.
    'logfile_location': 'logfile.log',

    # Comments are compiled (using Sphinx) in this location. Again, you are
    # required to sure this location exists for production servers.
    'comment_compile_dir': 'compile',

    # Default name of license file (e.g. 'COPYING.TXT')
    'license_filename': 'LICENSE.TXT',

    # Short link URL root (must end with a trailing slash).
    'short_URL_root': 'http://scpyce.org/',

    # Page hit horizon in days. Lists of views are sorted by the number of page
    # views over the past NNN days (the horizon).
    'hit_horizon': 60,

    # Number of entries per page is search output and table outputs
    'entries_per_page': 20,

    # SciPy Central version
    'version': 0.30,

    # Library submission maximum size (in bytes)
    'library_max_size': 25 * 1024 * 1024,

    # Image (screenshots) maximum size (in bytes)
    'image_max_size': 2 * 1024 * 1024,

    # We will strip out directories from common revision control systems
    # when users upload (ZIP) files
    'common_rcs_dirs': ['.hg', '.git', '.bzr', '.svn',],
}

# All about ``local_settings.py``
# ===============================

# Use ``local_settings.py`` to store variables that you don't want visible to
# revision control systems, or for settings that differ between production and
# development servers.
# The default variables that are expected are listed in the ``ImportError``
# part of the exception below.
this_dir = __file__[0:__file__.find('settings.py')]
try:
    execfile(this_dir + os.sep + 'local_settings.py')
except IOError:
    # See https://docs.djangoproject.com/en/1.3/ref/settings for EMAIL settings
    EMAIL_HOST = ''
    EMAIL_HOST_USER = ''
    EMAIL_HOST_PASSWORD = ''
    # Visitors will receive email from this address e.g. "admin@example.org"
    SERVER_EMAIL = ''
    DEFAULT_FROM_EMAIL = SERVER_EMAIL

    # Where should JQuery be served from?
    JQUERY_URL = 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'
    JQUERYUI_URL = 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js'
    JQUERYUI_CSS = 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.css'

    # If you use Piwik, Google Analytics, etc: add the code snippet here that
    # will be placed as the last entry in the closing </head> tag.
    ANALYTICS_SNIPPET = ''

    # You can also overwrite keys from ``SPC`` in the ``local_settings.py`` file

# Put all the search settings in a single file
execfile(this_dir + os.sep + 'search_settings.py')

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error. See
#
# http://docs.djangoproject.com/en/dev/topics/logging for details
LOGGING = {
    'version': 1,

    'disable_existing_loggers': False,

    'formatters': {
        'verbose': {
            'format': ('%(asctime)s,%(levelname)s,%(filename)s,%(lineno)d,'
                       '[%(funcName)s(...)] : %(message)s')
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },

    'handlers': {
        'null': {
            'level':'DEBUG',
            'class':'django.utils.log.NullHandler',
        },

        'console':{
            'level':'DEBUG',
            'class':'logging.StreamHandler',
            'formatter': 'simple'
        },

        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        },

        'file': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'formatter': 'verbose',
            # Inputs to the ``logging.handlers.RotatingFileHandler`` class
            'filename': SPC['logfile_location'],
        },
    },

    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        'scipycentral': {
            'handlers': ['file', 'mail_admins'],
            'level': 'DEBUG',
            'propagate': True,
        },
    }
}
<|endoftext|>


<commit_before>{
  'target_defaults': {
    'default_configuration': 'Debug',
    'configurations': {
      'Debug': {
        'defines': [ 'DEBUG', '_DEBUG' ],
        'msvs_settings': {
          'VCCLCompilerTool': {
            'RuntimeLibrary': 1, # static debug
          },
        },
      },
      'Release': {
        'defines': [ 'NDEBUG' ],
        'msvs_settings': {
          'VCCLCompilerTool': {
            'RuntimeLibrary': 0, # static release
          },
        },
      }
    },
    'msvs_settings': {
      'VCLinkerTool': {
        'GenerateDebugInformation': 'true',
      },
    },
    'include_dirs': [
      '../libdvbtee/usr/include',
      '../libdvbtee/usr/include/dvbtee',
      '../libdvbtee/usr/include/dvbpsi',
      '../libdvbtee/libdvbtee',
      '../libdvbtee/libdvbtee/decode',
      '../libdvbtee/libdvbtee/decode/table',
      '../libdvbtee/libdvbtee/decode/descriptor',
      '../libdvbtee'
    ],
    'defines': [
      'PIC',
      'HAVE_CONFIG_H',
      'FORCE_DECODER_LINKAGE'
    ],
  },

  'targets': [
    # libdvbtee_parser
    {
      'target_name': 'dvbtee_parser',
      'product_prefix': 'lib',
      'type': 'static_library',
      'sources': [
        '../libdvbtee/libdvbtee/atsctext.cpp',
#       '../libdvbtee/libdvbtee/channels.cpp',
#       '../libdvbtee/libdvbtee/curlhttpget.cpp',
        '../libdvbtee/libdvbtee/decode.cpp',
        '../libdvbtee/libdvbtee/demux.cpp',
#       '../libdvbtee/libdvbtee/feed.cpp',
        '../libdvbtee/libdvbtee/functions.cpp',
#       '../libdvbtee/libdvbtee/hdhr_tuner.cpp',
#       '../libdvbtee/libdvbtee/hlsfeed.cpp',
#       '../libdvbtee/libdvbtee/linuxtv_tuner.cpp',
        '../libdvbtee/libdvbtee/listen.cpp',
        '../libdvbtee/libdvbtee/log.cpp',
#       '../libdvbtee/libdvbtee/output.cpp',
        '../libdvbtee/libdvbtee/parse.cpp',
        '../libdvbtee/libdvbtee/rbuf.cpp',
        '../libdvbtee/libdvbtee/stats.cpp',
#       '../libdvbtee/libdvbtee/tune.cpp',

        '../libdvbtee/libdvbtee/value/value.cpp',
        '../libdvbtee/libdvbtee/value/object.cpp',
        '../libdvbtee/libdvbtee/value/array.cpp',

        '../libdvbtee/libdvbtee/decode/decoder.cpp',
        '../libdvbtee/libdvbtee/decode/table/table.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/descriptor.cpp',

        '../libdvbtee/libdvbtee/decode/table/tabl_00.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_02.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_40.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_42.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_4e.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_70.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_c7.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_c8.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_cb.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_cc.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_cd.cpp',

        '../libdvbtee/libdvbtee/decode/descriptor/desc_0a.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/desc_48.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/desc_4d.cpp',

        '../libdvbtee/libdvbtee/decode/descriptor/desc_62.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/desc_83.cpp',

        '../libdvbtee/libdvbtee/decode/descriptor/desc_81.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/desc_86.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/desc_a0.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/desc_a1.cpp',
      ],
      "dependencies": [
        'libdvbpsi.gyp:dvbpsi'
      ],
      'conditions': [
        ['OS=="mac"',
          {
            'xcode_settings': {
              'GCC_ENABLE_CPP_RTTI': '-frtti'
            }
          }
        ]
      ],
      'cflags_cc!': ['-fno-rtti','-Wunused-variable','-Wdeprecated-declarations'],
      'cflags_cc+': ['-frtti','-Wno-unused-variable','-Wno-deprecated-declarations'],
    },

    # dvbtee command line application
    {
      'target_name': 'dvbteee',
      'type': 'executable',
      'dependencies': [ 'dvbtee_parser' ],
      'sources': [ '../libdvbtee/dvbtee/dvbtee.cpp' ]
    },
  ]
}
<commit_msg>deps/libdvbtee.gyp: dont build listen.cpp<commit_after>{
  'target_defaults': {
    'default_configuration': 'Debug',
    'configurations': {
      'Debug': {
        'defines': [ 'DEBUG', '_DEBUG' ],
        'msvs_settings': {
          'VCCLCompilerTool': {
            'RuntimeLibrary': 1, # static debug
          },
        },
      },
      'Release': {
        'defines': [ 'NDEBUG' ],
        'msvs_settings': {
          'VCCLCompilerTool': {
            'RuntimeLibrary': 0, # static release
          },
        },
      }
    },
    'msvs_settings': {
      'VCLinkerTool': {
        'GenerateDebugInformation': 'true',
      },
    },
    'include_dirs': [
      '../libdvbtee/usr/include',
      '../libdvbtee/usr/include/dvbtee',
      '../libdvbtee/usr/include/dvbpsi',
      '../libdvbtee/libdvbtee',
      '../libdvbtee/libdvbtee/decode',
      '../libdvbtee/libdvbtee/decode/table',
      '../libdvbtee/libdvbtee/decode/descriptor',
      '../libdvbtee'
    ],
    'defines': [
      'PIC',
      'HAVE_CONFIG_H',
      'FORCE_DECODER_LINKAGE'
    ],
  },

  'targets': [
    # libdvbtee_parser
    {
      'target_name': 'dvbtee_parser',
      'product_prefix': 'lib',
      'type': 'static_library',
      'sources': [
        '../libdvbtee/libdvbtee/atsctext.cpp',
#       '../libdvbtee/libdvbtee/channels.cpp',
#       '../libdvbtee/libdvbtee/curlhttpget.cpp',
        '../libdvbtee/libdvbtee/decode.cpp',
        '../libdvbtee/libdvbtee/demux.cpp',
#       '../libdvbtee/libdvbtee/feed.cpp',
        '../libdvbtee/libdvbtee/functions.cpp',
#       '../libdvbtee/libdvbtee/hdhr_tuner.cpp',
#       '../libdvbtee/libdvbtee/hlsfeed.cpp',
#       '../libdvbtee/libdvbtee/linuxtv_tuner.cpp',
#       '../libdvbtee/libdvbtee/listen.cpp',
        '../libdvbtee/libdvbtee/log.cpp',
#       '../libdvbtee/libdvbtee/output.cpp',
        '../libdvbtee/libdvbtee/parse.cpp',
        '../libdvbtee/libdvbtee/rbuf.cpp',
        '../libdvbtee/libdvbtee/stats.cpp',
#       '../libdvbtee/libdvbtee/tune.cpp',

        '../libdvbtee/libdvbtee/value/value.cpp',
        '../libdvbtee/libdvbtee/value/object.cpp',
        '../libdvbtee/libdvbtee/value/array.cpp',

        '../libdvbtee/libdvbtee/decode/decoder.cpp',
        '../libdvbtee/libdvbtee/decode/table/table.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/descriptor.cpp',

        '../libdvbtee/libdvbtee/decode/table/tabl_00.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_02.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_40.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_42.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_4e.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_70.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_c7.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_c8.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_cb.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_cc.cpp',
        '../libdvbtee/libdvbtee/decode/table/tabl_cd.cpp',

        '../libdvbtee/libdvbtee/decode/descriptor/desc_0a.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/desc_48.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/desc_4d.cpp',

        '../libdvbtee/libdvbtee/decode/descriptor/desc_62.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/desc_83.cpp',

        '../libdvbtee/libdvbtee/decode/descriptor/desc_81.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/desc_86.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/desc_a0.cpp',
        '../libdvbtee/libdvbtee/decode/descriptor/desc_a1.cpp',
      ],
      "dependencies": [
        'libdvbpsi.gyp:dvbpsi'
      ],
      'conditions': [
        ['OS=="mac"',
          {
            'xcode_settings': {
              'GCC_ENABLE_CPP_RTTI': '-frtti'
            }
          }
        ]
      ],
      'cflags_cc!': ['-fno-rtti','-Wunused-variable','-Wdeprecated-declarations'],
      'cflags_cc+': ['-frtti','-Wno-unused-variable','-Wno-deprecated-declarations'],
    },

    # dvbtee command line application
    {
      'target_name': 'dvbteee',
      'type': 'executable',
      'dependencies': [ 'dvbtee_parser' ],
      'sources': [ '../libdvbtee/dvbtee/dvbtee.cpp' ]
    },
  ]
}
<|endoftext|>


<commit_before>#!/usr/bin/env python3

import enforce

import scipy as sp
import numpy as np
import math

@enforce.runtime_validation
def get_rotator(A, i: int, j: int, k: int):
    G = np.eye(A.shape[0])
    r = np.sqrt(A[i, k] ** 2 + A[j, k] ** 2)
    if r != 0 and A[j, k] != 0:
        G[i, i] = A[i, k] / r
        G[i, j] = A[j, k] / r
        G[j, i] = - A[j, k] / r
        G[j, j] = A[i, k] / r
    return G

@enforce.runtime_validation
def qr_givens(A):
    Q = np.eye(A.shape[0])
    for j in range(A.shape[0] - 1):
        G = np.eye(A.shape[0])
        for i in reversed(range(j, A.shape[0] - 1)):
            G = get_rotator(A, i, i + 1, j) @ G
        Q = Q @ np.transpose(G)
        A = G @ A
    return (Q, A)

def main() -> None:

    A = np.array([[1,1,0],
                  [-1,0,1],
                  [0,1,1],
                  [0,0,1]])
    A.shape[0]
    [Q, R] = qr_givens(A)

    print("A =", np.round(A, decimals=2),  '\n', sep='\n')
    print("Q =", np.round(Q, decimals=2),  '\n', sep='\n')
    print("R =", np.round(R, decimals=2),  '\n', sep='\n')
    print("Q @ R =", np.round(Q @ R, decimals=2), '\n', sep='\n')

if __name__ == '__main__':
    main()
<commit_msg>Minor improvements<commit_after>#!/usr/bin/env python3

import enforce

import scipy as sp
import numpy as np
import math

@enforce.runtime_validation
def rotator(A, i: int, j: int, k: int):
    G = np.eye(A.shape[0])
    r = np.sqrt(A[i, k] ** 2 + A[j, k] ** 2)
    if r != 0 and A[j, k] != 0:
        G[i, i] = A[i, k] / r
        G[i, j] = A[j, k] / r
        G[j, i] = - A[j, k] / r
        G[j, j] = A[i, k] / r
    return G

@enforce.runtime_validation
def qr_givens(A):
    Q = np.eye(A.shape[0])
    for j in range(A.shape[1]):
        G = np.eye(A.shape[0])
        for i in reversed(range(j, A.shape[1])):
            G = rotator(A, i, i + 1, j) @ G
        Q = Q @ np.transpose(G)
        A = G @ A
    return (Q, A)

def main() -> None:

    A = np.array([[1,1,0],
                  [-1,0,1],
                  [0,1,1],
                  [0,0,1]])

    [Q, R] = qr_givens(A)

    print("A =", np.round(A, decimals=2),  '\n', sep='\n')
    print("Q =", np.round(Q, decimals=2),  '\n', sep='\n')
    print("R =", np.round(R, decimals=2),  '\n', sep='\n')
    print("Q @ R =", np.round(Q @ R, decimals=2), '\n', sep='\n')

if __name__ == '__main__':
    main()
<|endoftext|>


<commit_before>#
# Copyright 2015 LinkedIn Corp. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#

import json
import csv, sys
from org.slf4j import LoggerFactory
from wherehows.common.writers import FileWriter
from wherehows.common.schemas import DatasetSchemaRecord, DatasetFieldRecord
from AvroColumnParser import AvroColumnParser

from org.python.core import codecs
codecs.setDefaultEncoding('utf-8')

class HBaseTransform:
  def __init__(this):
        this.logger = LoggerFactory.getLogger('jython script : ' + this.__class__.__name__)

  def transform(this, raw_metadata, metadata_output, field_metadata_output):
    input_json_file = open(raw_metadata, 'r')
    schema_file_writer = FileWriter(metadata_output)
    field_file_writer = FileWriter(field_metadata_output)
    i=0
    this.sort_id = 0
    o_urn = ''
    for line in input_json_file:
      try:
        j = json.loads(line)
      except:
        this.logger.error("   Invalid JSON:\n%s" % line)
        continue
      i += 1
      o_field_list_ = []
      this.sort_id = 0
      if not j.has_key('attributes'):
        o_properties = {"doc": null}
      else:
        o_properties = dict(j['attributes'].items())
        del j['attributes']
      if j.has_key('uri'):
        o_urn = j['uri']
        o_name = o_urn[o_urn.rfind('/') + 1:]
        o_source = 'Hbase'
      else:
        this.logger.info('*** Warning: "uri" is not found in %s' % j['name'])
        o_urn = ''
        o_name = ''
      if not j.has_key('fields'):
        o_fields = {"doc": None}
      else:
        o_fields = {}
        for f in j['fields']:
          o_field_name = f['name']
          o_fields[o_field_name] = dict(f)
        acp = AvroColumnParser(j, o_urn)
        o_field_list_ += acp.get_column_list_result()
      dataset_schema_record = DatasetSchemaRecord(o_name, json.dumps(j, sort_keys=True),
                                                  json.dumps(o_properties, sort_keys=True), json.dumps(o_fields), o_urn,
                                                  o_source, None, None, None)
      schema_file_writer.append(dataset_schema_record)
      for fields in o_field_list_:
        field_record = DatasetFieldRecord(fields)
        field_file_writer.append(field_record)

    field_file_writer.close()
    schema_file_writer.close()
    input_json_file.close()

if __name__ == "__main__":
  args = sys.argv[1]
# parse the arguments and do transformation.
  t = HBaseTransform()
  t.transform("/var/tmp/wherehows/hbase_raw_meta","/var/tmp/wherehows/hbase_meta",
              "/var/tmp/wherehows/hbase_field_meta")
<commit_msg>hbase web display info bug repair<commit_after>#
# Copyright 2015 LinkedIn Corp. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#

import json
import csv, sys
from org.slf4j import LoggerFactory
from wherehows.common.writers import FileWriter
from wherehows.common.schemas import DatasetSchemaRecord, DatasetFieldRecord
from AvroColumnParser import AvroColumnParser

from org.python.core import codecs
codecs.setDefaultEncoding('utf-8')

class HBaseTransform:
  def __init__(this):
        this.logger = LoggerFactory.getLogger('jython script : ' + this.__class__.__name__)

  def transform(this, raw_metadata, metadata_output, field_metadata_output):
    input_json_file = open(raw_metadata, 'r')
    schema_file_writer = FileWriter(metadata_output)
    field_file_writer = FileWriter(field_metadata_output)
    i=0
    this.sort_id = 0
    o_urn = ''
    for line in input_json_file:
      try:
        j = json.loads(line)
      except:
        this.logger.error("   Invalid JSON:\n%s" % line)
        continue
      i += 1
      o_field_list_ = []
      this.sort_id = 0
      if not j.has_key('attributes'):
        o_properties = {"doc": null}
      else:
        o_properties = dict(j['attributes'].items())
        del j['attributes']
      if j.has_key('uri'):
        o_urn = j['uri']
        o_name = o_urn[o_urn.rfind('/') + 1:]
        o_source = 'Hbase'
      else:
        this.logger.info('*** Warning: "uri" is not found in %s' % j['name'])
        o_urn = ''
        o_name = ''
      if not j.has_key('fields'):
        o_fields = {"doc": None}
      else:
        o_fields = {}
        for f in j['fields']:
          o_field_name = f['name']
          o_fields[o_field_name] = dict(f)
        acp = AvroColumnParser(j, o_urn)
        o_field_list_ += acp.get_column_list_result()
      dataset_schema_record = DatasetSchemaRecord(o_name, json.dumps(j, sort_keys=True),
                                                  json.dumps(o_properties, sort_keys=True), json.dumps(o_fields), o_urn,
                                                  o_source, 'HBase', 'Table', None,None,None)
      schema_file_writer.append(dataset_schema_record)
      for fields in o_field_list_:
        field_record = DatasetFieldRecord(fields)
        field_file_writer.append(field_record)

    field_file_writer.close()
    schema_file_writer.close()
    input_json_file.close()

if __name__ == "__main__":
  args = sys.argv[1]
# parse the arguments and do transformation.
  t = HBaseTransform()
  t.transform("/var/tmp/wherehows/hbase_raw_meta","/var/tmp/wherehows/hbase_meta",
              "/var/tmp/wherehows/hbase_field_meta")
<|endoftext|>