def test_parse_metadata(self):
        with mock.patch("builtins.open", mock.mock_open()) as m:
            with mock.patch("csv.reader") as mock_csv_reader:
                args = _arg_parse().parse_args(
                    ["-c", "mock_location.csv", "-u", "c"])
                mock_csv_reader.return_value = [["filename", "b", "c"],
                                                ["f.wav", "v", "y"]]
                d = parse_metadata(args, {"f.wav": 0})
                m.assert_called_with("mock_location.csv", "r")
                self.assertFalse("filename" in d,
                                 "'filename' was not properly ignored")

                self.assertTrue("b" in d)
                self.assertTrue("__filterable" in d["b"],
                                "'__filterable' not in 'a'")
                self.assertTrue(d["b"]["__filterable"],
                                "'__filterable' in 'b' is not True")
                self.assertTrue("v" in d["b"], "'v' not in 'b'")
                self.assertTrue("points" in d["b"]["v"],
                                "'points' not in 'b'.'v'")
                self.assertEqual(d["b"]["v"]["points"], [0],
                                 "Invalid point list for 'b'")

                self.assertTrue("c" in d, "'c' not in dictionary")
                self.assertTrue("__filterable" in d["c"],
                                "'__filterable' not in 'c'")
                self.assertFalse(d["c"]["__filterable"],
                                 "'__filterable' in 'c' is not False")
                self.assertTrue("y" in d["c"], "'y' not in 'c'")
                self.assertEqual(d["c"]["y"]["points"], [0],
                                 "Invalid point list for 'c'")
                self.assertTrue("points" in d["c"]["y"],
                                "'points' not in 'c'.'y'")
 def test_pca_job(self):
     args = _arg_parse().parse_args()
     arr = numpy.asarray([[1, 2, 3], [3, 4, 5], [5, 6, 7]])
     ret = pca(arr, 2, args)
     self.assertEqual(ret[0][0].shape, (3, 2), "invalid shape")
     self.assertEqual(ret[0][1], "pca")
     self.assertEqual(len(ret), 1)
Esempio n. 3
0
 def test_t_sne_parallel(self):
     args = _arg_parse().parse_args(["-p", "30", "50", "--parallel"])
     arr = numpy.asarray([1, 2, 3])
     res = t_sne(arr, 2, args)
     rarr = numpy.asarray([3, 2, 1])
     self.assertEqual(len(res), 2)
     self.assertTrue(numpy.array_equal(res[0][0], rarr))
     self.assertEqual(res[0][1], "mock")
     self.assertTrue(numpy.array_equal(res[1][0], rarr))
     self.assertEqual(res[1][1], "mock")
Esempio n. 4
0
 def test_t_sne_serial(self, mock_t_sne_job):
     args = _arg_parse().parse_args(["-p", "30", "50"])
     rarr = numpy.asarray([1, 2])
     mock_t_sne_job.return_value = (rarr, "30")
     arr = numpy.asarray([1, 2, 3])
     res = t_sne(arr, 2, args)
     self.assertEqual(len(res), 2)
     self.assertEqual(mock_t_sne_job.call_count, 2)
     self.assertEqual(res[0], (rarr, "30"))
     self.assertEqual(res[1], (rarr, "30"))
Esempio n. 5
0
 def setUp(self):
     self.ap = crunch._arg_parse()
     self.def_ap = self.ap.parse_args(args=[])
     self.val_ap = self.ap.parse_args(args=[
         "-f", "samp/", "-p", "20", "50", "60", "-o", "pca.json", "-r",
         "fing.npy", "-m", "-100", "-x", "100", "-t", "pca.png", "-c",
         "samp/data.csv", "-d", "4000", "-u", "unfilterable", "-n",
         "test_data_set", "-s", "sound_info.json", "-a", "1000", "-b",
         "pronunciation", "-k", "pca", "-g", "fft", "-e", "input.npy",
         "--td", "--colorby", "phoneme", "--parallel"
     ])
 def test_pca_func_call(self, mock_sci_pca):
     mock_func = mock.MagicMock()
     args = _arg_parse().parse_args()
     arr = numpy.asarray([1, 2, 3])
     params = (4, 5)
     res = pca(arr, 2, args, mock_func, params)
     mock_sci_pca.assert_called_with(n_components=2, svd_solver='full')
     self.assertEqual(mock_func.call_args[0][0][1], "pca")
     self.assertEqual(mock_func.call_args[0][1], 4)
     self.assertEqual(mock_func.call_args[0][2], 5)
     self.assertEqual(res[0][1], "pca")
 def test_load_numpy_fingerprint(self):
     with mock.patch("numpy.load", mock.mock_open()) as mock_load:
         args = _arg_parse().parse_args(
             ["-e", "mock.npy", "--format", "npy"])
         mock_load.return_value = [("name_1", np.asarray([1, 2, 3])),
                                   ("name_2", np.asarray([4, 5, 6]))]
         results, file_data = load_fingerprints(args)
         mock_load.assert_called_with("mock.npy")
         self.assertSequenceEqual(file_data, ["name_1", "name_2"])
         self.assertEqual(len(results), 2)
         assert_array_equal(results[0], [1, 2, 3])
         assert_array_equal(results[1], [4, 5, 6])
 def test_load_csv_fingerprint(self):
     with mock.patch("builtins.open", mock.mock_open()) as m:
         with mock.patch("csv.reader") as mock_csv_reader:
             args = _arg_parse().parse_args(
                 ["-e", "mock.csv", "--format", "csv"])
             mock_csv_reader.return_value = [["name_1", "1", "2", "3"],
                                             ["name_2", "4", "5", "6"]]
             results, file_data = load_fingerprints(args)
             m.assert_called_with("mock.csv")
             self.assertSequenceEqual(file_data, ["name_1", "name_2"])
             self.assertEqual(len(results), 2)
             assert_array_equal(results[0], [1, 2, 3])
             assert_array_equal(results[1], [4, 5, 6])