예제 #1
0
파일: test_dicts.py 프로젝트: Xion/taipan
 def test_strict__false(self):
     self.assertEquals(
         self.WITH_STRICT_KEYS_OMITTED,
         __unit__.omit(self.STRICT_KEYS, self.DICT, strict=False))
     self.assertEquals(
         self.WITH_NONSTRICT_KEYS_OMITTED,
         __unit__.omit(self.NONSTRICT_KEYS, self.DICT, strict=False))
예제 #2
0
 def test_strict__false(self):
     self.assertEquals(
         self.WITH_STRICT_KEYS_OMITTED,
         __unit__.omit(self.STRICT_KEYS, self.DICT, strict=False))
     self.assertEquals(
         self.WITH_NONSTRICT_KEYS_OMITTED,
         __unit__.omit(self.NONSTRICT_KEYS, self.DICT, strict=False))
예제 #3
0
    def test_strict__true(self):
        self.assertEquals(
            self.WITH_STRICT_KEYS_OMITTED,
            __unit__.omit(self.STRICT_KEYS, self.DICT, strict=True))

        with self.assertRaises(KeyError) as r:
            __unit__.omit(self.NONSTRICT_KEYS, self.DICT, strict=True)
        self.assertIn(repr(self.EXTRANEOUS_KEY), str(r.exception))
예제 #4
0
파일: test_dicts.py 프로젝트: Xion/taipan
    def test_strict__true(self):
        self.assertEquals(
            self.WITH_STRICT_KEYS_OMITTED,
            __unit__.omit(self.STRICT_KEYS, self.DICT, strict=True))

        with self.assertRaises(KeyError) as r:
            __unit__.omit(self.NONSTRICT_KEYS, self.DICT, strict=True)
        self.assertIn(repr(self.EXTRANEOUS_KEY), str(r.exception))
예제 #5
0
파일: output.py 프로젝트: Xion/coded4
def output_xml(repo_name, contribs, totals):
    """Outputs the repository statistics in general XML format."""
    from StringIO import StringIO
    import xml.etree.ElementTree as ET

    stats = ET.Element('statistics', attrib={'repo': repo_name})

    def write_contrib(contrib, parent, tag):
        ET.SubElement(parent, tag, attrib=dicts.mapvalues(str_, contrib))

    contributors = ET.SubElement(stats, 'contributors')
    for contrib in contribs:
        write_contrib(contrib, parent=contributors, tag='contributor')
    write_contrib(dicts.omit(['name'], from_=totals),
                  parent=stats, tag='totals')

    result = StringIO()
    ET.ElementTree(stats).write(result, encoding='utf-8', xml_declaration=True)

    result.seek(0)
    return result.read()
예제 #6
0
파일: output.py 프로젝트: mmgutsche/coded4
def output_xml(repo_name, contribs, totals):
    """Outputs the repository statistics in general XML format."""
    from StringIO import StringIO
    import xml.etree.ElementTree as ET

    stats = ET.Element('statistics', attrib={'repo': repo_name})

    def write_contrib(contrib, parent, tag):
        ET.SubElement(parent, tag, attrib=dicts.mapvalues(str_, contrib))

    contributors = ET.SubElement(stats, 'contributors')
    for contrib in contribs:
        write_contrib(contrib, parent=contributors, tag='contributor')
    write_contrib(dicts.omit(['name'], from_=totals),
                  parent=stats,
                  tag='totals')

    result = StringIO()
    ET.ElementTree(stats).write(result, encoding='utf-8', xml_declaration=True)

    result.seek(0)
    return result.read()
예제 #7
0
파일: output.py 프로젝트: Xion/coded4
def output_sexp(repo_name, contribs, totals):
    """Output the repository statistics as an S-expression."""
    from StringIO import StringIO

    result = StringIO()
    print >>result, '(repo "%s"' % repo_name

    def write_contrib(contrib, tag, indent=0):
        indent = ' ' * indent
        print >>result, indent +'(%s %s)' % (tag, ' '.join(
            '(%s "%s")' % item for item in contrib.items()))

    for contrib in contribs:
        write_contrib(contrib, tag='contributor', indent=1)
    write_contrib(dicts.omit(['name'], from_=totals), tag='totals', indent=1)

    # insert final closing parenthesis before the last newline
    result.seek(-len(os.linesep), 1)
    print >>result, ")"

    result.seek(0)
    return result.read()[:-len(os.linesep)]  # remove that last newline
