예제 #1
0
    def test_init(self):
        with self.assertRaises(TypeError):
            OrderedDict([('a', 1), ('b', 2)], None)  # too many args
        pairs = [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]
        self.assertEqual(sorted(OrderedDict(dict(pairs)).items()),
                         pairs)  # dict input
        self.assertEqual(sorted(OrderedDict(**dict(pairs)).items()),
                         pairs)  # kwds input
        self.assertEqual(list(OrderedDict(pairs).items()),
                         pairs)  # pairs input
        self.assertEqual(
            list(
                OrderedDict([('a', 1), ('b', 2), ('c', 9), ('d', 4)], c=3,
                            e=5).items()), pairs)  # mixed input

        # make sure no positional args conflict with possible kwdargs
        self.assertEqual(
            inspect.getargspec(OrderedDict.__dict__['__init__']).args,
            ['self'])

        # Make sure that direct calls to __init__ do not clear previous contents
        d = OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 44), ('e', 55)])
        d.__init__([('e', 5), ('f', 6)], g=7, d=4)
        self.assertEqual(list(d.items()), [('a', 1), ('b', 2), ('c', 3),
                                           ('d', 4), ('e', 5), ('f', 6),
                                           ('g', 7)])
def qqvideo(vid):
    #html = _http(self.url)
    #vid = re.compile(r'vid:"([^"]+)"').search(html).group(1)
    vid = 'c001640aimv'
    murl = 'http://vv.video.qq.com/'
    #vinfo = _http('%sgetvinfo?otype=json&vids=%s&platform=70202&utype=-1&appver=3.2.19.325'% (murl, vid) + '&ehost=http%3a%2f%2fcache.tv.qq.com%2fqqplayerout.swf%3fvid%3dc001640aimv' )
    vinfo = _http('%sgetinfo?otype=json&vids=%s&defaultfmt=fhd'% (murl, vid))
    infoj = json.loads(vinfo.split('=')[1][:-1])
    qtyps = OrderedDict((
        ('1080P', 'fhd'), ('超清', 'shd'), ('高清', 'hd'), ('标清', 'sd')))
    vtyps = {v['name']:v['id'] for v in infoj['fl']['fi']}
    qtypid = vtyps['sd']
    sels = [k for k,v in qtyps.iteritems() if v in vtyps]
    #sel = dialog.select('清晰度', sels)
    sel = 0
    surls = []
    urlpre = infoj['vl']['vi'][0]['ul']['ui'][-1]['url']
    if sel is not -1:
        qtypid = vtyps[qtyps[sels[sel]]]
    for i in range(1, int(infoj['vl']['vi'][0]['cl']['fc'])):
        fn = '%s.p%s.%s.mp4' % (vid, qtypid%10000, str(i))
        sinfo = _http(
                '{0}getkey?format={1}&filename={2}&vid={3}&otype=json'.format(
                        murl, qtypid, fn, vid))
        skey = json.loads(sinfo.split('=')[1][:-1])['key']
        surl = urllib2.urlopen(
                '%s%s?vkey=%s' % (urlpre, fn, skey), timeout=30).geturl()
        if not surl: break
        surls.append(surl)
        movurl = 'stack://{0}'.format(' , '.join(surls))
        return movurl
예제 #3
0
 def test_reduce_not_too_fat(self):
     # do not save instance dictionary if not needed
     pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
     od = OrderedDict(pairs)
     self.assertEqual(len(od.__reduce__()), 2)
     od.x = 10
     self.assertEqual(len(od.__reduce__()), 3)
 def test_clear(self):
     pairs = [("c", 1), ("b", 2), ("a", 3), ("d", 4), ("e", 5), ("f", 6)]
     shuffle(pairs)
     od = OrderedDict(pairs)
     self.assertEqual(len(od), len(pairs))
     od.clear()
     self.assertEqual(len(od), 0)
 def test_reduce_not_too_fat(self):
     # do not save instance dictionary if not needed
     pairs = [("c", 1), ("b", 2), ("a", 3), ("d", 4), ("e", 5), ("f", 6)]
     od = OrderedDict(pairs)
     self.assertEqual(len(od.__reduce__()), 2)
     od.x = 10
     self.assertEqual(len(od.__reduce__()), 3)
