Exemplo n.º 1
0
    def test_nqueries(self):
        from amcat.tools import amcatlogging
        amcatlogging.setup()

        codebook, codes = amcattest.create_test_codebook_with_codes()
        schema, codebook, strf, intf, codef = amcattest.create_test_schema_with_fields(codebook=codebook)
        job = amcattest.create_test_job(unitschema=schema, articleschema=schema, narticles=7)
        articles = list(job.articleset.articles.all())
        
        amcattest.create_test_coding(codingjob=job, article=articles[0]).update_values({strf:"bla", intf:1, codef:codes["A1b"]})
        amcattest.create_test_coding(codingjob=job, article=articles[1]).update_values({strf:"bla", intf:1, codef:codes["A1b"]})
        amcattest.create_test_coding(codingjob=job, article=articles[2]).update_values({strf:"bla", intf:1, codef:codes["A1b"]})
        amcattest.create_test_coding(codingjob=job, article=articles[3]).update_values({strf:"bla", intf:1, codef:codes["A1b"]})
        amcattest.create_test_coding(codingjob=job, article=articles[4]).update_values({strf:"bla", intf:1, codef:codes["A1b"]})                        

        codingjobs = list(CodingJob.objects.filter(pk__in=[job.id]))
        c = codingjobs[0].codings.all()[0]
        amcatlogging.debug_module('django.db.backends')

        script = self._get_results_script([job], {strf : {}, intf : {}})
        with self.checkMaxQueries(5):
            list(csv.reader(StringIO(script.run())))


        script = self._get_results_script([job], {strf : {}, intf : {}, codef : dict(ids=True)})
        with self.checkMaxQueries(5):
            list(csv.reader(StringIO(script.run())))


        script = self._get_results_script([job], {strf : {}, intf : {}, codef : dict(labels=True)})
        with self.checkMaxQueries(5):
            list(csv.reader(StringIO(script.run())))
Exemplo n.º 2
0
Arquivo: cli.py Projeto: edisona/amcat
def run_cli(cls=None, handle_output=None, get_script_depth=2):
    """Handle command line interface invocation of this script"""
    amcatlogging.setup()

    if cls is None: cls = get_script(get_script_depth)

    if handle_output is None:
        handle_output = cls.output_type != None

    parser = argument_parser_from_script(cls)
    args = parser.parse_args()
    options = args.__dict__

    if options.pop("verbose", None):
        amcatlogging.debug_module(cls.__module__)

    instance = cls(options)

    input = None
    if cls.input_type in (file, str, unicode):
        input = sys.stdin
    if cls.input_type in (str, unicode):
        input = input.read()
    if cls.input_type == unicode:
        encoding = chardet.detect(input)["encoding"]
        log.info("Using encoding {encoding}".format(**locals()))
        input = input.decode(encoding)

    out = instance.run(input)

    if handle_output:
        out = handleOutput(out, instance.output_type)
    return out
Exemplo n.º 3
0
    def test_nqueries(self):
        from amcat.tools import amcatlogging
        amcatlogging.setup()

        codebook, codes = amcattest.create_test_codebook_with_codes()
        schema, codebook, strf, intf, codef = amcattest.create_test_schema_with_fields(codebook=codebook)
        job = amcattest.create_test_job(unitschema=schema, articleschema=schema, narticles=7)
        articles = list(job.articleset.articles.all())

        log.info(codes)
        amcattest.create_test_coding(codingjob=job, article=articles[0]).update_values({strf:"bla", intf:1, codef:codes["A1b"].id})
        amcattest.create_test_coding(codingjob=job, article=articles[1]).update_values({strf:"bla", intf:1, codef:codes["A1b"].id})
        amcattest.create_test_coding(codingjob=job, article=articles[2]).update_values({strf:"bla", intf:1, codef:codes["A1b"].id})
        amcattest.create_test_coding(codingjob=job, article=articles[3]).update_values({strf:"bla", intf:1, codef:codes["A1b"].id})
        amcattest.create_test_coding(codingjob=job, article=articles[4]).update_values({strf:"bla", intf:1, codef:codes["A1b"].id})

        codingjobs = list(CodingJob.objects.filter(pk__in=[job.id]))
        c = list(codingjobs[0].codings)[0]
        amcatlogging.debug_module('django.db.backends')

        script = self._get_results_script([job], {strf : {}, intf : {}})
        with self.checkMaxQueries(8):
            list(csv.reader(StringIO(script.run())))


        script = self._get_results_script([job], {strf : {}, intf : {}, codef : dict(ids=True)})
        with self.checkMaxQueries(8):
            list(csv.reader(StringIO(script.run())))


        script = self._get_results_script([job], {strf : {}, intf : {}, codef : dict(labels=True)})
        with self.checkMaxQueries(8):
            list(csv.reader(StringIO(script.run())))
