def test_duplicates_included(self): exporter = export_pot._PotExporter(StringIO(), True) context = export_pot._ModuleContext("mod.py", 1) exporter.poentry_in_context(context, "Common line.") context.lineno = 3 exporter.poentry_in_context(context, "Common line.") self.assertEqual(2, exporter.outf.getvalue().count("Common line."))
def test_registry_option_title_context_string(self): s = "Grounded!" context = export_pot._ModuleContext("practice.py", 3, ({}, {s: 144})) opt = option.RegistryOption.from_kwargs("concrete", title=s) self.assertContainsString( self.pot_from_option(opt, context), "#: practice.py:144\n" "# title of 'concrete' test\n")
def test_registry_option_title_context_string(self): s = "Grounded!" context = export_pot._ModuleContext("practice.py", 3, ({}, {s: 144})) opt = option.RegistryOption.from_kwargs("concrete", title=s) self.assertContainsString(self.pot_from_option(opt, context), "#: practice.py:144\n" "# title of 'concrete' test\n")
def test_option_context_string(self): s = "Literally." context = export_pot._ModuleContext("local.py", 3, ({}, {s: 17})) opt = option.Option("example", help=s) self.assertContainsString( self.pot_from_option(opt, context), "#: local.py:17\n" "# help of 'example' test\n")
def pot_from_option(self, opt, context=None, note="test"): sio = StringIO() exporter = export_pot._PotExporter(sio) if context is None: context = export_pot._ModuleContext("nowhere", 0) export_pot._write_option(exporter, context, opt, note) return sio.getvalue()
def test_option_context_string(self): s = "Literally." context = export_pot._ModuleContext("local.py", 3, ({}, {s: 17})) opt = option.Option("example", help=s) self.assertContainsString(self.pot_from_option(opt, context), "#: local.py:17\n" "# help of 'example' test\n")
def test_from_string_missing(self): """When string has no lineno the old context details are returned""" path = "str_missing.py" context = export_pot._ModuleContext(path, 4, ({}, {"line\n": 21})) context1 = context.from_string("line\n") context2A = context.from_string("not there") self.check_context(context2A, path, 4) context2B = context1.from_string("not there") self.check_context(context2B, path, 21) self.assertContainsRe(self.get_log(), "String 'not there' not found")
def test_from_class_missing(self): """When class has no lineno the old context details are returned""" path = "cls_missing.py" class A(object): pass class M(object): pass context = export_pot._ModuleContext(path, 3, ({"A": 15}, {})) contextA = context.from_class(A) contextM1 = context.from_class(M) self.check_context(contextM1, path, 3) contextM2 = contextA.from_class(M) self.check_context(contextM2, path, 15) self.assertContainsRe(self.get_log(), "Definition of <.*M'> not found")
def test_from_string(self): """New context returned with lineno updated from string""" path = "str.py" str_lines = {"one": 14, "two": 42} context = export_pot._ModuleContext(path, _source_info=({}, str_lines)) context1 = context.from_string("one") self.check_context(context1, path, 14) context2A = context.from_string("two") self.check_context(context2A, path, 42) context2B = context1.from_string("two") self.check_context(context2B, path, 42) self.check_context(context, path, 1) self.assertEquals("", self.get_log())
def test_from_string(self): """New context returned with lineno updated from string""" path = "str.py" str_lines = {"one": 14, "two": 42} context = export_pot._ModuleContext(path, _source_info=({}, str_lines)) context1 = context.from_string("one") self.check_context(context1, path, 14) context2A = context.from_string("two") self.check_context(context2A, path, 42) context2B = context1.from_string("two") self.check_context(context2B, path, 42) self.check_context(context, path, 1) self.assertEqual("", self.get_log())
def test_from_class(self): """New context returned with lineno updated from class""" path = "cls.py" class A(object): pass class B(object): pass cls_lines = {"A": 5, "B": 7} context = export_pot._ModuleContext(path, _source_info=(cls_lines, {})) contextA = context.from_class(A) self.check_context(contextA, path, 5) contextB1 = context.from_class(B) self.check_context(contextB1, path, 7) contextB2 = contextA.from_class(B) self.check_context(contextB2, path, 7) self.check_context(context, path, 1) self.assertEquals("", self.get_log())
def test_from_class(self): """New context returned with lineno updated from class""" path = "cls.py" class A(object): pass class B(object): pass cls_lines = {"A": 5, "B": 7} context = export_pot._ModuleContext(path, _source_info=(cls_lines, {})) contextA = context.from_class(A) self.check_context(contextA, path, 5) contextB1 = context.from_class(B) self.check_context(contextB1, path, 7) contextB2 = contextA.from_class(B) self.check_context(contextB2, path, 7) self.check_context(context, path, 1) self.assertEqual("", self.get_log())
def test_registry_option_title_context_missing(self): context = export_pot._ModuleContext("theory.py", 3) opt = option.RegistryOption.from_kwargs("abstract", title="Unfounded!") self.assertContainsString(self.pot_from_option(opt, context), "#: theory.py:3\n" "# title of 'abstract' test\n")
def test_option_context_missing(self): context = export_pot._ModuleContext("remote.py", 3) opt = option.Option("metaphor", help="Not a literal in the source.") self.assertContainsString(self.pot_from_option(opt, context), "#: remote.py:3\n" "# help of 'metaphor' test\n")
def test_option_context_missing(self): context = export_pot._ModuleContext("remote.py", 3) opt = option.Option("metaphor", help="Not a literal in the source.") self.assertContainsString( self.pot_from_option(opt, context), "#: remote.py:3\n" "# help of 'metaphor' test\n")
def test_registry_option_title_context_missing(self): context = export_pot._ModuleContext("theory.py", 3) opt = option.RegistryOption.from_kwargs("abstract", title="Unfounded!") self.assertContainsString( self.pot_from_option(opt, context), "#: theory.py:3\n" "# title of 'abstract' test\n")
def test___init__(self): context = export_pot._ModuleContext("one.py") self.check_context(context, "one.py", 1) context = export_pot._ModuleContext("two.py", 5) self.check_context(context, "two.py", 5)