예제 #6
0
 def test_clear(self):
     pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
     shuffle(pairs)
     od = OrderedDict(pairs)
     self.assertEqual(len(od), len(pairs))
     od.clear()
     self.assertEqual(len(od), 0)
 def test_yaml_linkage(self):
     # Verify that __reduce__ is setup in a way that supports PyYAML's dump() feature.
     # In yaml, lists are native but tuples are not.
     pairs = [("c", 1), ("b", 2), ("a", 3), ("d", 4), ("e", 5), ("f", 6)]
     od = OrderedDict(pairs)
     # yaml.dump(od) -->
     # '!!python/object/apply:__main__.OrderedDict\n- - [a, 1]\n  - [b, 2]\n'
     self.assertTrue(all(type(pair) == list for pair in od.__reduce__()[1]))
예제 #8
0
 def test_delitem(self):
     pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
     od = OrderedDict(pairs)
     del od['a']
     self.assertNotIn('a', od)
     with self.assertRaises(KeyError):
         del od['a']
     self.assertEqual(list(od.items()), pairs[:2] + pairs[3:])
예제 #9
0
 def test_yaml_linkage(self):
     # Verify that __reduce__ is setup in a way that supports PyYAML's dump() feature.
     # In yaml, lists are native but tuples are not.
     pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
     od = OrderedDict(pairs)
     # yaml.dump(od) -->
     # '!!python/object/apply:__main__.OrderedDict\n- - [a, 1]\n  - [b, 2]\n'
     self.assertTrue(all(type(pair) == list for pair in od.__reduce__()[1]))
예제 #10
0
 def test_delitem(self):
     pairs = [("c", 1), ("b", 2), ("a", 3), ("d", 4), ("e", 5), ("f", 6)]
     od = OrderedDict(pairs)
     del od["a"]
     self.assertNotIn("a", od)
     with self.assertRaises(KeyError):
         del od["a"]
     self.assertEqual(list(od.items()), pairs[:2] + pairs[3:])
예제 #11
0
 def test_reinsert(self):
     # Given insert a, insert b, delete a, re-insert a,
     # verify that a is now later than b.
     od = OrderedDict()
     od["a"] = 1
     od["b"] = 2
     del od["a"]
     od["a"] = 1
     self.assertEqual(list(od.items()), [("b", 2), ("a", 1)])
예제 #12
0
 def test_popitem(self):
     pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
     shuffle(pairs)
     od = OrderedDict(pairs)
     while pairs:
         self.assertEqual(od.popitem(), pairs.pop())
     with self.assertRaises(KeyError):
         od.popitem()
     self.assertEqual(len(od), 0)
예제 #13
0
 def test_popitem(self):
     pairs = [("c", 1), ("b", 2), ("a", 3), ("d", 4), ("e", 5), ("f", 6)]
     shuffle(pairs)
     od = OrderedDict(pairs)
     while pairs:
         self.assertEqual(od.popitem(), pairs.pop())
     with self.assertRaises(KeyError):
         od.popitem()
     self.assertEqual(len(od), 0)
예제 #14
0
 def test_repr(self):
     od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5),
                       ('f', 6)])
     self.assertEqual(
         repr(od),
         "OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])"
     )
     self.assertEqual(eval(repr(od)), od)
     self.assertEqual(repr(OrderedDict()), "OrderedDict()")
예제 #15
0
 def test_reinsert(self):
     # Given insert a, insert b, delete a, re-insert a,
     # verify that a is now later than b.
     od = OrderedDict()
     od['a'] = 1
     od['b'] = 2
     del od['a']
     od['a'] = 1
     self.assertEqual(list(od.items()), [('b', 2), ('a', 1)])
예제 #16
0
 def test_equality(self):
     pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
     shuffle(pairs)
     od1 = OrderedDict(pairs)
     od2 = OrderedDict(pairs)
     self.assertEqual(od1, od2)  # same order implies equality
     pairs = pairs[2:] + pairs[:2]
     od2 = OrderedDict(pairs)
     self.assertNotEqual(od1, od2)  # different order implies inequality
     # comparison to regular dict is not order sensitive
     self.assertEqual(od1, dict(od2))
     self.assertEqual(dict(od2), od1)
     # different length implied inequality
     self.assertNotEqual(od1, OrderedDict(pairs[:-1]))
