Konstantine Rybnikov avatar Konstantine Rybnikov committed 3b92c9d

rename Diff to PoDiff. So nice ^____^

Comments (0)

Files changed (4)

fat_po_editor/diffutil.py

 
 MAXLEN = 80
 
-class Diff(object):
+class PoDiff(object):
     """This class implements storage of diff data between two po-files.
 
     It:
         return self.operation_to_storage_map[operation_type]
 
     def __repr__(self):
-        rv = StringBuilder(unicode(super(Diff, self).__repr__()))
+        rv = StringBuilder(unicode(super(PoDiff, self).__repr__()))
         rv += u' (%(add_num)s add, %(rm_num)s rm, %(modify_num)s modify)' \
             % dict(add_num=len(self.operation_to_storage_map['add']),
                    rm_num=len(self.operation_to_storage_map['rm']),
     
     def full_represent(self):
         """Full represent should guaranty that it represent all the information
-        needed to fully describe Diff. Used to make sure that two Diff's are
+        needed to fully describe PoDiff. Used to make sure that two PoDiff's are
         equal.
         """
         def prefix_lines(prefix, text):
         return unicode(rv)
 
     def __eq__(self, other):
-        if not isinstance(other, Diff):
+        if not isinstance(other, PoDiff):
             return False
         return self.full_represent() == other.full_represent()
 
 def compare_two_pofiles(pofile1, pofile2):
-    """Returns :class:`~Diff` object that represents difference between two po
+    """Returns :class:`~PoDiff` object that represents difference between two po
     files.
 
     ``pofile1``, ``pofile2``
         :class:`~polib.POFile` instances.
     """
 
-    rv = Diff()
+    rv = PoDiff()
     
     pofile1_msgid_to_poentry_map = dict(map(lambda entry: (entry.msgid, entry), pofile1))
     pofile2_msgid_to_poentry_map = dict(map(lambda entry: (entry.msgid, entry), pofile2))

fat_po_editor/vcs_util.py

     """Info about changeset that will be really useful for fat_po_editor"""
 
     def __init__(self, changeset):
+        self.changeset = changeset
         self.revision = changeset.short_id
         self.author = changeset.author
         self.affected_pofiles = list(filter(lambda x: x.endswith('.po'),
         rv = StringBuilder()
         rv += u"Revision no.: %s\n" % self.revision
         rv += u"Author: %s\n" % self.author
-        rv += u"Affected pofiles: [%s]\n" % u", ".joinself.affected_pofiles
+        rv += u"Affected pofiles: [%s]\n" % u", ".join(self.affected_pofiles)
         return unicode(rv)
 
 class RepoWithPofiles(object):
         self.path = path
         self.vcs_repo = vcs.get_repo(path)
 
-    def get_last_changesets_info(self, limit=10):
+    def get_last_useful_changesets_info(self, limit=10):
         """Returns information needed to draw nice representation of last
         affected pofiles and they're authors"""
         MAX_ITERATED_CHANGESETS_NUM = 1000
                                    self.vcs_repo.get_changeset(changeset)),
                 reversed(revisions)))
         useful_revisions = (
-            map(lambda x: is_useful_changeset(revision_to_changeset_map.get(x)),
-                revisions))
+            filter(lambda x: is_useful_changeset(revision_to_changeset_map.get(x)),
+                   revisions))
         rv = [BoundChangesetInfo(self.vcs_repo.get_changeset(r))
               for r in useful_revisions]
         return rv
+
+    def generate_podiff_for_changeset(self):
+        """Returns :class:`~fat_po_editor.diffutil.PoDiff` instance for this changeset"""
+        pass

tests/test_diffutil.py

 
 from polib import POEntry, POFile
 
-from fat_po_editor.diffutil import Diff, compare_two_pofiles
+from fat_po_editor.diffutil import PoDiff, compare_two_pofiles
 
-class TestDiffUtilDiff(unittest.TestCase):
+class TestDiffUtilPoDiff(unittest.TestCase):
     def test_append_simple(self):
