def test_case_existing(self): folder = get_cased_path(temp_folder()) p1 = os.path.join(folder, "MyFolder", "Subfolder") mkdir(p1) self.assertEqual(p1, get_cased_path(p1)) # Idempotent self.assertEqual(p1, get_cased_path(os.path.join(folder, "myfolder", "subfolder")))
def test_case_not_existing(self): current_dir = get_cased_path(os.getcwd()) non_existing_path = os.path.join(current_dir, "this", "Path", "does", "NOT", "Exists") p = get_cased_path( non_existing_path) # If not exists from the root, returns as is self.assertEqual(p, non_existing_path)
def test_case_partial_exists(self): folder = get_cased_path(temp_folder()) p1 = os.path.join(folder, "MyFolder", "Subfolder") mkdir(p1) non_existing_path = os.path.join(folder, "myfolder", "subfolder", "not-existing") # The first part of the path will be properly cased. self.assertEqual(os.path.join(p1, "not-existing"), get_cased_path(non_existing_path))
def test_case(self): folder = temp_folder() p1 = os.path.join(folder, "MyFolder", "Subfolder") mkdir(p1) p2 = get_cased_path(p1) self.assertEqual(p1, p2) p3 = os.path.join(folder, "myfolder", "subfolder") p4 = get_cased_path(p3) self.assertEqual(p1, p4)
def create_local_git_repo(files=None, branch=None, submodules=None, folder=None, commits=1, tags=None): tmp = folder or temp_folder() tmp = get_cased_path(tmp) if files: save_files(tmp, files) git = Git(tmp) git.run("init .") git.run('config user.email "*****@*****.**"') git.run('config user.name "Your Name"') if branch: git.run("checkout -b %s" % branch) git.run("add .") for i in range(0, commits): git.run('commit --allow-empty -m "commiting"') tags = tags or [] for tag in tags: git.run("tag %s" % tag) if submodules: for submodule in submodules: git.run('submodule add "%s"' % submodule) git.run('commit -m "add submodules"') return tmp.replace("\\", "/"), git.get_revision()
def test_auto_git(self): curdir = get_cased_path(self.client.current_folder).replace("\\", "/") conanfile = base_git.format(directory="None", url=_quoted("auto"), revision="auto") self.client.save({"conanfile.py": conanfile, "myfile.txt": "My file is copied"}) create_local_git_repo(folder=self.client.current_folder) self.client.run("export . user/channel", assert_error=True) self.assertIn("Repo origin cannot be deduced", self.client.out) self.client.run_command('git remote add origin https://myrepo.com.git') # Create the package, will copy the sources from the local folder self.client.run("create . user/channel") self.assertIn("Repo origin deduced by 'auto': https://myrepo.com.git", self.client.out) self.assertIn("Revision deduced by 'auto'", self.client.out) self.assertIn("SCM: Getting sources from folder: %s" % curdir, self.client.out) self.assertIn("My file is copied", self.client.out) # check blank lines are respected in replacement self.client.run("get lib/0.1@user/channel") self.assertIn("""} def build(self):""", self.client.out) # Export again but now with absolute reference, so no sources are copied from the local dir git = Git(curdir) self.client.save({"conanfile.py": base_git.format(url=_quoted(curdir), revision=git.get_revision())}) self.client.run("create . user/channel") self.assertNotIn("Repo origin deduced by 'auto'", self.client.out) self.assertNotIn("Revision deduced by 'auto'", self.client.out) self.assertNotIn("Getting sources from folder: %s" % curdir, self.client.out) self.assertIn("SCM: Getting sources from url: '%s'" % curdir, self.client.out) self.assertIn("My file is copied", self.client.out)
def test_auto_conanfile_no_root(self): """ Conanfile is not in the root of the repo: https://github.com/conan-io/conan/issues/3465 """ curdir = get_cased_path(self.client.current_folder).replace("\\", "/") conanfile = base_git.format(url=_quoted("auto"), revision="auto") self.client.save({"conan/conanfile.py": conanfile, "myfile.txt": "content of my file"}) self._commit_contents() self.client.runner('git remote add origin https://myrepo.com.git', cwd=curdir) # Create the package self.client.run("create conan/ user/channel") sources_dir = self.client.cache.scm_folder(self.ref) self.assertEqual(load(sources_dir), curdir.replace('\\', '/')) # Root of git is 'curdir'
def temp_folder(path_with_spaces=True): t = tempfile.mkdtemp(suffix='conans', dir=CONAN_TEST_FOLDER) # Make sure that the temp folder is correctly cased, as tempfile return lowercase for Win t = get_cased_path(t) # necessary for Mac OSX, where the temp folders in /var/ are symlinks to /private/var/ t = os.path.realpath(t) # FreeBSD and Solaris do not use GNU Make as a the default 'make' program which has trouble # with spaces in paths generated by CMake if not path_with_spaces or platform.system() == "FreeBSD" or platform.system() == "SunOS": path = "pathwithoutspaces" else: path = "path with spaces" nt = os.path.join(t, path) os.makedirs(nt) return nt
def test_auto_git(self): curdir = get_cased_path(self.client.current_folder).replace("\\", "/") conanfile = base_git.format(directory="None", url="auto", revision="auto") self.client.save({"conanfile.py": conanfile, "myfile.txt": "My file is copied"}) create_local_git_repo(folder=self.client.current_folder) error = self.client.run("export . user/channel", ignore_error=True) self.assertTrue(error) self.assertIn("Repo origin cannot be deduced by 'auto'", self.client.out) self.client.runner('git remote add origin https://myrepo.com.git', cwd=curdir) # Create the package, will copy the sources from the local folder self.client.run("create . user/channel") sources_dir = self.client.client_cache.scm_folder(self.reference) self.assertEquals(load(sources_dir), curdir) self.assertIn("Repo origin deduced by 'auto': https://myrepo.com.git", self.client.out) self.assertIn("Revision deduced by 'auto'", self.client.out) self.assertIn("Getting sources from folder: %s" % curdir, self.client.out) self.assertIn("My file is copied", self.client.out) # check blank lines are respected in replacement self.client.run("get lib/0.1@user/channel") self.assertIn("""} def build(self):""", self.client.out) # Export again but now with absolute reference, so no pointer file is created nor kept git = Git(curdir) self.client.save({"conanfile.py": base_git.format(url=curdir, revision=git.get_revision())}) self.client.run("create . user/channel") sources_dir = self.client.client_cache.scm_folder(self.reference) self.assertFalse(os.path.exists(sources_dir)) self.assertNotIn("Repo origin deduced by 'auto'", self.client.out) self.assertNotIn("Revision deduced by 'auto'", self.client.out) self.assertIn("Getting sources from url: '%s'" % curdir, self.client.out) self.assertIn("My file is copied", self.client.out)