예제 #17
0
 def test_repr_recursive(self):
     # See issue #9826
     od = OrderedDict.fromkeys('abc')
     od['x'] = od
     self.assertEqual(
         repr(od),
         "OrderedDict([('a', None), ('b', None), ('c', None), ('x', ...)])")
예제 #18
0
 def test_views(self):
     s = 'the quick brown fox jumped over a lazy dog yesterday before dawn'.split(
     )
     od = OrderedDict.fromkeys(s)
     self.assertEqual(list(od.viewkeys()), s)
     self.assertEqual(list(od.viewvalues()), [None for k in s])
     self.assertEqual(list(od.viewitems()), [(k, None) for k in s])
예제 #19
0
    def test_init(self):
        with self.assertRaises(TypeError):
            OrderedDict([("a", 1), ("b", 2)], None)  # too many args
        pairs = [("a", 1), ("b", 2), ("c", 3), ("d", 4), ("e", 5)]
        self.assertEqual(sorted(OrderedDict(dict(pairs)).items()), pairs)  # dict input
        self.assertEqual(sorted(OrderedDict(**dict(pairs)).items()), pairs)  # kwds input
        self.assertEqual(list(OrderedDict(pairs).items()), pairs)  # pairs input
        self.assertEqual(
            list(OrderedDict([("a", 1), ("b", 2), ("c", 9), ("d", 4)], c=3, e=5).items()), pairs
        )  # mixed input

        # make sure no positional args conflict with possible kwdargs
        self.assertEqual(inspect.getargspec(OrderedDict.__dict__["__init__"]).args, ["self"])

        # Make sure that direct calls to __init__ do not clear previous contents
        d = OrderedDict([("a", 1), ("b", 2), ("c", 3), ("d", 44), ("e", 55)])
        d.__init__([("e", 5), ("f", 6)], g=7, d=4)
        self.assertEqual(list(d.items()), [("a", 1), ("b", 2), ("c", 3), ("d", 4), ("e", 5), ("f", 6), ("g", 7)])
예제 #20
0
 def test_iterators(self):
     pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
     shuffle(pairs)
     od = OrderedDict(pairs)
     self.assertEqual(list(od), [t[0] for t in pairs])
     self.assertEqual(od.keys()[:], [t[0] for t in pairs])
     self.assertEqual(od.values()[:], [t[1] for t in pairs])
     self.assertEqual(od.items()[:], pairs)
     self.assertEqual(list(od.iterkeys()), [t[0] for t in pairs])
     self.assertEqual(list(od.itervalues()), [t[1] for t in pairs])
     self.assertEqual(list(od.iteritems()), pairs)
     self.assertEqual(list(reversed(od)), [t[0] for t in reversed(pairs)])
예제 #21
0
 def test_copying(self):
     # Check that ordered dicts are copyable, deepcopyable, picklable,
     # and have a repr/eval round-trip
     pairs = [("c", 1), ("b", 2), ("a", 3), ("d", 4), ("e", 5), ("f", 6)]
     od = OrderedDict(pairs)
     update_test = OrderedDict()
     update_test.update(od)
     for i, dup in enumerate(
         [
             od.copy(),
             copy.copy(od),
             copy.deepcopy(od),
             pickle.loads(pickle.dumps(od, 0)),
             pickle.loads(pickle.dumps(od, 1)),
             pickle.loads(pickle.dumps(od, 2)),
             pickle.loads(pickle.dumps(od, -1)),
             eval(repr(od)),
             update_test,
             OrderedDict(od),
         ]
     ):
         self.assertTrue(dup is not od)
         self.assertEqual(dup, od)
         self.assertEqual(list(dup.items()), list(od.items()))
         self.assertEqual(len(dup), len(od))
         self.assertEqual(type(dup), type(od))
