MCPcopy Create free account
hub / github.com/ActiveState/code / main

Function main

recipes/Python/52277_Saving_backups_when_writing/recipe-52277.py:97–128  ·  view source on GitHub ↗

Module mainline (for isolation testing)

()

Source from the content-addressed store, hash-verified

95 os.remove(pathname)
96
97def main():
98 """Module mainline (for isolation testing)"""
99 basename = "TestFile.txt"
100 if os.path.exists(basename):
101 os.remove(basename)
102 for i in range(10):
103 outf = VersionedOutputFile(basename)
104 outf.write("This is version %s.\n" % i)
105 outf.close()
106
107 # Now there should be just four versions of TestFile.txt:
108 expectedSuffixes = ["", ".~7~", ".~8~", ".~9~"]
109 expectedVersions = []
110 for suffix in expectedSuffixes:
111 expectedVersions.append("%s%s" % (basename, suffix))
112 matchingFiles = glob.glob("%s*" % basename)
113 for filename in matchingFiles:
114 if filename not in expectedVersions:
115 sys.stderr.write("Found unexpected file %s.\n" % filename)
116 else:
117 # Unit tests should clean up after themselves...
118 os.remove(filename)
119
120 # Finally, here's an example of how to use versioned
121 # output files in concert with marshal.
122 import marshal
123
124 outf = VersionedOutputFile("marshal.dat")
125 # Marshal out a sequence:
126 marshal.dump([1, 2, 3], outf.asFile())
127 outf.close()
128 os.remove("marshal.dat")
129
130if __name__ == "__main__":
131 main()

Callers 1

recipe-52277.pyFile · 0.70

Calls 9

closeMethod · 0.95
asFileMethod · 0.95
rangeFunction · 0.85
VersionedOutputFileClass · 0.85
existsMethod · 0.45
removeMethod · 0.45
writeMethod · 0.45
appendMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected