Exemple #1
0
 def test_missing_fields(self) -> None:
     """Tests if loading fails when a tabbed text file has missing fields."""
     tabbed_txt_content = (
         # Header row
         "CofName\tFramesPerDirection\tAnimationSpeed\t" +
         "\t".join(f"FrameData{i:03}" for i in range(144)) + "\r\n"
         # Record 0
         + ("00A1HTH\t1\t256\t0\t1\t2\t3\r\n"))
     with self.assertRaises(TabbedTextError):
         load_txt(StringIO(tabbed_txt_content, newline=""))
Exemple #2
0
    def test_bad_records(self) -> None:
        """Tests if loading a tabbed text file containing bad records causes an
        error.
        """
        tabbed_txt_content = (
            # Header row
            "CofName\tFramesPerDirection\tAnimationSpeed\t" +
            "\t".join(f"FrameData{i:03}" for i in range(144)) + "\r\n"
            # Record 0
            + ("BAD COF NAME\t1\t256\t0\t1\t2\t3" + "\t0" * 140 + "\r\n"))
        with self.assertRaises(TabbedTextError):
            load_txt(StringIO(tabbed_txt_content, newline=""))

        tabbed_txt_content = (
            # Header row
            "CofName\tFramesPerDirection\tAnimationSpeed\t" +
            "\t".join(f"FrameData{i:03}" for i in range(144)) + "\r\n"
            # Record 0
            + ("00A1HTH\t-1\t256\t0\t1\t2\t3" + "\t0" * 140 + "\r\n"))
        with self.assertRaises(TabbedTextError):
            load_txt(StringIO(tabbed_txt_content, newline=""))
Exemple #3
0
 def test_valid(self) -> None:
     """Tests if a valid tabbed text file can be loaded correctly."""
     tabbed_txt = StringIO(TXT_VALID, newline="")
     records = load_txt(tabbed_txt)
     self.assertEqual(records, RECORDS_VALID)
Exemple #4
0
 def test_invalid_format(self) -> None:
     """Tests if loading fails when a tabbed text file cannot be parsed."""
     tabbed_txt = StringIO("This isn't a tabbed text file!", newline="")
     with self.assertRaises(TabbedTextError):
         load_txt(tabbed_txt)