예제 #22
0
 def test_iterators(self):
     pairs = [("c", 1), ("b", 2), ("a", 3), ("d", 4), ("e", 5), ("f", 6)]
     shuffle(pairs)
     od = OrderedDict(pairs)
     self.assertEqual(list(od), [t[0] for t in pairs])
     self.assertEqual(od.keys()[:], [t[0] for t in pairs])
     self.assertEqual(od.values()[:], [t[1] for t in pairs])
     self.assertEqual(od.items()[:], pairs)
     self.assertEqual(list(od.iterkeys()), [t[0] for t in pairs])
     self.assertEqual(list(od.itervalues()), [t[1] for t in pairs])
     self.assertEqual(list(od.iteritems()), pairs)
     self.assertEqual(list(reversed(od)), [t[0] for t in reversed(pairs)])
예제 #23
0
 def __init__(self, acct, stats_home, host_list_dir, batch_acct):
     self.id = acct['id']
     self.start_time = acct['start_time']
     self.end_time = acct['end_time']
     self.acct = acct
     self.schemas = {}
     self.hosts = OrderedDict()
     self.times = []
     self.stats_home = stats_home
     self.host_list_dir = host_list_dir
     self.batch_acct = batch_acct
     self.edit_flags = []
     self.errors = set()
     self.overflows = dict()
예제 #24
0
파일: Job.py 프로젝트: minnus/supremm
    def __init__(self, job_pk_id, job_id, acct):
        # pylint: disable=too-many-arguments

        self.job_pk_id = job_pk_id
        self.job_id = job_id
        self.acct = acct
        self._nodecount = acct['nodes']
        self._start_datetime = datetimeconvert(acct['start_time'])
        self._end_datetime = datetimeconvert(acct['end_time'])

        # It is neccessary to set the end time to be one second past because the time
        # precision is only per-second
        self._end_datetime += datetime.timedelta(seconds=1)

        self.walltime = acct['end_time'] - acct['start_time']
        self._nodes = OrderedDict()

        self._data = {}
        self.jobdir = None
        self._nodebegin = {}
        self._nodeend = {}

        self._errors = {}
예제 #25
0
    def test_pop(self):
        pairs = [("c", 1), ("b", 2), ("a", 3), ("d", 4), ("e", 5), ("f", 6)]
        shuffle(pairs)
        od = OrderedDict(pairs)
        shuffle(pairs)
        while pairs:
            k, v = pairs.pop()
            self.assertEqual(od.pop(k), v)
        with self.assertRaises(KeyError):
            od.pop("xyz")
        self.assertEqual(len(od), 0)
        self.assertEqual(od.pop(k, 12345), 12345)

        # make sure pop still works when __missing__ is defined
        class Missing(OrderedDict):
            def __missing__(self, key):
                return 0

        m = Missing(a=1)
        self.assertEqual(m.pop("b", 5), 5)
        self.assertEqual(m.pop("a", 6), 1)
        self.assertEqual(m.pop("a", 6), 6)
        with self.assertRaises(KeyError):
            m.pop("a")
예제 #26
0
 def test_copying(self):
     # Check that ordered dicts are copyable, deepcopyable, picklable,
     # and have a repr/eval round-trip
     pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
     od = OrderedDict(pairs)
     update_test = OrderedDict()
     update_test.update(od)
     for i, dup in enumerate([
             od.copy(),
             copy.copy(od),
             copy.deepcopy(od),
             pickle.loads(pickle.dumps(od, 0)),
             pickle.loads(pickle.dumps(od, 1)),
             pickle.loads(pickle.dumps(od, 2)),
             pickle.loads(pickle.dumps(od, -1)),
             eval(repr(od)),
             update_test,
             OrderedDict(od),
     ]):
         self.assertTrue(dup is not od)
         self.assertEqual(dup, od)
         self.assertEqual(list(dup.items()), list(od.items()))
         self.assertEqual(len(dup), len(od))
         self.assertEqual(type(dup), type(od))
예제 #27
0
    def test_setdefault(self):
        pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
        shuffle(pairs)
        od = OrderedDict(pairs)
        pair_order = list(od.items())
        self.assertEqual(od.setdefault('a', 10), 3)
        # make sure order didn't change
        self.assertEqual(list(od.items()), pair_order)
        self.assertEqual(od.setdefault('x', 10), 10)
        # make sure 'x' is added to the end
        self.assertEqual(list(od.items())[-1], ('x', 10))

        # make sure setdefault still works when __missing__ is defined
        class Missing(OrderedDict):
            def __missing__(self, key):
                return 0

        self.assertEqual(Missing().setdefault(5, 9), 9)
