def test_JPV_230_python_version_is_less_than(self): vi = sys.version_info for (major, minor, micro, expected) in [ (vi.major, vi.minor, vi.micro, False), (vi.major + 1, vi.minor, vi.micro, True), (vi.major, vi.minor + 1, vi.micro, True), (vi.major, vi.minor, vi.micro + 1, True), (vi.major - 1, vi.minor, vi.micro, False), (vi.major, vi.minor - 1, vi.micro, False), (vi.major, vi.minor, vi.micro - 1, False), ]: result = pv.python_version_is_less_than(major, minor, micro) self.assertEqual(result, expected) result = pv.python_version_is_less_than(major, minor=minor, micro=micro) self.assertEqual(result, expected)
def test_JIU_201_is_string_unicode(self): if pv.python_version_is_less_than(3): for (thing, expected) in [ # fmt: off (u"x", True), # fmt: on ]: result = jiu.is_string(thing) self.assertEqual(result, expected)
def test_JSI_117_dump_json_text_indent_string(self): for (kwargs, json_data, expected_json_text) in [ (INDENT_KWARGS, DUMMY_JSON_DATA_ORDERED_DICT, DUMMY_JSON_TEXT_FORMATTED), ]: if pv.python_version_is_less_than(3, 2): with self.assertRaises(TypeError) as context: # noqa: F841 ji.dump_json_text(json_data, **kwargs) errmsg = context.exception.args[0] self.assertEqual( errmsg, "can't multiply sequence by non-int of type 'str'") else: text = ji.dump_json_text(json_data, **kwargs) self.assertEqual(text, expected_json_text)
def test_JSI_111_dump_json_indent_string(self): with open(self.outfile.name, "w") as f: # Ensure file exists and is empty pass for (kwargs, json_data, expected_json_text) in [ (INDENT_KWARGS, DUMMY_JSON_DATA_ORDERED_DICT, DUMMY_JSON_TEXT_FORMATTED), ]: if pv.python_version_is_less_than(3, 2): with self.assertRaises(TypeError) as context: # noqa: F841 with open(self.outfile.name, "w") as f: ji.dump_json(json_data, f, **kwargs) errmsg = context.exception.args[0] self.assertEqual( errmsg, "can't multiply sequence by non-int of type 'str'") else: with open(self.outfile.name, "w") as f: text = ji.dump_json(json_data, f, **kwargs) self.assertEqual(text, expected_json_text) with open(self.outfile.name, "r") as f: self.assertEqual(f.read(), expected_json_text) if pv.python_version_is_less_than(3, 2): with self.assertRaises(TypeError) as context: # noqa: F841 with open(self.outfile.name, "w") as f: ji.dump_json(json_data, outfile=f, **kwargs) errmsg = context.exception.args[0] self.assertEqual( errmsg, "can't multiply sequence by non-int of type 'str'") else: with open(self.outfile.name, "w") as f: text = ji.dump_json(json_data, outfile=f, **kwargs) self.assertEqual(text, expected_json_text) with open(self.outfile.name, "r") as f: self.assertEqual(f.read(), expected_json_text)
def test_JSI_303_cli_inplace_indent_string(self): for (test_args, expected_json_text) in [ (ARGS_INDENT, DUMMY_JSON_TEXT_FORMATTED), ]: with open(self.infile.name, "w") as f: f.write(DUMMY_JSON_TEXT_UNFORMATTED) args = test_args + ARGS_DEBUG + ["--inplace", self.infile.name] if pv.python_version_is_less_than(3, 2): with self.assertRaises(TypeError) as context: # noqa: F841 ji.cli(*args) errmsg = context.exception.args[0] self.assertEqual( errmsg, "can't multiply sequence by non-int of type 'str'") else: ji.cli(*args) with open(self.infile.name, "r") as f: self.assertEqual(f.read(), expected_json_text)