Merge lp:~sil/u1db/testing-inmemory into lp:u1db

Proposed by Sidnei da Silva
Status: Merged
Approved by: Sidnei da Silva
Approved revision: 437
Merged at revision: 436
Proposed branch: lp:~sil/u1db/testing-inmemory
Merge into: lp:u1db
Diff against target: 65 lines (+43/-1)
1 file modified
html-docs/tutorial.rst (+43/-1)
To merge this branch: bzr merge lp:~sil/u1db/testing-inmemory
Reviewer Review Type Date Requested Status
Sidnei da Silva (community) Approve
Review via email: mp+138202@code.launchpad.net

Commit message

Add a note to the tutorial documentation explaining how to use inmemory implementations of u1db for test suites.

Description of the change

Add a note to the tutorial documentation explaining how to use inmemory implementations of u1db for test suites.

To post a comment you must log in.
Revision history for this message
Sidnei da Silva (sidnei) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'html-docs/tutorial.rst'
2--- html-docs/tutorial.rst 2012-09-26 07:11:08 +0000
3+++ html-docs/tutorial.rst 2012-12-05 15:12:39 +0000
4@@ -7,6 +7,8 @@
5 in the u1db source tree. It comes with a user interface, but we will only
6 focus on the code that interacts with u1db here.
7
8+This tutorial demonstrates the Python implementation of u1db.
9+
10 Defining the Task Object
11 ------------------------
12
13@@ -394,7 +396,46 @@
14 # refresh the UI to show the resolved version
15 self.refresh_filter()
16
17-Full Cosas Documentation and Source Code
18+Testing your programs
19+---------------------
20+
21+When building tests for programs which use u1db, you may not want to create a real database
22+file in your test suite. U1DB can be run entirely in-memory; this makes test suites easier
23+to write and much faster to run!
24+
25+Python
26+======
27+
28+For Python u1db-using programs, there are two ways to create an in-memory U1DB. The Python
29+implementation of u1db has its own in-memory implementation:
30+
31+.. code-block:: python
32+
33+ # db = u1db.open(somepath, create=True) # this is how your program will normally use u1db
34+
35+ # Use the in-memory implementation instead:
36+ from u1db.backends import inmemory
37+ db = inmemory.InMemoryDatabase("test")
38+
39+Alternatively, you can take advantage of the Python implementation being backed by SQLite, and
40+use SQLite's in-memory implementation:
41+
42+.. code-block:: python
43+
44+ db = u1db.open(":memory:", create=True) # create a SQLite database in memory
45+
46+C
47+=
48+
49+The C implementation of u1db does not have its own in-memory implementation, but you can
50+use SQLite's:
51+
52+.. code-block:: c
53+
54+ #include <u1db/u1db.h>
55+ u1database *db = u1db_open(":memory:");
56+
57+Full Cosas Documentation and Source Code
58 ----------------------------------------
59
60 .. automodule:: cosas.cosas
61@@ -403,3 +444,4 @@
62 .. automodule:: cosas.ui
63 :members:
64
65+

Subscribers

People subscribed via source and target branches