Exemplo n.º 4
0
def run_test():
    """
    for some reason, django testing gets in the way of creating users
    (the call succeeds, but can't log on with the credentials)
    running the same code from the command line does work
    this might be connected with http://code.google.com/p/amcat/issues/detail?id=49
    run with python -c "from amcat.tools import dbtoolkit; dbtoolkit.run_test()"
    """
    from amcat.tools.amcatlogging import setup
    setup()

    class Dummy(TestDBToolkit):
        """Dummy class for testing externally"""
        def __init__(self):
            pass

        def assertTrue(self, test):
            if not test:
                raise Exception("%r is not True" % test)

        def assertFalse(self, test):
            self.assertTrue(not test)

    TestDBToolkit.x_test_users_passwords(Dummy())
Exemplo n.º 5
0
            format(**locals()))
        for listener in self.listeners:
            listener(self)

    def add_listener(self, func):
        self.listeners.append(func)

    def remove_listener(self, func):
        self.listeners.remove(func)


class NullMonitor(ProgressMonitor):
    def update(self, *args, **kargs):
        pass


if __name__ == '__main__':
    from amcat.tools import amcatlogging
    from django.conf import settings
    amcatlogging.setup()
    p = ProgressMonitor()

    def listen(pm):
        print(pm.percent, pm.message)

    p.add_listener(listen)
    p.update(15, "bezig")
    p.update(15, "nog steeds")
    p.remove_listener(listen)
    p.update(10, 'Ja')
Exemplo n.º 6
0
WWWCOVERAGEDEST = '{wwwroot}/cov_{reponame}_{branch}.txt'

CWD = "{tmpdir}/amcat"
TESTCMD = (
    "PYTHONPATH={tmpdir} DJANGO_SETTINGS_MODULE=amcat.settings python-coverage run"
    + " manage.py test --noinput {testapp}")
COVERAGECMD = "python-coverage report --omit=/usr"

if len(sys.argv) > 1:
    outdir = sys.argv[1]
    wwwroot = 'file://{outdir}'.format(**locals())
else:
    outdir = OUTDIR_DEFAULT
    wwwroot = WWWROOT_DEFAULT

log = amcatlogging.setup()

if not os.path.exists(outdir): os.makedirs(outdir)  # make sure target exists

script = sys.argv[0]
log.info("Starting documentation by {script} at {stamp}".format(**locals()))

doc = table3.ObjectTable()
test = table3.ObjectTable()

for reponame in REPONAMES:
    repolocation = REPOLOC.format(**locals())
    # clone repositorymkdtemp
    tmpdir = tempfile.mkdtemp()
    repodir = '{tmpdir}/{reponame}'.format(**locals())
    log.info(
Exemplo n.º 7
0
        self.do_update()

    def do_update(self):
        self.percent = int(100. * self.worked / self.total)
        log.info("[{self.percent}%] {self.worked} / {self.total} {self.message!r}".format(**locals()))
        for listener in self.listeners:
            listener(self)

    def add_listener(self, func):
        self.listeners.append(func)

    def remove_listener(self, func):
        self.listeners.remove(func)

class NullMonitor(ProgressMonitor):
    def update(self, *args, **kargs):
        pass

if __name__ == '__main__':
    from amcat.tools import amcatlogging
    from django.conf import settings
    amcatlogging.setup()
    p = ProgressMonitor()
    def listen(pm):
        print (pm.percent, pm.message)
    p.add_listener(listen)
    p.update(15, "bezig")
    p.update(15, "nog steeds")
    p.remove_listener(listen)
    p.update(10, 'Ja')