예제 #28
0
파일: Job.py 프로젝트: iMurfyD/supremm
    def __init__(self, job_pk_id, job_id, acct):
        # pylint: disable=too-many-arguments

        self.job_pk_id = job_pk_id
        self.job_id = job_id
        self.acct = acct
        self._nodecount = acct['nodes']
        self._start_datetime = datetimeconvert(acct['start_time'])
        self._end_datetime = datetimeconvert(acct['end_time'])

        # It is neccessary to set the end time to be one second past because the time
        # precision is only per-second
        self._end_datetime += datetime.timedelta(seconds=1)

        self.walltime = acct['end_time'] - acct['start_time']
        self._nodes = OrderedDict()

        self._data = {}
        self.jobdir = None
        self._nodebegin = {}
        self._nodeend = {}

        self._errors = {}
예제 #29
0
    def test_setdefault(self):
        pairs = [("c", 1), ("b", 2), ("a", 3), ("d", 4), ("e", 5), ("f", 6)]
        shuffle(pairs)
        od = OrderedDict(pairs)
        pair_order = list(od.items())
        self.assertEqual(od.setdefault("a", 10), 3)
        # make sure order didn't change
        self.assertEqual(list(od.items()), pair_order)
        self.assertEqual(od.setdefault("x", 10), 10)
        # make sure 'x' is added to the end
        self.assertEqual(list(od.items())[-1], ("x", 10))

        # make sure setdefault still works when __missing__ is defined
        class Missing(OrderedDict):
            def __missing__(self, key):
                return 0

        self.assertEqual(Missing().setdefault(5, 9), 9)
예제 #30
0
    def test_pop(self):
        pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
        shuffle(pairs)
        od = OrderedDict(pairs)
        shuffle(pairs)
        while pairs:
            k, v = pairs.pop()
            self.assertEqual(od.pop(k), v)
        with self.assertRaises(KeyError):
            od.pop('xyz')
        self.assertEqual(len(od), 0)
        self.assertEqual(od.pop(k, 12345), 12345)

        # make sure pop still works when __missing__ is defined
        class Missing(OrderedDict):
            def __missing__(self, key):
                return 0

        m = Missing(a=1)
        self.assertEqual(m.pop('b', 5), 5)
        self.assertEqual(m.pop('a', 6), 1)
        self.assertEqual(m.pop('a', 6), 6)
        with self.assertRaises(KeyError):
            m.pop('a')
