Skip to content

Commit

Permalink
Found reason of test failing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneBachmann committed Dec 18, 2017
1 parent 50fe371 commit 203144b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
import sos.version # was already generated during build phase
with open(readmeFile, "r") as fd: README = fd.read()

#if 'test' in sys.argv and '-v' in sys.argv: os.environ["DEBUG"] = "true"
if 'cover' in sys.argv:
sys.argv.remove('cover')
if 'test' in sys.argv: sys.argv.remove('test')
if 0 != os.system("coverage run --branch --debug=sys --source=sos sos/tests.py && coverage html && coverage annotate sos/tests.py"):
print("Cannot create coverage report when tests fail")


print("\nRunning setup() for SOS version " + sos.version.__version__)
setup(
name = 'sos-vcs',
Expand Down
16 changes: 8 additions & 8 deletions sos/sos.coco
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class Metadata:
if write: os.makedirs(os.path.join(_.root, metaFolder, "b%d" % branch, "r%d" % revision))
changes:ChangeSet = ChangeSet({}, {}, {})
counter:Counter = Counter(-1); timer = time.time()
hashed:str; written:longint; compressed:longint = 0; original:longint = 0
hashed:str?; written:longint; compressed:longint = 0; original:longint = 0
for path, dirnames, filenames in os.walk(_.root):
dirnames[:] = [f for f in dirnames if len([n for n in _.c.ignoreDirs if fnmatch.fnmatch(f, n)]) == 0 or len([p for p in _.c.ignoreDirsWhitelist if fnmatch.fnmatch(f, p)]) > 0]
filenames[:] = [f for f in filenames if len([n for n in _.c.ignores if fnmatch.fnmatch(f, n)]) == 0 or len([p for p in _.c.ignoresWhitelist if fnmatch.fnmatch(f, p)]) > 0]
Expand All @@ -272,17 +272,17 @@ class Metadata:
sys.stdout.write(outstring + " " * max(0, termWidth - len(outstring))); sys.stdout.flush(); timer = newtime # TODO could write to new line instead of carriage return, also needs terminal width
if filename not in _.paths: # detected file not present (or untracked) in other branch
namehash = hashStr(filename)
hashed, written = hashFile(filepath, _.compress, saveTo = os.path.join(_.root, metaFolder, "b%d" % branch, "r%d" % revision, namehash) if write else None)
changes.additions[filename] = PathInfo(namehash, size, mtime, hashed if size > 0 else None)
hashed, written = hashFile(filepath, _.compress, saveTo = os.path.join(_.root, metaFolder, "b%d" % branch, "r%d" % revision, namehash) if write else None) if size > 0 else (None, 0)
changes.additions[filename] = PathInfo(namehash, size, mtime, hashed)
compressed += written; original += size
continue
last = _.paths[filename] # filename is known - check for modifications
if last.size is None: # was removed before but is now added back - does not apply for tracking mode (which never marks files for removal in the history)
hashed, written = hashFile(filepath, _.compress, saveTo = os.path.join(_.root, metaFolder, "b%d" % branch, "r%d" % revision, last.namehash) if write else None)
changes.additions[filename] = PathInfo(last.namehash, size, mtime, hashed if size > 0 else None); continue
hashed, written = hashFile(filepath, _.compress, saveTo = os.path.join(_.root, metaFolder, "b%d" % branch, "r%d" % revision, last.namehash) if write else None) if size > 0 else (None, 0)
changes.additions[filename] = PathInfo(last.namehash, size, mtime, hashed); continue
elif size != last.size or mtime != last.mtime or (checkContent and hashFile(filepath, _.compress) != last.hash): # detected a modification
hashed, written = hashFile(filepath, _.compress, saveTo = os.path.join(_.root, metaFolder, "b%d" % branch, "r%d" % revision, last.namehash) if write else None) if not inverse else (None, 0)
changes.modifications[filename] = PathInfo(last.namehash, last.size if inverse else size, last.mtime if inverse else mtime, last.hash if inverse else hashed if (last.size if inverse else size) > 0 else None)
hashed, written = hashFile(filepath, _.compress, saveTo = os.path.join(_.root, metaFolder, "b%d" % branch, "r%d" % revision, last.namehash) if write else None) if (last.size if inverse else size) > 0 else (last.hash if inverse else None, 0)
changes.modifications[filename] = PathInfo(last.namehash, last.size if inverse else size, last.mtime if inverse else mtime, hashed)
else: continue
compressed += written; original += last.size if inverse else size
# Detect deletions. Files no longer being tracked should not be found here
Expand Down Expand Up @@ -805,7 +805,7 @@ def main() -> None:
parse(root, cwd)
elif cmd is not None: # online mode - delegate to VCS
info("SOS: Running '%s %s'" % (cmd, " ".join(sys.argv[1:])))
import subprocess # only requuired in this section
import subprocess # only required in this section
process = subprocess.Popen([cmd] + sys.argv[1:], shell = False, stdin = subprocess.PIPE, stdout = sys.stdout, stderr = sys.stderr)
inp:str = ""
while True:
Expand Down
15 changes: 8 additions & 7 deletions sos/tests.coco
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def determineFilesystemTimeResolution() -> float =
name = str(uuid.uuid4())
with open(name, "w") as fd: fd.write("x") # create temporary file
mt = os.stat(name)[8] # get current timestamp

while os.stat(name)[8] == mt: # wait until timestamp modified
with open(name, "w") as fd: fd.write("x")
mt, start, count = os.stat(name)[8], time.time(), 0
Expand Down Expand Up @@ -278,7 +277,7 @@ class Tests(unittest.TestCase):
_.assertEqual(0, len(changes.additions))
_.assertEqual(0, len(changes.deletions))
_.assertEqual(0, len(changes.modifications))
_.createFile(1, "z")
_.createFile(1, "z") # size change
changes = sos.changes()
_.assertEqual(0, len(changes.additions))
_.assertEqual(0, len(changes.deletions))
Expand All @@ -287,14 +286,16 @@ class Tests(unittest.TestCase):
_.assertAllIn(["r0", "r1", sos.metaFile], os.listdir("." + os.sep + sos.metaFolder + os.sep + "b0"))
_.assertAllIn([sos.metaFile, "b9ee10a87f612e299a6eb208210bc0898092a64c48091327cc2aaeee9b764ffa"], os.listdir(branchFolder(0, 1)))
_.assertEqual(2, len(os.listdir(branchFolder(0, 1)))) # no further files, only the modified one
_.assertEqual(1, len(sos.changes("/0").modifications)) # vs. implicit (same) branch revision
_.assertEqual(1, len(sos.changes("0/0").modifications)) # vs. explicit branch revision
_.createFile(1, "") # create empty file, mentioned in meta data, but not stored as own file
_.assertEqual(1, len(sos.changes("/0").modifications)) # vs. explicit revision on current branch
_.assertEqual(1, len(sos.changes("0/0").modifications)) # vs. explicit branch/revision
_.createFile(1, "") # modify to empty file, mentioned in meta data, but not stored as own file
os.unlink("file2")
changes = sos.changes()
_.assertEqual(0, len(changes.additions))
_.assertEqual(0, len(changes.deletions))
_.assertEqual(1, len(changes.deletions))
_.assertEqual(1, len(changes.modifications))
sos.commit("modified")
_.assertEqual(1, len(os.listdir(branchFolder(0, 2)))) # no further files, only the modified one
_.assertEqual(1, len(os.listdir(branchFolder(0, 2)))) # no additional files, only mentions in metadata
try: sos.commit("nothing"); _.fail() # expecting Exit due to no changes
except: pass

Expand Down
6 changes: 3 additions & 3 deletions sos/utility.coco
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try:
except: pass # typing not available (e.g. Python 2)
try: import wcwidth
except: pass # optional dependency
longint:Union[Type] = eval("long") if sys.version_info.major < 3 else int # for Python 2 compatibility
longint:Type = eval("long") if sys.version_info.major < 3 else int # for Python 2 compatibility


# Classes
Expand Down Expand Up @@ -54,7 +54,7 @@ vcsBranches:Dict[str,str?] = {SVN: "trunk", "git": "master", "bzr": "trunk", "hg
# Value types
data BranchInfo(number:int, ctime:int, name:str? = None, insync:bool = False, tracked:List[str] = []) # tracked is a list on purpose, as serialization to JSON needs effort and frequent access is not taking place
data CommitInfo(number:int, ctime:int, message:str? = None)
data PathInfo(namehash:str, size:int?, mtime:int, hash:str) # size == None means deleted in this revision
data PathInfo(namehash:str, size:int?, mtime:int, hash:str?) # size == None means deleted in this revision
data ChangeSet(additions:Dict[str,PathInfo], deletions:Dict[str,PathInfo], modifications:Dict[str,PathInfo]) # avoid default assignment of {} as it leads to runtime errors (contains data on init for unknown reason)
data Range(tipe:int, indexes:int[]) # MergeBlockType[1,2,4], line number, length
data MergeBlock(tipe:int, lines:str[], line:int, replaces:MergeBlock? = None, changes:Range? = None)
Expand Down Expand Up @@ -126,7 +126,7 @@ def getTermWidth() -> int =
termwidth.getTermWidth()[0]

def hashFile(path:str, compress:bool, saveTo:str? = None) -> Tuple[str,longint] =
''' Calculate hash of file contents, and return compressed sized, if in write mode. '''
''' Calculate hash of file contents, and return compressed sized, if in write mode, or zero. '''
_hash = hashlib.sha256()
wsize:longint = 0
to = openIt(saveTo, "w", compress) if saveTo else None
Expand Down

0 comments on commit 203144b

Please sign in to comment.