Example #1
0
def setup_env():
    dirpath = tempfile.mkdtemp()

    temp_path = op.join(dirpath, 'temp.pl')
    output_path = op.join(dirpath, 'out.txt')
    code_path = op.join(dirpath, 'code.pl')
    return temp_path, output_path, code_path, dirpath
def test__fix_history_tz():

    with tempfile.TemporaryDirectory() as cachedir:

        iw = IssueWrapperMock()
        cachedir = tempfile.mkdtemp()
        hw = HistoryWrapper(iw, cachedir=cachedir, usecache=False)

        events = [
            {
                'created_at': datetime.datetime.now()
            },
            {
                'created_at': pytz.utc.localize(datetime.datetime.now())
            },
            {
                'created_at': '2019-08-01T19:00:00'
            },
            {
                'created_at': '2019-08-01T19:00:00Z'
            },
            {
                'created_at': '2019-08-01T19:00:00+00:00'
            },
        ]

        fixed = hw._fix_history_tz(events)
        for event in fixed:
            assert hasattr(event['created_at'], 'tzinfo')
            assert event['created_at'].tzinfo is not None
def test_ignore_events_without_dates_on_last_methods():

    # With the addition of timeline events, we have a lot
    # of missing keys that we would normally get from the
    # events endpoint. This test asserts that the historywrapper
    # filters those timeline events out when the necessary
    # keys are missing

    # iw.history.label_last_applied(u'needs_info')
    # iw.history.label_last_removed(u'needs_info')
    # iw.history.last_date_for_boilerplate(u'needs_info_base')
    # iw.history.last_date_for_boilerplate(u'issue_missing_data')

    events = [
        [u'labeled', True, u'bcoca', u'needs_info'],
        [u'labeled', None, u'bcoca', u'needs_info'],
        [
            u'comment', True, u'ansibot',
            u'foobar\n<!--- boilerplate: needs_info --->'
        ],
        [
            u'comment', None, u'ansibot',
            u'foobar\n<!--- boilerplate: needs_info --->'
        ],
        [u'labeled', True, u'ansibot', u'needs_info'],
        [u'labeled', None, u'ansibot', u'needs_info'],
        [u'comment', True, u'jimi-c', u'unicorns are awesome'],
        [u'comment', None, u'jimi-c', u'unicorns are awesome'],
        [u'unlabeled', True, u'ansibot', u'needs_info'],
        [u'unlabeled', None, u'ansibot', u'needs_info'],
    ]

    iw = IssueWrapperMock()
    for event in events:
        if event[0] in [u'labeled', u'unlabeled']:
            levent = LabelEventMock(event[0], event[2], label=event[3])
            if event[1] is None:
                levent._created_at = None
            iw._events.append(levent)

        if event[0] == u'comment':
            thiscomment = CommentMock(event[2], event[3])
            if event[1] is None:
                thiscomment.date = None
            iw._comments.append(thiscomment)

    cachedir = tempfile.mkdtemp()
    hw = HistoryWrapper(iw, cachedir=cachedir, usecache=False)

    res = []
    res.append(hw.label_last_applied(u'needs_info'))
    res.append(hw.label_last_removed(u'needs_info'))
    res.append(hw.last_date_for_boilerplate(u'needs_info'))
    res.append(hw.was_labeled(u'needs_info'))
    res.append(hw.was_unlabeled(u'needs_info'))

    assert not [x for x in res if x is None]
Example #4
0
def main():
    options = parseOptions(sys.argv[1:])
    print(
        compareLevel(
            options.jsengine,
            options.flags,
            options.infilename,  # pylint: disable=no-member
            Path(tempfile.mkdtemp("compare_jitmain")),
            options,
            True,
            False)[0])
def test_get_component_commands():
    iw = IssueWrapperMock()

    iw._comments = [CommentMock('jimi-c', '!component =lib/ansible/unicorns')]

    cachedir = tempfile.mkdtemp()
    hw = HistoryWrapper(iw, cachedir=cachedir, usecache=False)

    events = hw._find_events_by_actor('commented', None)
    ccommands = hw.get_component_commands(botnames=[])

    assert len(events) > 0
    assert len(ccommands) > 0
Example #6
0
def main(args):
    args = get_args(args)
    failed = False
    try:
        pdf_as_img_dir_path = tempfile.mkdtemp()
        half_imgs_dir_path = tempfile.mkdtemp()
        img_crop_dir_path = tempfile.mkdtemp()
        img_resize_dir_path = tempfile.mkdtemp()
        return process_pdf(args.filename, args.input_location,
                           args.output_location, args.mode,
                           pdf_as_img_dir_path, half_imgs_dir_path,
                           img_crop_dir_path, img_resize_dir_path)
    except Exception as err:
        logger.error("split_pdf.py failed!")
        logger.error(err)
        failed = True
    finally:
        # delete all the temp files before leaving
        shutil.rmtree(pdf_as_img_dir_path)
        shutil.rmtree(half_imgs_dir_path)
        shutil.rmtree(img_crop_dir_path)
        shutil.rmtree(img_resize_dir_path)
        if failed:
            exit(-1)
    def __init__(self):
        self.venvDir = None
        self.venv = None

        try:
            self.venvDir = tempfile.mkdtemp()
            LOG.info("Created virtual env dir: %s", self.venvDir)
        except Exception as e:
            LOG.exception("Exception during virtual env directory create: %s",
                          e.message)

        if not os.path.exists(self.venvDir):
            LOG.error("Failed to create virtual env dir: %s. Exiting",
                      self.venvDir)
            return

        # create virtual env
        self.venv = VirtualEnvironment(self.venvDir)
