Commits

Jan Willems committed 00315a8

Added proper asserts for the hg_pull and hg_push tests.
Made sure that tox worked.

  • Participants
  • Parent commits 333ce72

Comments (0)

Files changed (2)

-hgapi
-=====
-
-.. image:: https://travis-ci.org/haard/hgapi.png?branch=master
-   :target: https://travis-ci.org/haard/hgapi
-
-
-hgapi is a pure-Python API to Mercurial, that uses the command-line
-interface instead of the internal Mercurial API. The rationale for
-this is twofold: the internal API is unstable, and it is GPL.
-
-hgapi works for all versions of Mercurial, and will instantly reflect any
-changes to the repository (including hgrc). It also has a really 
-permissive license (do whatever you want, don't blame me).
-
-For example of code that uses this API, take a look at
-https://bitbucket.org/haard/autohook which now uses hgapi
-exclusively. Add any feature requests or bugs found to the issue tracker.
-
-So far, the API supports::
-
- hg add [<file>]
- hg addremove [<file>]
- hg branch
- hg branches
- hg clone
- hg commit [files] [-u name] [--close-branch]
- hg diff
- hg heads
- hg id
- hg init
- hg log
- hg merge (fails on conflict)
- hg pull [<source>]
- hg push [<destination>]
- hg remove
- hg rename <source> <destination>
- hg revert
- hg root
- hg status
- hg tag
- hg tags
- hg update <rev>
- hg version
-
-You also have access to the configuration (config, configbool,
-configlist) just as in the internal Mercurial API. The repository 
-supports slicing and indexing notation.
-
-Example usage::
-    >>> import hgapi
-    >>> repo = hgapi.Repo("test_hgapi")  # existing folder
-    >>> repo.hg_init()
-    >>> repo.hg_add("file.txt")  # already created but not added file
-    >>> repo.hg_commit("Adding file.txt", user="me")
-    >>> str(repo['tip'].desc)
-    'Adding file.txt'
-    >>> len(repo[0:'tip'])
-    1
-    >>> open('test_hgapi/file.txt', 'a').write('\nAdded line') # doctest: +IGNORE_RESULT
-    >>> diff = repo.hg_diff()  # returns list of diffs
-    >>> assert diff[0]['filename'] == 'file.txt'
-    >>> assert '+Added line' in diff[0]['diff']
-    
-Installation
-============
-
-Easiest is easy_install or pip from PyPy::
-
- pip install hgapi
-
-or::
-
- easy_install hgapi
-
-Otherwise, download the source, make sure you have setuptools
-installed, and then run::
-
- python setup.py install
-
-License
-=======
-
-Copyright (c) 2011, Fredrik Håård 
-
-Do whatever you want, don't blame me. You may also use this software
-as licensed under the MIT or BSD licenses, or the more permissive license below:
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so:
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
+hgapi
+=====
+
+.. image:: https://travis-ci.org/haard/hgapi.png?branch=master
+   :target: https://travis-ci.org/haard/hgapi
+
+
+hgapi is a pure-Python API to Mercurial, that uses the command-line
+interface instead of the internal Mercurial API. The rationale for
+this is twofold: the internal API is unstable, and it is GPL.
+
+hgapi works for all versions of Mercurial, and will instantly reflect any
+changes to the repository (including hgrc). It also has a really
+permissive license (do whatever you want, don't blame me).
+
+For example of code that uses this API, take a look at
+https://bitbucket.org/haard/autohook which now uses hgapi
+exclusively. Add any feature requests or bugs found to the issue tracker.
+
+So far, the API supports::
+
+ hg add [<file>]
+ hg addremove [<file>]
+ hg branch
+ hg branches
+ hg clone
+ hg commit [files] [-u name] [--close-branch]
+ hg diff
+ hg heads
+ hg id
+ hg init
+ hg log
+ hg merge (fails on conflict)
+ hg pull [<source>]
+ hg push [<destination>]
+ hg remove
+ hg rename <source> <destination>
+ hg revert
+ hg root
+ hg status
+ hg tag
+ hg tags
+ hg update <rev>
+ hg version
+
+You also have access to the configuration (config, configbool,
+configlist) just as in the internal Mercurial API. The repository
+supports slicing and indexing notation.
+
+Example usage::
+
+    >>> import hgapi
+    >>> repo = hgapi.Repo("test_hgapi")  # existing folder
+    >>> repo.hg_init()
+    >>> repo.hg_add("file.txt")  # already created but not added file
+    >>> repo.hg_commit("Adding file.txt", user="me")
+    >>> str(repo['tip'].desc)
+    'Adding file.txt'
+    >>> len(repo[0:'tip'])
+    1
+    >>> open('test_hgapi/file.txt', 'a').write('\nAdded line')
+    >>> diff = repo.hg_diff()  # returns list of diffs
+    >>> assert diff[0]['filename'] == 'file.txt'
+    >>> assert '+Added line' in diff[0]['diff']
+
+Installation
+============
+
+Easiest is easy_install or pip from PyPy::
+
+ pip install hgapi
+
+or::
+
+ easy_install hgapi
+
+Otherwise, download the source, make sure you have setuptools
+installed, and then run::
+
+ python setup.py install
+
+License
+=======
+
+Copyright (c) 2011, Fredrik Håård
+
+Do whatever you want, don't blame me. You may also use this software
+as licensed under the MIT or BSD licenses, or the more permissive license below:
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so:
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

File hgapi/testhgapi.py

         with open("./test/cities/antwerp.txt", "w") as out:
             out.write("antwerpen")
         self.repo.hg_add()
-        self.repo.hg_commit("[TEST] Added two cities.")
+        message = "[TEST] Added two cities."
+        self.repo.hg_commit(message)
         self.clone.hg_pull("../test")
-        # TODO: assert
+        # update clone after pull and then check if the identifiers are the same
+        self.clone.hg_update("tip")
+        self.assertEquals(self.clone.hg_id(), self.repo.hg_id())
+        # check summary of pulled tip
+        self.assertTrue(message in self.clone.hg_log(identifier="tip"))
 
     def test_320_push(self):
         """Update, add another file in test-clone and push test-clone to test."""
-        #import time
-        #time.sleep(120)
-        self.clone.hg_update("tip")
-        #self.clone.hg_pull()
-        with open("./test-clone/ghent.txt", "w") as out:
+        with open("./test-clone/cities/ghent.txt", "w") as out:
             out.write("gent")
         self.clone.hg_add()
-        self.clone.hg_commit("[CLONE] Added one file.")
+        message = "[CLONE] Added one file."
+        self.clone.hg_commit(message)
         self.clone.hg_push("../test")
-        # TODO: assert
+        # update test after push and assert
+        self.repo.hg_update("tip")
+        self.assertEquals(self.clone.hg_id(), self.repo.hg_id())
+        # check summary of pushed tip
+        self.assertTrue(message in self.repo.hg_log(identifier="tip"))
 
     def test_400_version(self):
         self.assertNotEquals(hgapi.Repo.hg_version(), "")
     def test_410_root(self):
         # regular test repo
         reply = hgapi.Repo.hg_root("./test")
-        self.assertTrue(reply.endswith("hgapi/hgapi/test"))
+        self.assertTrue(reply.endswith("/hgapi/test"))
         # non existing repo
         self.assertRaises(hgapi.HgException, hgapi.Repo.hg_root, "./whatever")
 
         #Cleanup
         shutil.rmtree("test_hgapi")
 
+
 if __name__ == "__main__":
     try:
         test_doc()