def test_path_to_local_project_no_separator(self): """Local folder can have no path separator (in current directory).""" project_path = "testpath" # local() is called more than once so we need an extra next_call() # otherwise fudge compares the args to the last call to local() self.fake_local.with_args(arg.endswith("-C . testpath")).next_call() # Exercise project.upload_project(local_dir=project_path)
def test_path_to_local_project_can_be_specified(self): """It should be possible to specify which local folder to upload.""" project_path = "path/to/my/project" # local() is called more than once so we need an extra next_call() # otherwise fudge compares the args to the last call to local() self.fake_local.with_args( arg.endswith("-C path/to/my project")).next_call() # Exercise project.upload_project(local_dir=project_path)
def test_current_directory_is_uploaded_by_default(self): """By default the project uploaded is the current working directory.""" cwd_path, cwd_name = os.path.split(os.getcwd()) # local() is called more than once so we need an extra next_call() # otherwise fudge compares the args to the last call to local() self.fake_local.with_args( arg.endswith("-C %s %s" % (cwd_path, cwd_name))).next_call() # Exercise project.upload_project()
def test_path_to_local_project_can_be_specified(self): """It should be possible to specify which local folder to upload.""" project_path = "path/to/my/project" # local() is called more than once so we need an extra next_call() # otherwise fudge compares the args to the last call to local() self.fake_local.with_args( arg.endswith("-C path/to/my project") ).next_call() # Exercise project.upload_project(local_dir=project_path)
def test_current_directory_is_uploaded_by_default(self): """By default the project uploaded is the current working directory.""" cwd_path, cwd_name = os.path.split(os.getcwd()) # local() is called more than once so we need an extra next_call() # otherwise fudge compares the args to the last call to local() self.fake_local.with_args( arg.endswith("-C %s %s" % (cwd_path, cwd_name)) ).next_call() # Exercise project.upload_project()
def test_path_to_local_project_no_separator(self): """Local folder can have no path separator (in current directory).""" project_path = "testpath" # local() is called more than once so we need an extra next_call() # otherwise fudge compares the args to the last call to local() self.fake_local.with_args( arg.endswith("-C . testpath") ).next_call() # Exercise project.upload_project(local_dir=project_path)
def test_path_to_local_project_can_end_in_separator(self): """A local path ending in a separator should be handled correctly.""" project_path = "path/to/my" base = "project" # local() is called more than once so we need an extra next_call() # otherwise fudge compares the args to the last call to local() self.fake_local.with_args( arg.endswith("-C %s %s" % (project_path, base))).next_call() # Exercise project.upload_project(local_dir="%s/%s/" % (project_path, base))
def test_path_to_local_project_can_end_in_separator(self): """A local path ending in a separator should be handled correctly.""" project_path = "path/to/my" base = "project" # local() is called more than once so we need an extra next_call() # otherwise fudge compares the args to the last call to local() self.fake_local.with_args( arg.endswith("-C %s %s" % (project_path, base)) ).next_call() # Exercise project.upload_project(local_dir="%s/%s/" % (project_path, base))
def test_endswith_ok_uni(self): db = Fake("db").expects("execute").with_args(arg.endswith(u"Ivan Krsti\u0107")) db.execute(u"select Ivan Krsti\u0107")
def test_endswith_ok(self): db = Fake("db").expects("execute").with_args(arg.endswith("values (1,2,3,4)")) db.execute("insert into foo values (1,2,3,4)")
def test_endswith_ok_uni(self): db = Fake("db").expects("execute").with_args(arg.endswith("Ivan Krsti\u0107")) db.execute("select Ivan Krsti\u0107")
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from fudge import Fake, with_fakes, with_patched_object, clear_expectations from fudge.inspector import arg import ion.settings as sets from ion import Settings, SettingsSection from ConfigParser import ConfigParser, NoSectionError, NoOptionError exists_fake = Fake(callable=True).with_args(arg.any_value()).returns(True) parser = Fake("ConfigParser").expects("__init__").expects("read").with_args(arg.endswith("config.ini")) @with_fakes @with_patched_object(sets, "ConfigParser", parser) @with_patched_object(sets, "exists", exists_fake) def test_can_create_settings(): clear_expectations() settings = Settings("some_dir") assert settings @with_fakes @with_patched_object(sets, "ConfigParser", parser) @with_patched_object(sets, "exists", exists_fake)
setup() clear_expectations() prov = CreateProjectProvider() try: prov.execute(None, None, None) except ValueError, err: assert str(err).strip() == "You need to pass the project name to be created", str(err).strip() return assert False, "Shouldn't reach this far" teardown() fake_exists_1 = Fake(callable=True).with_args(arg.endswith("some_path/some_project")).returns(True) @with_fakes @with_patched_object(providers, "exists", fake_exists_1) def test_create_project_provider_raises_when_directory_already_exists(): setup() clear_expectations() prov = CreateProjectProvider() try: prov.execute("some_path", None, ["some_project"]) except ValueError, err: assert str(err).endswith("some_path/some_project) already exists! Please choose a different name or try another folder.") return assert False, "Shouldn't reach this far"
class TestController(Controller): @route("/something") def SomeAction(self): pass ctrl = TestController() ctrl.register_routes(dispatcher) template_context = Fake('context').has_attr(settings=Fake('settings')) template_context.settings.has_attr(Ion=Fake('ion')) template_context.settings.Ion.has_attr(template_path="some/path/to/templates") template_loader = Fake('template_loader') environment = Fake(callable=True).with_args(loader=arg.any_value()).returns(template_loader) package_loader = Fake(callable=True).with_args(arg.endswith("some/root/templates")) template_fake = Fake('template') template_loader.expects('get_template').with_args('some_file.html').returns(template_fake) template_fake.expects('render').with_args(user="******", some="args", settings=arg.any_value()).returns("expected") @with_fakes @with_patched_object(ctrl, "Environment", environment) @with_patched_object(ctrl, "FileSystemLoader", package_loader) @with_patched_object(ctrl, "cherrypy", authenticated_cherrypy) def test_render_template(): clear_expectations() clear() ctrl = Controller() ctrl.server = Fake('server')