예제 #31
0
파일: Job.py 프로젝트: minnus/supremm
class Job(object):
    """ Contains the data for a job. """

    # pylint: disable=too-many-instance-attributes

    def __init__(self, job_pk_id, job_id, acct):
        # pylint: disable=too-many-arguments

        self.job_pk_id = job_pk_id
        self.job_id = job_id
        self.acct = acct
        self._nodecount = acct['nodes']
        self._start_datetime = datetimeconvert(acct['start_time'])
        self._end_datetime = datetimeconvert(acct['end_time'])

        # It is neccessary to set the end time to be one second past because the time
        # precision is only per-second
        self._end_datetime += datetime.timedelta(seconds=1)

        self.walltime = acct['end_time'] - acct['start_time']
        self._nodes = OrderedDict()

        self._data = {}
        self.jobdir = None
        self._nodebegin = {}
        self._nodeend = {}

        self._errors = {}

    def __str__(self):
        """ Return a summary string describing the job """
        return "jobid=%s nodes=%s walltime=%s" % (self.job_id, self._nodecount,
                                                  self.walltime)

    def setjobdir(self, jobdir):
        """
        Set job dir
        """
        self.jobdir = jobdir

    def addnodearchive(self, nodename, node_archive):
        """
        Add the path to the node archive to the list archives for the job
        """
        self._nodes[nodename].set_combinedarchive(node_archive)

    def set_rawarchives(self, node_ar_map):
        """
        Store the list of raw archives that comprise the node
        """
        for nodename, archivelist in node_ar_map.iteritems():
            self._nodes[nodename].set_rawarchives(archivelist)

    def rawarchives(self):
        """ iterator for the raw archives for the nodes in the job """
        for nodename, nodedata in self._nodes.iteritems():
            if len(nodedata.rawarchives) > 0:
                yield nodename, nodedata.rawarchives

    def nodearchives(self):
        """ iterator for the combined archives for the nodes in the job """
        for nodename, nodedata in self._nodes.iteritems():
            if nodedata.archive != None:
                yield nodename, nodedata.nodeindex, nodedata.archive

    def has_any_archives(self):
        """ are there any archives for this job """

        for _, nodedata in self._nodes.iteritems():
            if len(nodedata.rawarchives) > 0:
                return True

        return False

    def has_enough_raw_archives(self):
        """ are there enough raw archives for this job to try pmlogextract"""

        num_archives = 0

        for _, nodedata in self._nodes.iteritems():
            if len(nodedata.rawarchives) > 0:
                num_archives += 1

        if float(num_archives) / float(self._nodecount) > 0.95:
            return True
        else:
            return False

    def has_enough_combined_archives(self):
        """ are there enough combined archives for this job to try summarization"""

        num_archives = 0

        for _, nodedata in self._nodes.iteritems():
            if nodedata.archive != None:
                num_archives += 1

        if float(num_archives) / float(self._nodecount) > 0.95:
            return True
        else:
            return False

    def setnodebeginend(self, node, begin, end):
        """
        Set the begin and end times for the given node. If either
        begin or end is None then the default time from the accounting
        data is used
        """
        if begin != None:
            self._nodebegin[node] = begin
        if end != None:
            self._nodeend[node] = end

    def getnodebegin(self, node):
        """
        Get the start time for job data on the given node
        """
        if node in self._nodebegin:
            return self._nodebegin[node]
        else:
            return self.start_datetime

    def getnodeend(self, node):
        """
        Get end time for job data on the given node
        """
        if node in self._nodeend:
            return self._nodeend[node]
        else:
            return self.end_datetime

    @property
    def nodecount(self):
        """ Total number of nodes assigned to the job """
        return self._nodecount

    @property
    def start_datetime(self):
        """
        Gets a datetime object representing the job's start time, or None
        if the string representation can't be converted.

        Returns:
            A datetime object representing the job's start time, or None
            if the string representation can't be converted.
        """
        return self._start_datetime

    def set_nodes(self, nodelist):
        """ Set the list of nodes assigned to the job.  The First entry in the
        list should be the head node """
        for nodeid, node in enumerate(nodelist):
            self._nodes[node] = JobNode(node, nodeid)

    @property
    def end_datetime(self):
        """
        Gets a datetime object representing the job's end time, or None
        if the string representation can't be converted.

        Returns:
            A datetime object representing the job's end time, or None
            if the string representation can't be converted.
        """
        return self._end_datetime

    def get_errors(self):
        """ Return the list of processing errors """
        return self._errors.keys()

    def record_error(self, msg):
        """ record a processing error for the job """
        if msg in self._errors:
            self._errors[msg] += 1
        else:
            self._errors[msg] = 1

    def data(self):
        """ return all job metadata """
        return self._data

    def adddata(self, name, data):
        """ Add job metadata """
        self._data[name] = data

    def getdata(self, name):
        """ return job metadata for name """
        if name in self._data:
            return self._data[name]
        return None
예제 #32
0
 def test_setitem(self):
     od = OrderedDict([("d", 1), ("b", 2), ("c", 3), ("a", 4), ("e", 5)])
     od["c"] = 10  # existing element
     od["f"] = 20  # new element
     self.assertEqual(list(od.items()), [("d", 1), ("b", 2), ("c", 10), ("a", 4), ("e", 5), ("f", 20)])
예제 #33
0
 def test_repr_recursive(self):
     # See issue #9826
     od = OrderedDict.fromkeys("abc")
     od["x"] = od
     self.assertEqual(repr(od), "OrderedDict([('a', None), ('b', None), ('c', None), ('x', ...)])")
예제 #34
0
 def test_views(self):
     s = "the quick brown fox jumped over a lazy dog yesterday before dawn".split()
     od = OrderedDict.fromkeys(s)
     self.assertEqual(list(od.viewkeys()), s)
     self.assertEqual(list(od.viewvalues()), [None for k in s])
     self.assertEqual(list(od.viewitems()), [(k, None) for k in s])