Example #8
0
def test_get_component_commands():
    iw = IssueWrapperMock()

    iw._comments = [{
        u'id': 1,
        u'actor': u'jimi-c',
        u'body': '!component =lib/ansible/unicorns',
        u'event': u'commented',
        u'created_at': datetime.datetime.utcnow(),
    }]
    iw._events = iw._comments

    cachedir = tempfile.mkdtemp()
    hw = HistoryWrapper(iw, cachedir=cachedir, usecache=False)
    hw.BOTNAMES = []

    events = hw._find_events_by_actor('commented', None)
    ccommands = hw.get_component_commands()

    assert len(events) > 0
    assert len(ccommands) > 0
Example #9
0
def download_vols(ids, output_dir=None):
    # If no explicit output directory is specified, just create a temporary one
    if output_dir is None:
        output_dir = tempfile.mkdtemp()

    if 'volume_id' in ids:
        ids.remove('volume_id')

    # Download extracted features
    paths = {id: '{}/{}.json.bz2'.format(output_dir, id) for id in ids}
    try:
        download_file(htids=ids, outdir=output_dir)
    except subprocess.CalledProcessError:
        missing = [id for id, p in paths.items() if not os.path.exists(p)]
        with open('error_missing.log', 'w') as outfile:
            outfile.write('\n'.join(missing))
        
        print("{} volume{} failed to download. "
              "See `error_missing.log`.".format(len(missing), 's' if len(missing) > 1 else ''))
        print("Continuing with volumes that succesfully downloaded...")
    
    paths = [p for id, p in paths.items() if os.path.exists(p)]
    return paths
Example #10
0
def download_vols(ids, output_dir=None):
    # If no explicit output directory is specified, just create a temporary one
    if output_dir is None:
        output_dir = tempfile.mkdtemp()

    if 'volume_id' in ids:
        ids.remove('volume_id')

    # Download extracted features
    paths = {id: '{}/{}.json.bz2'.format(output_dir, id) for id in ids}
    try:
        download_file(htids=ids, outdir=output_dir)
    except subprocess.CalledProcessError:
        missing = [id for id, p in paths.items() if not os.path.exists(p)]
        with open('error_missing.log', 'w') as outfile:
            outfile.write('\n'.join(missing))

        print("{} volume{} failed to download. "
              "See `error_missing.log`.".format(
                  len(missing), 's' if len(missing) > 1 else ''))
        print("Continuing with volumes that succesfully downloaded...")

    paths = [p for id, p in paths.items() if os.path.exists(p)]
    return paths
Example #11
0
 def setUp(self):
     self.directory = mkdtemp()
     self._orig_cwd = os.getcwd()
     self.create_working_directory(self.directory)
Example #12
0
def get_temp_dir():
    return tempfile.mkdtemp()
Example #13
0
def test_ignore_events_without_dates_on_last_methods():
    """With the addition of timeline events, we have a lot
    of missing keys that we would normally get from the 
    events endpoint. This test asserts that the historywrapper
    filters those timeline events out when the necessary
    keys are missing."""

    events = [
        {
            u'event': u'labeled',
            u'created_at': datetime.datetime.utcnow(),
            u'actor': u'bcoca',
            u'label': u'needs_info'
        },
        {
            u'event': u'labeled',
            u'created_at': datetime.datetime.utcnow(),
            u'actor': u'bcoca',
            u'label': u'needs_info'
        },
        {
            u'event': u'comment',
            u'created_at': datetime.datetime.utcnow(),
            u'actor': u'ansibot',
            u'body': u'foobar\n<!--- boilerplate: needs_info --->'
        },
        {
            u'event': u'comment',
            u'actor': u'ansibot',
            u'body': u'foobar\n<!--- boilerplate: needs_info --->'
        },
        {
            u'event': u'labeled',
            u'created_at': datetime.datetime.utcnow(),
            u'actor': u'ansibot',
            u'label': u'needs_info'
        },
        {
            u'event': u'labeled',
            u'actor': u'ansibot',
            u'label': u'needs_info'
        },
        {
            u'event': u'comment',
            u'created_at': datetime.datetime.utcnow(),
            u'actor': u'jimi-c',
            u'body': u'unicorns are awesome'
        },
        {
            u'event': u'comment',
            u'actor': u'jimi-c',
            u'body': u'unicorns are awesome'
        },
        {
            u'event': u'unlabeled',
            u'created_at': datetime.datetime.utcnow(),
            u'actor': u'ansibot',
            u'label': u'needs_info'
        },
        {
            u'event': u'unlabeled',
            u'actor': u'ansibot',
            u'label': u'needs_info'
        },
    ]

    iw = IssueWrapperMock()
    for event in events:
        if event[u'event'] == u'comment':
            iw._comments.append(event)
        iw._events.append(event)

    cachedir = tempfile.mkdtemp()
    hw = HistoryWrapper(iw, cachedir=cachedir, usecache=False)
    hw.BOTNAMES = ['ansibot']

    res = []
    res.append(hw.label_last_applied(u'needs_info'))
    res.append(hw.label_last_removed(u'needs_info'))
    res.append(hw.last_date_for_boilerplate(u'needs_info'))
    res.append(hw.was_labeled(u'needs_info'))
    res.append(hw.was_unlabeled(u'needs_info'))

    assert not [x for x in res if x is None]