示例#1
0
    def test_file_preview(self) -> None:
        path = (pathlib.Path(__file__).parent.parent.absolute() /
                "file_formats" / "tests" / "stairs.ctb")
        ctb_preview = CTBFile.read_preview(path)

        with patch("mariner.server.utils.CTBFile.read_preview",
                   return_value=ctb_preview):
            response = self.client.get("/api/file_preview?filename=stairs.ctb")
            expect(response.content_type).to_equal("image/png")
            expect(hashlib.md5(response.get_data()).hexdigest()).to_equal(
                "ca98c806d42898ba70626e556f714928")
示例#2
0
 def test_preview_rendering(self) -> None:
     path = pathlib.Path(__file__).parent.absolute() / "pyramid.cbddlp"
     bytes = io.BytesIO()
     preview_image: png.Image = CTBFile.read_preview(path)
     preview_image.write(bytes)
     expect(preview_image.info["width"]).to_equal(400)
     expect(preview_image.info["height"]).to_equal(300)
     expect(preview_image.info["bitdepth"]).to_equal(5)
     expect(preview_image.info["alpha"]).is_false()
     expect(hashlib.md5(bytes.getvalue()).hexdigest()).to_equal(
         "1e80ffc6bd1e975f9c943dfbcb990be5")
示例#3
0
 def test_preview_rendering(self) -> None:
     path = pathlib.Path(__file__).parent.absolute() / "stairs.ctb"
     bytes = io.BytesIO()
     preview_image: png.Image = CTBFile.read_preview(path)
     preview_image.write(bytes)
     expect(preview_image.info["width"]).to_equal(400)
     expect(preview_image.info["height"]).to_equal(300)
     expect(preview_image.info["bitdepth"]).to_equal(5)
     expect(preview_image.info["alpha"]).is_false()
     expect(hashlib.md5(bytes.getvalue()).hexdigest()).to_equal(
         "ca98c806d42898ba70626e556f714928")
示例#4
0
 def test_loading_cbddlp_file(self) -> None:
     path = pathlib.Path(__file__).parent.absolute() / "pyramid.cbddlp"
     cbddlp_file = CTBFile.read(path)
     expect(cbddlp_file.filename).to_equal("pyramid.cbddlp")
     expect(cbddlp_file.bed_size_mm).to_equal((68.04, 120.96, 150.0))
     expect(cbddlp_file.height_mm).close_to(2.5, max_delta=1e-9)
     expect(cbddlp_file.layer_height_mm).close_to(0.05, max_delta=1e-9)
     expect(cbddlp_file.layer_count).to_equal(50)
     expect(cbddlp_file.resolution).to_equal((1440, 2560))
     expect(cbddlp_file.print_time_secs).to_equal(931)
     expect(cbddlp_file.end_byte_offset_by_layer[:5]).to_equal(
         [42047, 161261, 280467, 399665, 518853])
     expect(cbddlp_file.end_byte_offset_by_layer[-5:]).to_equal(
         [5389468, 5507868, 5626244, 5744596, 5862924])
     expect(cbddlp_file.slicer_version).to_equal("1.7.0.0")
     expect(cbddlp_file.printer_name).to_equal("ELEGOO MARS")
示例#5
0
 def test_loading_ctb_file(self) -> None:
     path = pathlib.Path(__file__).parent.absolute() / "stairs.ctb"
     ctb_file = CTBFile.read(path)
     expect(ctb_file.filename).to_equal("stairs.ctb")
     expect(ctb_file.bed_size_mm).to_equal((68.04, 120.96, 150.0))
     expect(ctb_file.height_mm).close_to(20.0, max_delta=1e-9)
     expect(ctb_file.layer_height_mm).close_to(0.05, max_delta=1e-9)
     expect(ctb_file.layer_count).to_equal(400)
     expect(ctb_file.resolution).to_equal((1440, 2560))
     expect(ctb_file.print_time_secs).to_equal(5621)
     expect(ctb_file.end_byte_offset_by_layer[:5]).to_equal(
         [26272, 28057, 29842, 31627, 33412])
     expect(ctb_file.end_byte_offset_by_layer[-5:]).to_equal(
         [822027, 824704, 827383, 830061, 832745])
     expect(ctb_file.slicer_version).to_equal("1.6.5.1")
     expect(ctb_file.printer_name).to_equal("ELEGOO MARS Pro")
示例#6
0
    def test_file_details(self) -> None:
        path = (pathlib.Path(__file__).parent.parent.absolute() /
                "file_formats" / "tests" / "stairs.ctb")
        ctb_file = CTBFile.read(path)

        with patch("mariner.server.utils.CTBFile.read", return_value=ctb_file):
            response = self.client.get("/api/file_details?filename=stairs.ctb")
            expect(response.get_json()).to_equal({
                "filename":
                "stairs.ctb",
                "path":
                "stairs.ctb",
                "bed_size_mm": [68.04, 120.96, 150.0],
                "height_mm":
                20.0,
                "layer_count":
                400,
                "layer_height_mm":
                0.05,
                "resolution": [1440, 2560],
                "print_time_secs":
                5621,
            })
示例#7
0
def read_cached_preview(filename: str) -> bytes:
    assert os.path.isabs(filename)
    bytes = io.BytesIO()
    preview_image: png.Image = CTBFile.read_preview(FILES_DIRECTORY / filename)
    preview_image.write(bytes)
    return bytes.getvalue()
示例#8
0
def read_cached_ctb_file(filename: str) -> CTBFile:
    assert os.path.isabs(filename)
    return CTBFile.read(FILES_DIRECTORY / filename)