예제 #35
0
    def test_update(self):
        with self.assertRaises(TypeError):
            OrderedDict().update([("a", 1), ("b", 2)], None)  # too many args
        pairs = [("a", 1), ("b", 2), ("c", 3), ("d", 4), ("e", 5)]
        od = OrderedDict()
        od.update(dict(pairs))
        self.assertEqual(sorted(od.items()), pairs)  # dict input
        od = OrderedDict()
        od.update(**dict(pairs))
        self.assertEqual(sorted(od.items()), pairs)  # kwds input
        od = OrderedDict()
        od.update(pairs)
        self.assertEqual(list(od.items()), pairs)  # pairs input
        od = OrderedDict()
        od.update([("a", 1), ("b", 2), ("c", 9), ("d", 4)], c=3, e=5)
        self.assertEqual(list(od.items()), pairs)  # mixed input

        # Issue 9137: Named argument called 'other' or 'self'
        # shouldn't be treated specially.
        # Does not work in Python 2.6. It complains with the message:
        # TypeError: update() got multiple values for keyword argument 'self'
        # od = OrderedDict()
        # od.update(self=23)
        # self.assertEqual(list(od.items()), [('self', 23)])
        # od = OrderedDict()
        # od.update(other={})
        # self.assertEqual(list(od.items()), [('other', {})])
        # od = OrderedDict()
        # od.update(red=5, blue=6, other=7, self=8)
        # self.assertEqual(sorted(list(od.items())),
        #                 [('blue', 6), ('other', 7), ('red', 5), ('self', 8)])

        # Make sure that direct calls to update do not clear previous contents
        # add that updates items are not moved to the end
        d = OrderedDict([("a", 1), ("b", 2), ("c", 3), ("d", 44), ("e", 55)])
        d.update([("e", 5), ("f", 6)], g=7, d=4)
        self.assertEqual(list(d.items()), [("a", 1), ("b", 2), ("c", 3), ("d", 4), ("e", 5), ("f", 6), ("g", 7)])
예제 #36
0
 def test_abc(self):
     self.assertIsInstance(OrderedDict(), MutableMapping)
     self.assertTrue(issubclass(OrderedDict, MutableMapping))
예제 #37
0
 def test_setitem(self):
     od = OrderedDict([('d', 1), ('b', 2), ('c', 3), ('a', 4), ('e', 5)])
     od['c'] = 10  # existing element
     od['f'] = 20  # new element
     self.assertEqual(list(od.items()), [('d', 1), ('b', 2), ('c', 10),
                                         ('a', 4), ('e', 5), ('f', 20)])
예제 #38
0
    def test_update(self):
        with self.assertRaises(TypeError):
            OrderedDict().update([('a', 1), ('b', 2)], None)  # too many args
        pairs = [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]
        od = OrderedDict()
        od.update(dict(pairs))
        self.assertEqual(sorted(od.items()), pairs)  # dict input
        od = OrderedDict()
        od.update(**dict(pairs))
        self.assertEqual(sorted(od.items()), pairs)  # kwds input
        od = OrderedDict()
        od.update(pairs)
        self.assertEqual(list(od.items()), pairs)  # pairs input
        od = OrderedDict()
        od.update([('a', 1), ('b', 2), ('c', 9), ('d', 4)], c=3, e=5)
        self.assertEqual(list(od.items()), pairs)  # mixed input

        # Issue 9137: Named argument called 'other' or 'self'
        # shouldn't be treated specially.
        # Does not work in Python 2.6. It complains with the message:
        # TypeError: update() got multiple values for keyword argument 'self'
        #od = OrderedDict()
        #od.update(self=23)
        #self.assertEqual(list(od.items()), [('self', 23)])
        #od = OrderedDict()
        #od.update(other={})
        #self.assertEqual(list(od.items()), [('other', {})])
        #od = OrderedDict()
        #od.update(red=5, blue=6, other=7, self=8)
        #self.assertEqual(sorted(list(od.items())),
        #                 [('blue', 6), ('other', 7), ('red', 5), ('self', 8)])

        # Make sure that direct calls to update do not clear previous contents
        # add that updates items are not moved to the end
        d = OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 44), ('e', 55)])
        d.update([('e', 5), ('f', 6)], g=7, d=4)
        self.assertEqual(list(d.items()), [('a', 1), ('b', 2), ('c', 3),
                                           ('d', 4), ('e', 5), ('f', 6),
                                           ('g', 7)])
