def scenario(**files_to_levels):
    levels = []
    with utils.tempdir() as a:
        levels.append(a)
        with utils.tempdir() as b:
            levels.append(b)
            with utils.tempdir() as c:
                levels.append(c)
                for name, dirs in files_to_levels.items():
                    for level in dirs:
                        with open(os.path.join(levels[level], name), 'w') as f:
                            f.write(str(level))

                with utils.bootstrap_scenario() as spec:
                    with mock.patch('mandrel.bootstrap.SEARCH_PATHS', new=levels):
                        yield levels
예제 #2
0
 def testRootNested(self):
     with utils.bootstrap_scenario(dir='~') as spec:
         with utils.tempdir(dir=spec[0]) as nested_a:
             with utils.workdir(dir=nested_a) as nested_b:
                 utils.refresh_bootstrapper()
                 self.assertEqual(spec[0], mandrel.bootstrap.ROOT_PATH)
                 self.assertEqual(spec[1], mandrel.bootstrap.BOOTSTRAP_FILE)
 def testRootNested(self):
     with utils.bootstrap_scenario(dir='~') as spec:
         with utils.tempdir(dir=spec[0]) as nested_a:
             with utils.workdir(dir=nested_a) as nested_b:
                 utils.refresh_bootstrapper()
                 self.assertEqual(spec[0], mandrel.bootstrap.ROOT_PATH)
                 self.assertEqual(spec[1], mandrel.bootstrap.BOOTSTRAP_FILE)
예제 #4
0
def scenario(**files_to_levels):
    levels = []
    with utils.tempdir() as a:
        levels.append(a)
        with utils.tempdir() as b:
            levels.append(b)
            with utils.tempdir() as c:
                levels.append(c)
                for name, dirs in files_to_levels.items():
                    for level in dirs:
                        with open(os.path.join(levels[level], name), 'w') as f:
                            f.write(str(level))

                with utils.bootstrap_scenario() as spec:
                    with mock.patch('mandrel.bootstrap.SEARCH_PATHS',
                                    new=levels):
                        yield levels
 def testNormalizeAbsolutePath(self):
     with utils.bootstrap_scenario() as spec:
         utils.refresh_bootstrapper()
         with utils.tempdir() as root:
             paths = [
                 os.path.join(root, x)
                 for x in ('blibby', 'blooby', 'blobby')
             ]
             self.assertEqual(
                 paths,
                 [mandrel.bootstrap.normalize_path(p) for p in paths])
예제 #6
0
    def testGetByFQNImportable(self):
        with utils.tempdir() as tmp:
            path = os.path.join(tmp, 'fluffypants')
            os.mkdir(path)
            with open(os.path.join(path, '__init__.py'), 'w') as f:
                f.write("\n")

            with open(os.path.join(path, 'happydance.py'), 'w') as f:
                f.write("\n")

            sys.path.insert(0, tmp)
            try:
                result = util.get_by_fqn('fluffypants.happydance')
                self.assertEqual('fluffypants.happydance', result.__name__)
            finally:
                sys.path.pop(0)
예제 #7
0
    def testGetByFQNImportable(self):
        with utils.tempdir() as tmp:
            path = os.path.join(tmp, 'fluffypants')
            os.mkdir(path)
            with open(os.path.join(path, '__init__.py'), 'w') as f:
                f.write("\n")

            with open(os.path.join(path, 'happydance.py'), 'w') as f:
                f.write("\n")

            sys.path.insert(0, tmp)
            try:
                result = util.get_by_fqn('fluffypants.happydance')
                self.assertEqual('fluffypants.happydance', result.__name__)
            finally:
                sys.path.pop(0)
예제 #8
0
 def testLoadOperation(self):
     with utils.tempdir() as dirpath:
         filepath = os.path.join(dirpath, 'some_config')
         contents = "---\nfoo: blargh\nblee:\n - blah\n - blorp\n"
         with open(filepath, 'w') as outfile:
             outfile.write(contents)
         
         with mock.patch('yaml.safe_load') as safe_load:
             def loader(f):
                 safe_load.file_contents = f.read()
                 return safe_load.return_value
             safe_load.side_effect = loader
             result = config.core.read_yaml_path(filepath)
             # yaml.safe_load called once
             self.assertEqual(1, len(safe_load.call_args_list))
             # it's first arg appears to be a reader of our file
             self.assertEqual(contents, safe_load.file_contents)
             # and we got the result back.
             self.assertEqual(result, safe_load.return_value)