예제 #8
0
파일: output.py 프로젝트: mmgutsche/coded4
def output_sexp(repo_name, contribs, totals):
    """Output the repository statistics as an S-expression."""
    from StringIO import StringIO

    result = StringIO()
    print >> result, '(repo "%s"' % repo_name

    def write_contrib(contrib, tag, indent=0):
        indent = ' ' * indent
        print >> result, indent + '(%s %s)' % (tag, ' '.join(
            '(%s "%s")' % item for item in contrib.items()))

    for contrib in contribs:
        write_contrib(contrib, tag='contributor', indent=1)
    write_contrib(dicts.omit(['name'], from_=totals), tag='totals', indent=1)

    # insert final closing parenthesis before the last newline
    result.seek(-len(os.linesep), 1)
    print >> result, ")"

    result.seek(0)
    return result.read()[:-len(os.linesep)]  # remove that last newline
예제 #9
0
파일: output.py 프로젝트: Xion/coded4
def output_yaml(repo_name, contribs, totals):
    """Output the repository statistics in YAML format."""
    from StringIO import StringIO

    result = StringIO()
    print >>result, "repo:", repo_name

    def write_contrib(contrib, indent=0):
        prefix = "- "
        indent = " " * indent
        for key, value in contrib.items():
            print >>result, indent + "%s%s: %s" % (prefix, key, value)
            prefix = "  "

    print >>result, "contributors:"
    for contrib in contribs:
        write_contrib(contrib)

    print >>result, "totals:"
    write_contrib(dicts.omit(['name'], from_=totals))

    result.seek(0)
    return result.read()
예제 #10
0
파일: output.py 프로젝트: mmgutsche/coded4
def output_yaml(repo_name, contribs, totals):
    """Output the repository statistics in YAML format."""
    from StringIO import StringIO

    result = StringIO()
    print >> result, "repo:", repo_name

    def write_contrib(contrib, indent=0):
        prefix = "- "
        indent = " " * indent
        for key, value in contrib.items():
            print >> result, indent + "%s%s: %s" % (prefix, key, value)
            prefix = "  "

    print >> result, "contributors:"
    for contrib in contribs:
        write_contrib(contrib)

    print >> result, "totals:"
    write_contrib(dicts.omit(['name'], from_=totals))

    result.seek(0)
    return result.read()
예제 #11
0
파일: test_dicts.py 프로젝트: Xion/taipan
 def test_keys__none(self):
     with self.assertRaises(TypeError):
         __unit__.omit(None, self.DICT)
예제 #12
0
 def test_from__some_object(self):
     with self.assertRaises(TypeError):
         __unit__.omit(self.STRICT_KEYS, object())
예제 #13
0
 def test_from__empty(self):
     with self.assertRaises(KeyError):
         __unit__.omit(self.STRICT_KEYS, {}, strict=True)
     self.assertEquals({},
                       __unit__.omit(self.NONSTRICT_KEYS, {}, strict=False))
예제 #14
0
 def test_keys__empty(self):
     self.assertEquals(self.DICT, __unit__.omit((), self.DICT))
예제 #15
0
 def test_from__none(self):
     with self.assertRaises(TypeError):
         __unit__.omit(self.STRICT_KEYS, None)
예제 #16
0
 def test_keys__none(self):
     with self.assertRaises(TypeError):
         __unit__.omit(None, self.DICT)
예제 #17
0
 def test_keys__some_object(self):
     with self.assertRaises(TypeError):
         __unit__.omit(object(), self.DICT)
예제 #18
0
파일: test_dicts.py 프로젝트: Xion/taipan
 def test_keys__some_object(self):
     with self.assertRaises(TypeError):
         __unit__.omit(object(), self.DICT)
예제 #19
0
파일: test_dicts.py 프로젝트: Xion/taipan
 def test_keys__empty(self):
     self.assertEquals(self.DICT, __unit__.omit((), self.DICT))
예제 #20
0
파일: test_dicts.py 프로젝트: Xion/taipan
 def test_from__none(self):
     with self.assertRaises(TypeError):
         __unit__.omit(self.STRICT_KEYS, None)
예제 #21
0
파일: test_dicts.py 프로젝트: Xion/taipan
 def test_from__some_object(self):
     with self.assertRaises(TypeError):
         __unit__.omit(self.STRICT_KEYS, object())
예제 #22
0
파일: test_dicts.py 프로젝트: Xion/taipan
 def test_from__empty(self):
     with self.assertRaises(KeyError):
         __unit__.omit(self.STRICT_KEYS, {}, strict=True)
     self.assertEquals(
         {}, __unit__.omit(self.NONSTRICT_KEYS, {}, strict=False))