-        diff = Diff()
+        diff = PoDiff()
         entry = POEntry(msgid=u"First msgid",
                         msgstr=u"First msgstr")
         diff.append_entry('add', entry)
             [entry])
 
     def test_representation_simple(self):
-        diff = Diff()
+        diff = PoDiff()
         entry = POEntry(msgid=u"First msgid",
                         msgstr=u"First msgstr")
         diff.append_entry('add', entry)
              u"    * First msgid\n"))
 
     def test_representation_more_complex(self):
-        diff = Diff()
+        diff = PoDiff()
         entry = POEntry(msgid=u"First msgid",
                         msgstr=u"First msgstr")
         diff.append_entry('add', entry)
              u"    * Third msgid\n"))
 
     def test_representation_too_long(self):
-        diff = Diff()
+        diff = PoDiff()
         entry = POEntry(msgid=u"F" * 81,
                         msgstr=u"First msgstr")
         diff.append_entry('add', entry)
              u"    * %s...\n") % (u"F" * 71))
 
     def test_representation_with_newline(self):
-        diff = Diff()
+        diff = PoDiff()
         entry = POEntry(msgid=u"First \nmsgid",
                         msgstr=u"First msgstr")
         diff.append_entry('add', entry)
              u"    * First \\nmsgid\n"))
 
     def test_full_represent(self):
-        diff = Diff()
+        diff = PoDiff()
         entry = POEntry(msgid=u"First msgid",
                         msgstr=u"First msgstr")
         diff.append_entry('add', entry)
              u'''- msgstr "Third msgstr"\n'''))
 
     def test_eq_simple(self):
-        diff1 = Diff()
+        diff1 = PoDiff()
         entry = POEntry(msgid=u"First msgid",
                         msgstr=u"First msgstr")
         diff1.append_entry('add', entry)
-        diff2 = Diff()
+        diff2 = PoDiff()
         entry = POEntry(msgid=u"First msgid",
                         msgstr=u"First msgstr")
         diff2.append_entry('add', entry)
         self.assertEquals(diff1 == diff2, True)
 
     def test_eq_simple_noneq(self):
-        diff1 = Diff()
+        diff1 = PoDiff()
         entry = POEntry(msgid=u"First msgid",
                         msgstr=u"First msgstr")
         diff1.append_entry('add', entry)
-        diff2 = Diff()
+        diff2 = PoDiff()
         entry = POEntry(msgid=u"Second msgid",
                         msgstr=u"Second msgstr")
         diff2.append_entry('add', entry)
         self.assertEquals(diff1 == diff2, False)
 
     def test_eq_empty(self):
-        diff1 = Diff()
-        diff2 = Diff()
+        diff1 = PoDiff()
+        diff2 = PoDiff()
         
         self.assertEquals(diff1 == diff2, True)
 
         f2 = POFile()
 
         self.assertEquals(compare_two_pofiles(f1, f2),
-                          Diff())
+                          PoDiff())
 
     def test_simple(self):
         f1 = POFile()
         f2 = POFile()
-        expected = Diff()
+        expected = PoDiff()
         
         e = POEntry(msgid=u"First msgid",
                     msgstr=u"First msgstr")

tests/test_vcs_util.py

                                           'repo1')
         self.repo = RepoWithPofiles(self.testdata_path)
 
-    def test_get_last_changesets_info_simple(self):
-        info = self.repo.get_last_changesets_info()
+    def test_get_last_useful_changesets_info_simple(self):
+        info = self.repo.get_last_useful_changesets_info()
         self.assertEquals(len(info), 2)
         self.assertEquals(unicode(info[0]),
-                          (u"Revision no.: "))
-        
+                          (u"Revision no.: b45afb00139e\n"
+                           u"Author: kost BebiX <k.bx@ya.ru>\n"
+                           u"Affected pofiles: [pofiles/first.po]\n"))
+        self.assertEquals(unicode(info[1]),
+                          (u"Revision no.: df3e51d42076\n"
+                           u"Author: kost BebiX <k.bx@ya.ru>\n"
+                           u"Affected pofiles: [pofiles/first.po]\n"))
+
+class TestBoundChangesetInfo(unittest.TestCase):
+    pass
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.