Example #1
0
 def test_get_image_returns_image_path(self):
     cm = StoreWriter(self.directory, self.file_name)
     cm.to_image(MagicMock(), 'test_image')
     path = cm.get_img_path()
     self.assertIsNotNone(path)
     self.assertIn('test_image', path)
     self.assertIn("img_dir", path)
     self.assertIn(self.directory, path)
    def test_get_img_path_returns_none_if_to_image_not_called(self):
        # Arrange
        cm = StoreWriter(self.directory, self.file_name)
        cm.to_image = MagicMock()

        # Act
        cm.to_image.assert_not_called()

        # Assert
        self.assertIsNone(cm.get_img_path())
Example #3
0
    def test_remove_image_file_attempts_to_remove_file_when_it_exists(self):
        # Arrange
        cm = StoreWriter(self.directory, self.file_name)
        cm._file_manager = MagicMock()
        cm._file_manager.is_file.return_value = True

        # Act
        cm.remove_img_file(MagicMock())

        # Assert
        cm._file_manager.remove.assert_called_once()
    def test_to_image_calls_image_save_as(self):
        # Arrange
        cm = StoreWriter(self.directory, self.file_name)
        pin_image = MagicMock()
        holder_image = MagicMock()

        # Act
        cm.to_image(pin_image, holder_image, 'test_image')

        # Assert
        pin_image.save_as.assert_called_once()
    def test_to_image_makes_img_dir(self):
        # Arrange
        cm = StoreWriter(self.directory, self.file_name)
        cm._make_img_dir = MagicMock()
        cm._make_img_dir.return_value = 'dir'

        # Act
        cm.to_image(MagicMock(), MagicMock(), 'name')

        # Assert
        cm._make_img_dir.assert_called_once()
Example #6
0
    def test_make_image_dir_attempts_to_create_img_dir(self):

        # Arrange
        cm = StoreWriter(self.directory, self.file_name)
        cm._file_manager = MagicMock()
        img_dir = os.path.join(self.directory, "img_dir")

        # Act
        cm._make_img_dir()

        # Assert
        self.assertEqual(cm._file_manager.make_dir_when_no_dir.call_count, 2)
        cm._file_manager.make_dir_when_no_dir.assert_called_with(img_dir)
Example #7
0
    def test_to_file_csv_store_in_csv_file(self):
        # Arrange
        cm = StoreWriter(self.directory, self.file_name)
        cm._file_manager = MagicMock()
        file_name = os.path.join(self.directory, self.file_name + ".csv")

        # Act
        cm.to_csv_file(self.records)

        # Assert
        ((filename_used, record_lines_used),
         kwargs) = cm._file_manager.write_lines.call_args_list[0]
        self.assertEqual(file_name, filename_used)
        for r, l in zip(self.records, record_lines_used):
            self.assertIn(r.to_csv_string(), l)
Example #8
0
 def backup_records(self, directory):
     ts = time.localtime()
     file_name = time.strftime("%Y-%m-%d_%H-%M-%S", ts)
     backup_writer = StoreWriter(directory, file_name)
     backup = Backup(backup_writer)
     self._sort_records()
     backup.backup_records(self.records)
    def test_to_image_sets_image_path(self):
        # Arrange
        cm = StoreWriter(self.directory, self.file_name)

        # Act
        self.assertIsNone((cm.get_img_path()))
        cm.to_image(MagicMock(), MagicMock(), 'name')

        # Assert
        self.assertIsNotNone((cm.get_img_path()))
Example #10
0
    def __init__(self, barcode_table, image_frame, options):
        super(ScanRecordTable, self).__init__()

        # Read the store from file
        store_writer = StoreWriter(options.get_store_directory(), "store")
        store_loader = StoreLoader(options.get_store_directory(), "store")

        self._store = Store(store_writer,
                            store_loader.load_records_from_file())
        self._options = options

        self._barcodeTable = barcode_table
        self._imageFrame = image_frame

        self.setTitle("Scan Records")
        self.setMaximumWidth(730)

        self._init_ui()

        self._load_store_records()
Example #11
0
 def test_to_image_calls_image_save_as(self):
     cm = StoreWriter(self.directory, self.file_name)
     image = MagicMock()
     cm.to_image(image, 'test_image')
     image.save_as.assert_called_once()
# SHOULD BE OPEN CV 2.4.10

# Directory storing all of the test images
from dls_util.shape import Point

TEST_IMG_DIR = 'tests/test-resources/blue_stand/'
CONFIG_FILE = os.path.join(TEST_IMG_DIR, "system_test_config.ini")
FILE_MANAGER = FileManager()
OPTIONS = BarcodeConfig(CONFIG_FILE, FILE_MANAGER)

# Clear store before creating a new one
store_dir = OPTIONS.store_directory
if os.path.isdir(store_dir.value()):
    shutil.rmtree(store_dir.value())
comms_manger = StoreWriter(OPTIONS.get_store_directory(), "store")
STORE = Store(comms_manger, MagicMock)


def test_generator():
    TEST_CASES = generate_test_cases()
    for params in TEST_CASES:
        yield run_scans, params[0], params[1]


def run_scans(img_file, expected_codes):
    filepath = os.path.join(TEST_IMG_DIR, img_file)
    print(img_file)
    cv_image = Image.from_file(filepath)
    gray_image = cv_image.to_grayscale()
    results = GeometryScanner("Unipuck",