def test_relpath_symlink(self): """ Ensure `relative_to` works in a symlink. Not available on windows. """ symlink = getattr(os, 'symlink', None) if symlink is None: return # symlinks unavailable on this platform oldcwd = os.getcwd() workspace = tempfile.mkdtemp() try: tmpdir = os.path.join(workspace, 'directory') os.makedirs(tmpdir) linkdir = os.path.join(workspace, 'link') symlink(tmpdir, linkdir) self.create_stub(tmpdir) # subdir with in-memory manifest files = ['../bar', '../fleem', '../foo', 'subfile'] subdir = os.path.join(linkdir, 'subdir') os.chdir(os.path.realpath(subdir)) for directory in (tmpdir, linkdir): parser = convert([directory], relative_to='.') self.assertEqual([i['name'] for i in parser.tests], files) finally: shutil.rmtree(workspace) os.chdir(oldcwd) # a more complicated example oldcwd = os.getcwd() workspace = tempfile.mkdtemp() try: tmpdir = os.path.join(workspace, 'directory') os.makedirs(tmpdir) linkdir = os.path.join(workspace, 'link') symlink(tmpdir, linkdir) self.create_stub(tmpdir) files = ['../bar', '../fleem', '../foo', 'subfile'] subdir = os.path.join(linkdir, 'subdir') subsubdir = os.path.join(subdir, 'sub') os.makedirs(subsubdir) linksubdir = os.path.join(linkdir, 'linky') linksubsubdir = os.path.join(subsubdir, 'linky') symlink(subdir, linksubdir) symlink(subdir, linksubsubdir) for dest in (subdir,): os.chdir(dest) for directory in (tmpdir, linkdir): parser = convert([directory], relative_to='.') self.assertEqual([i['name'] for i in parser.tests], files) finally: shutil.rmtree(workspace) os.chdir(oldcwd)
def test_relpath_symlink(self): """ Ensure `relative_to` works in a symlink. Not available on windows. """ symlink = getattr(os, 'symlink', None) if symlink is None: return # symlinks unavailable on this platform oldcwd = os.getcwd() workspace = tempfile.mkdtemp() try: tmpdir = os.path.join(workspace, 'directory') os.makedirs(tmpdir) linkdir = os.path.join(workspace, 'link') symlink(tmpdir, linkdir) self.create_stub(tmpdir) # subdir with in-memory manifest files = ['../bar', '../fleem', '../foo', 'subfile'] subdir = os.path.join(linkdir, 'subdir') os.chdir(os.path.realpath(subdir)) for directory in (tmpdir, linkdir): parser = convert([directory], relative_to='.') self.assertEqual([i['name'] for i in parser.tests], files) finally: shutil.rmtree(workspace) os.chdir(oldcwd) # a more complicated example oldcwd = os.getcwd() workspace = tempfile.mkdtemp() try: tmpdir = os.path.join(workspace, 'directory') os.makedirs(tmpdir) linkdir = os.path.join(workspace, 'link') symlink(tmpdir, linkdir) self.create_stub(tmpdir) files = ['../bar', '../fleem', '../foo', 'subfile'] subdir = os.path.join(linkdir, 'subdir') subsubdir = os.path.join(subdir, 'sub') os.makedirs(subsubdir) linksubdir = os.path.join(linkdir, 'linky') linksubsubdir = os.path.join(subsubdir, 'linky') symlink(subdir, linksubdir) symlink(subdir, linksubsubdir) for dest in (subdir, ): os.chdir(dest) for directory in (tmpdir, linkdir): parser = convert([directory], relative_to='.') self.assertEqual([i['name'] for i in parser.tests], files) finally: shutil.rmtree(workspace) os.chdir(oldcwd)
def test_relpath_symlink(self): """ Ensure `relative_to` works in a symlink. Not available on windows. """ oldcwd = os.getcwd() workspace = tempfile.mkdtemp() try: tmpdir = os.path.join(workspace, "directory") os.makedirs(tmpdir) linkdir = os.path.join(workspace, "link") os.symlink(tmpdir, linkdir) self.create_stub(tmpdir) # subdir with in-memory manifest files = ["../bar", "../fleem", "../foo", "subfile"] subdir = os.path.join(linkdir, "subdir") os.chdir(os.path.realpath(subdir)) for directory in (tmpdir, linkdir): parser = convert([directory], relative_to=".") self.assertEqual([i["name"] for i in parser.tests], files) finally: shutil.rmtree(workspace) os.chdir(oldcwd) # a more complicated example oldcwd = os.getcwd() workspace = tempfile.mkdtemp() try: tmpdir = os.path.join(workspace, "directory") os.makedirs(tmpdir) linkdir = os.path.join(workspace, "link") os.symlink(tmpdir, linkdir) self.create_stub(tmpdir) files = ["../bar", "../fleem", "../foo", "subfile"] subdir = os.path.join(linkdir, "subdir") subsubdir = os.path.join(subdir, "sub") os.makedirs(subsubdir) linksubdir = os.path.join(linkdir, "linky") linksubsubdir = os.path.join(subsubdir, "linky") os.symlink(subdir, linksubdir) os.symlink(subdir, linksubsubdir) for dest in (subdir, ): os.chdir(dest) for directory in (tmpdir, linkdir): parser = convert([directory], relative_to=".") self.assertEqual([i["name"] for i in parser.tests], files) finally: shutil.rmtree(workspace) os.chdir(oldcwd)
def test_pattern(self): """test directory -> manifest with a file pattern""" stub = self.create_stub() try: parser = convert([stub], pattern="f*", relative_to=stub) self.assertEqual([i["name"] for i in parser.tests], ["fleem", "foo"]) # test multiple patterns parser = convert([stub], pattern=("f*", "s*"), relative_to=stub) self.assertEqual([i["name"] for i in parser.tests], ["fleem", "foo", "subdir/subfile"]) except: raise finally: shutil.rmtree(stub)
def test_directory_to_manifest(self): """ Test our ability to convert a static directory structure to a manifest. """ # create a stub directory stub = self.create_stub() try: stub = stub.replace(os.path.sep, "/") self.assertTrue(os.path.exists(stub) and os.path.isdir(stub)) # Make a manifest for it manifest = convert([stub]) out_tmpl = """[%(stub)s/bar] [%(stub)s/fleem] [%(stub)s/foo] [%(stub)s/subdir/subfile] """ # noqa self.assertEqual(str(manifest), out_tmpl % dict(stub=stub)) except BaseException: raise finally: shutil.rmtree(stub) # cleanup
def test_directory_to_manifest(self): """ Test our ability to convert a static directory structure to a manifest. """ # create a stub directory stub = self.create_stub() try: stub = stub.replace(os.path.sep, "/") self.assertTrue(os.path.exists(stub) and os.path.isdir(stub)) # Make a manifest for it manifest = convert([stub]) self.assertEqual(str(manifest), """[%(stub)s/bar] subsuite = [%(stub)s/fleem] subsuite = [%(stub)s/foo] subsuite = [%(stub)s/subdir/subfile] subsuite = """ % dict(stub=stub)) except: raise finally: shutil.rmtree(stub) # cleanup
def test_pattern(self): """test directory -> manifest with a file pattern""" stub = self.create_stub() try: parser = convert([stub], pattern='f*', relative_to=stub) self.assertEqual([i['name'] for i in parser.tests], ['fleem', 'foo']) # test multiple patterns parser = convert([stub], pattern=('f*', 's*'), relative_to=stub) self.assertEqual([i['name'] for i in parser.tests], ['fleem', 'foo', 'subdir/subfile']) except BaseException: raise finally: shutil.rmtree(stub)
def test_pattern(self): """test directory -> manifest with a file pattern""" stub = self.create_stub() try: parser = convert([stub], pattern='f*', relative_to=stub) self.assertEqual([i['name'] for i in parser.tests], ['fleem', 'foo']) # test multiple patterns parser = convert([stub], pattern=('f*', 's*'), relative_to=stub) self.assertEqual([i['name'] for i in parser.tests], ['fleem', 'foo', 'subdir/subfile']) except: raise finally: shutil.rmtree(stub)
def test_pattern(self): """test directory -> manifest with a file pattern""" stub = self.create_stub() try: parser = convert([stub], pattern="f*", relative_to=stub) self.assertEqual([i["name"] for i in parser.tests], ["fleem", "foo"]) # test multiple patterns parser = convert([stub], pattern=("f*", "s*"), relative_to=stub) self.assertEqual( [i["name"] for i in parser.tests], ["fleem", "foo", "subdir/subfile"] ) except BaseException: raise finally: shutil.rmtree(stub)
def test_directory_to_manifest(self): """ Test our ability to convert a static directory structure to a manifest. """ # First, stub out a directory with files in it:: def create_stub(): directory = tempfile.mkdtemp() for i in 'foo', 'bar', 'fleem': file(os.path.join(directory, i), 'w').write(i) subdir = os.path.join(directory, 'subdir') os.mkdir(subdir) file(os.path.join(subdir, 'subfile'), 'w').write('baz') return directory stub = create_stub() self.assertTrue(os.path.exists(stub) and os.path.isdir(stub)) # Make a manifest for it: self.assertEqual(convert([stub]), """[bar] [fleem] [foo] [subdir/subfile]""") shutil.rmtree(stub) # cleanup # Now do the same thing but keep the manifests in place: stub = create_stub() convert([stub], write='manifest.ini') self.assertEqual(sorted(os.listdir(stub)), ['bar', 'fleem', 'foo', 'manifest.ini', 'subdir']) parser = ManifestParser() parser.read(os.path.join(stub, 'manifest.ini')) self.assertEqual([i['name'] for i in parser.tests], ['subfile', 'bar', 'fleem', 'foo']) parser = ManifestParser() parser.read(os.path.join(stub, 'subdir', 'manifest.ini')) self.assertEqual(len(parser.tests), 1) self.assertEqual(parser.tests[0]['name'], 'subfile') shutil.rmtree(stub)
def test_relpath(self): """test convert `relative_to` functionality""" oldcwd = os.getcwd() stub = self.create_stub() try: # subdir with in-memory manifest files = ['../bar', '../fleem', '../foo', 'subfile'] subdir = os.path.join(stub, 'subdir') os.chdir(subdir) parser = convert([stub], relative_to='.') self.assertEqual([i['name'] for i in parser.tests], files) except BaseException: raise finally: shutil.rmtree(stub) os.chdir(oldcwd)
def test_update(self): """ Test our ability to update tests from a manifest and a directory of files """ # boilerplate tempdir = create_realpath_tempdir() for i in range(10): open(os.path.join(tempdir, str(i)), "w").write(str(i)) # otherwise empty directory with a manifest file newtempdir = create_realpath_tempdir() manifest_file = os.path.join(newtempdir, "manifest.ini") manifest_contents = str(convert([tempdir], relative_to=tempdir)) with open(manifest_file, "w") as f: f.write(manifest_contents) # get the manifest manifest = ManifestParser(manifests=(manifest_file,)) # All of the tests are initially missing: paths = [str(i) for i in range(10)] self.assertEqual([i["name"] for i in manifest.missing()], paths) # But then we copy one over: self.assertEqual(manifest.get("name", name="1"), ["1"]) manifest.update(tempdir, name="1") self.assertEqual(sorted(os.listdir(newtempdir)), ["1", "manifest.ini"]) # Update that one file and copy all the "tests": open(os.path.join(tempdir, "1"), "w").write("secret door") manifest.update(tempdir) self.assertEqual( sorted(os.listdir(newtempdir)), ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "manifest.ini"], ) self.assertEqual( open(os.path.join(newtempdir, "1")).read().strip(), "secret door" ) # clean up: shutil.rmtree(tempdir) shutil.rmtree(newtempdir)
def test_update(self): """ Test our ability to update tests from a manifest and a directory of files """ # boilerplate tempdir = create_realpath_tempdir() for i in range(10): file(os.path.join(tempdir, str(i)), 'w').write(str(i)) # otherwise empty directory with a manifest file newtempdir = create_realpath_tempdir() manifest_file = os.path.join(newtempdir, 'manifest.ini') manifest_contents = str(convert([tempdir], relative_to=tempdir)) with file(manifest_file, 'w') as f: f.write(manifest_contents) # get the manifest manifest = ManifestParser(manifests=(manifest_file,)) # All of the tests are initially missing: paths = [str(i) for i in range(10)] self.assertEqual([i['name'] for i in manifest.missing()], paths) # But then we copy one over: self.assertEqual(manifest.get('name', name='1'), ['1']) manifest.update(tempdir, name='1') self.assertEqual(sorted(os.listdir(newtempdir)), ['1', 'manifest.ini']) # Update that one file and copy all the "tests": file(os.path.join(tempdir, '1'), 'w').write('secret door') manifest.update(tempdir) self.assertEqual(sorted(os.listdir(newtempdir)), ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'manifest.ini']) self.assertEqual(file(os.path.join(newtempdir, '1')).read().strip(), 'secret door') # clean up: shutil.rmtree(tempdir) shutil.rmtree(newtempdir)
def test_update(self): """ Test our ability to update tests from a manifest and a directory of files """ # boilerplate tempdir = tempfile.mkdtemp() for i in range(10): file(os.path.join(tempdir, str(i)), 'w').write(str(i)) # otherwise empty directory with a manifest file newtempdir = tempfile.mkdtemp() manifest_file = os.path.join(newtempdir, 'manifest.ini') manifest_contents = str(convert([tempdir], relative_to=tempdir)) with file(manifest_file, 'w') as f: f.write(manifest_contents) # get the manifest manifest = ManifestParser(manifests=(manifest_file,)) # All of the tests are initially missing: paths = [str(i) for i in range(10)] self.assertEqual([i['name'] for i in manifest.missing()], paths) # But then we copy one over: self.assertEqual(manifest.get('name', name='1'), ['1']) manifest.update(tempdir, name='1') self.assertEqual(sorted(os.listdir(newtempdir)), ['1', 'manifest.ini']) # Update that one file and copy all the "tests": file(os.path.join(tempdir, '1'), 'w').write('secret door') manifest.update(tempdir) self.assertEqual(sorted(os.listdir(newtempdir)), ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'manifest.ini']) self.assertEqual(file(os.path.join(newtempdir, '1')).read().strip(), 'secret door') # clean up: shutil.rmtree(tempdir) shutil.rmtree(newtempdir)
def test_update(self): """ Test our ability to update tests from a manifest and a directory of files """ # boilerplate tempdir = create_realpath_tempdir() for i in range(10): file(os.path.join(tempdir, str(i)), "w").write(str(i)) # otherwise empty directory with a manifest file newtempdir = create_realpath_tempdir() manifest_file = os.path.join(newtempdir, "manifest.ini") manifest_contents = str(convert([tempdir], relative_to=tempdir)) with file(manifest_file, "w") as f: f.write(manifest_contents) # get the manifest manifest = ManifestParser(manifests=(manifest_file,)) # All of the tests are initially missing: paths = [str(i) for i in range(10)] self.assertEqual([i["name"] for i in manifest.missing()], paths) # But then we copy one over: self.assertEqual(manifest.get("name", name="1"), ["1"]) manifest.update(tempdir, name="1") self.assertEqual(sorted(os.listdir(newtempdir)), ["1", "manifest.ini"]) # Update that one file and copy all the "tests": file(os.path.join(tempdir, "1"), "w").write("secret door") manifest.update(tempdir) self.assertEqual( sorted(os.listdir(newtempdir)), ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "manifest.ini"] ) self.assertEqual(file(os.path.join(newtempdir, "1")).read().strip(), "secret door") # clean up: shutil.rmtree(tempdir) shutil.rmtree(newtempdir)
def test_update(self): """ Test our ability to update tests from a manifest and a directory of files """ # boilerplate tempdir = tempfile.mkdtemp() for i in range(10): file(os.path.join(tempdir, str(i)), 'w').write(str(i)) # First, make a manifest: manifest = convert([tempdir]) newtempdir = tempfile.mkdtemp() manifest_file = os.path.join(newtempdir, 'manifest.ini') file(manifest_file,'w').write(manifest) manifest = ManifestParser(manifests=(manifest_file,)) self.assertEqual(manifest.get('name'), [str(i) for i in range(10)]) # All of the tests are initially missing: self.assertEqual([i['name'] for i in manifest.missing()], [str(i) for i in range(10)]) # But then we copy one over: self.assertEqual(manifest.get('name', name='1'), ['1']) manifest.update(tempdir, name='1') self.assertEqual(sorted(os.listdir(newtempdir)), ['1', 'manifest.ini']) # Update that one file and copy all the "tests": file(os.path.join(tempdir, '1'), 'w').write('secret door') manifest.update(tempdir) self.assertEqual(sorted(os.listdir(newtempdir)), ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'manifest.ini']) self.assertEqual(file(os.path.join(newtempdir, '1')).read().strip(), 'secret door') # clean up: shutil.rmtree(tempdir) shutil.rmtree(newtempdir)