예제 #39
0
파일: Job.py 프로젝트: iMurfyD/supremm
class Job(object):
    """ Contains the data for a job. """
    # pylint: disable=too-many-instance-attributes

    def __init__(self, job_pk_id, job_id, acct):
        # pylint: disable=too-many-arguments

        self.job_pk_id = job_pk_id
        self.job_id = job_id
        self.acct = acct
        self._nodecount = acct['nodes']
        self._start_datetime = datetimeconvert(acct['start_time'])
        self._end_datetime = datetimeconvert(acct['end_time'])

        # It is neccessary to set the end time to be one second past because the time
        # precision is only per-second
        self._end_datetime += datetime.timedelta(seconds=1)

        self.walltime = acct['end_time'] - acct['start_time']
        self._nodes = OrderedDict()

        self._data = {}
        self.jobdir = None
        self._nodebegin = {}
        self._nodeend = {}

        self._errors = {}

    def __str__(self):
        """ Return a summary string describing the job """
        return "jobid=%s nodes=%s walltime=%s" % (self.job_id, self._nodecount, self.walltime)

    def setjobdir(self, jobdir):
        """
        Set job dir
        """
        self.jobdir = jobdir

    def addnodearchive(self, nodename, node_archive):
        """
        Add the path to the node archive to the list archives for the job
        """
        self._nodes[nodename].set_combinedarchive(node_archive)

    def set_rawarchives(self, node_ar_map):
        """
        Store the list of raw archives that comprise the node
        """
        for nodename, archivelist in node_ar_map.iteritems():
            self._nodes[nodename].set_rawarchives(archivelist)

    def rawarchives(self):
        """ iterator for the raw archives for the nodes in the job """
        for nodename, nodedata in self._nodes.iteritems():
            if len(nodedata.rawarchives) > 0:
                yield nodename, nodedata.rawarchives

    def nodearchives(self):
        """ iterator for the combined archives for the nodes in the job """
        for nodename, nodedata in self._nodes.iteritems():
            if nodedata.archive != None:
                yield nodename, nodedata.nodeindex, nodedata.archive

    def setnodebeginend(self, node, begin, end):
        """
        Set the begin and end times for the given node. If either
        begin or end is None then the default time from the accounting
        data is used
        """
        if begin != None:
            self._nodebegin[node] = begin
        if end != None:
            self._nodeend[node] = end

    def getnodebegin(self, node):
        """
        Get the start time for job data on the given node
        """
        if node in self._nodebegin:
            return self._nodebegin[node]
        else:
            return self.start_datetime

    def getnodeend(self, node):
        """
        Get end time for job data on the given node
        """
        if node in self._nodeend:
            return self._nodeend[node]
        else:
            return self.end_datetime

    @property
    def nodecount(self):
        """ Total number of nodes assigned to the job """
        return self._nodecount

    @property
    def start_datetime(self):
        """
        Gets a datetime object representing the job's start time, or None
        if the string representation can't be converted.

        Returns:
            A datetime object representing the job's start time, or None
            if the string representation can't be converted.
        """
        return self._start_datetime

    def set_nodes(self, nodelist):
        """ Set the list of nodes assigned to the job.  The First entry in the
        list should be the head node """
        for nodeid, node in enumerate(nodelist):
            self._nodes[node] = JobNode(node, nodeid)

    @property
    def end_datetime(self):
        """
        Gets a datetime object representing the job's end time, or None
        if the string representation can't be converted.

        Returns:
            A datetime object representing the job's end time, or None
            if the string representation can't be converted.
        """
        return self._end_datetime

    def get_errors(self):
        """ Return the list of processing errors """
        return self._errors.keys()

    def record_error(self, msg):
        """ record a processing error for the job """
        if msg in self._errors:
            self._errors[msg] += 1
        else:
            self._errors[msg] = 1

    def data(self):
        """ return all job metadata """
        return self._data

    def adddata(self, name, data):
        """ Add job metadata """
        self._data[name] = data

    def getdata(self, name):
        """ return job metadata for name """
        if name in self._data:
            return self._data[name]
        return None