def test_attributes_construtor(self): m1 = Mock() m2 = Mock() cfg = config.Config(attributes={'m1': m1}) cfg.attributes['connection'] = m2 eq_( cfg.attributes, {'m1': m1, 'connection': m2} )
def test_column_type_not_modified_custom_compare_type_returns_False(self): my_compare_type = Mock() my_compare_type.return_value = False self.context._user_compare_type = my_compare_type diffs = [] autogenerate._produce_net_changes(self.context.bind, self.m2, diffs, self.autogen_context) eq_(diffs, [])
def test_column_type_modified_custom_compare_type_returns_True(self): my_compare_type = Mock() my_compare_type.return_value = True self.context._user_compare_type = my_compare_type diffs = [] autogenerate._produce_net_changes(self.context.bind, self.m2, diffs, self.autogen_context) eq_(diffs[0][0][0], 'modify_type') eq_(diffs[1][0][0], 'modify_type')
def test_column_type_modified_custom_compare_type_returns_True(self): my_compare_type = Mock() my_compare_type.return_value = True self.context._user_compare_type = my_compare_type ctx = self.autogen_context uo = ops.UpgradeOps(ops=[]) autogenerate._produce_net_changes(ctx, uo) diffs = uo.as_diffs() eq_(diffs[0][0][0], 'modify_type') eq_(diffs[1][0][0], 'modify_type')
def test_column_type_modified_custom_compare_type_returns_True(self): my_compare_type = Mock() my_compare_type.return_value = True self.context._user_compare_type = my_compare_type ctx = self.autogen_context.copy() ctx['metadata'] = self.m2 diffs = [] autogenerate._produce_net_changes(ctx, diffs) eq_(diffs[0][0][0], 'modify_type') eq_(diffs[1][0][0], 'modify_type')
def test_column_type_not_modified_custom_compare_type_returns_False(self): my_compare_type = Mock() my_compare_type.return_value = False self.context._user_compare_type = my_compare_type diffs = [] ctx = self.autogen_context.copy() ctx['metadata'] = self.m2 diffs = [] autogenerate._produce_net_changes(ctx, diffs) eq_(diffs, [])
def test_x_arg(self): env = self._fixture() self.cfg.cmd_opts = Mock(x="y=5") eq_( env.get_x_argument(), "y=5" )
def test_uses_custom_compare_type_function(self): my_compare_type = Mock() self.context._user_compare_type = my_compare_type uo = ops.UpgradeOps(ops=[]) ctx = self.autogen_context autogenerate._produce_net_changes(ctx, uo) first_table = self.m2.tables["sometable"] first_column = first_table.columns["id"] eq_(len(my_compare_type.mock_calls), 2) # We'll just test the first call _, args, _ = my_compare_type.mock_calls[0] ( context, inspected_column, metadata_column, inspected_type, metadata_type, ) = args eq_(context, self.context) eq_(metadata_column, first_column) eq_(metadata_type, first_column.type) eq_(inspected_column.name, first_column.name) eq_(type(inspected_type), INTEGER)
def test_utf8_unicode(self): stdout = Mock(encoding='latin-1') cfg = config.Config(stdout=stdout) cfg.print_stdout(compat.u("méil %s %s"), "x", "y") eq_(stdout.mock_calls, [call.write(compat.u('méil x y')), call.write('\n')])
def test_x_arg_asdict(self): env = self._fixture() self.cfg.cmd_opts = Mock(x=["y=5"]) eq_( env.get_x_argument(as_dictionary=True), {"y": "5"} )
def test_attributes_attr(self): m1 = Mock() cfg = config.Config() cfg.attributes['connection'] = m1 eq_( cfg.attributes['connection'], m1 )
def test_ascii_unicode(self): stdout = Mock(encoding=None) cfg = config.Config(stdout=stdout) cfg.print_stdout(compat.u("méil %s %s"), "x", "y") eq_( stdout.mock_calls, [call.write('m?il x y'), call.write('\n')] )
def test_plain(self): stdout = Mock(encoding='latin-1') cfg = config.Config(stdout=stdout) cfg.print_stdout("test %s %s", "x", "y") eq_( stdout.mock_calls, [call.write('test x y'), call.write('\n')] )
def test_uses_custom_compare_type_function(self): my_compare_type = Mock() self.context._user_compare_type = my_compare_type diffs = [] autogenerate._produce_net_changes(self.context.bind, self.m2, diffs, self.autogen_context) first_table = self.m2.tables['sometable'] first_column = first_table.columns['id'] eq_(len(my_compare_type.mock_calls), 2) # We'll just test the first call _, args, _ = my_compare_type.mock_calls[0] (context, inspected_column, metadata_column, inspected_type, metadata_type) = args eq_(context, self.context) eq_(metadata_column, first_column) eq_(metadata_type, first_column.type) eq_(inspected_column.name, first_column.name) eq_(type(inspected_type), INTEGER)
def test_only_formats_output_with_args(self): stdout = Mock(encoding=None) cfg = config.Config(stdout=stdout) cfg.print_stdout(compat.u("test 3%")) eq_(stdout.mock_calls, [call.write("test 3%"), call.write("\n")])
def test_plain(self): stdout = Mock(encoding="latin-1") cfg = config.Config(stdout=stdout) cfg.print_stdout("test %s %s", "x", "y") eq_(stdout.mock_calls, [call.write("test x y"), call.write("\n")])
def test_attributes_construtor(self): m1 = Mock() m2 = Mock() cfg = config.Config(attributes={"m1": m1}) cfg.attributes["connection"] = m2 eq_(cfg.attributes, {"m1": m1, "connection": m2})