# Path: moonlight/training/clustering/kmeans_labeler_request_handler.py
# class LabelerHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
#   def __init__(self, clusters, output_path, *args):
#   def do_GET(self):
#   def do_POST(self):
# def create_page(clusters, template):
# def _process_cluster(cluster):
# def create_highlighted_image(cluster, enlarge_ratio=10):
# def create_examples(clusters, labels):


import re
import numpy as np
from absl.testing import absltest
from mako import template as mako_template
from tensorflow.core.example import example_pb2
from tensorflow.core.example import feature_pb2
from tensorflow.python.platform import resource_loader
from moonlight.protobuf import musicscore_pb2
from moonlight.training.clustering import kmeans_labeler_request_handler
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for the k-means labeler request handler."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function





class KmeansLabelerRequestHandlerTest(absltest.TestCase):

  def testCreatePage(self):
    num_clusters = 10
    clusters = np.random.random((num_clusters, 12, 14))
    template_src = resource_loader.get_path_to_datafile(
        'kmeans_labeler_template.html')
    template = mako_template.Template(open(template_src).read())
    html = kmeans_labeler_request_handler.create_page(clusters, template)
    self.assertEqual(len(re.findall('<img', html)), num_clusters)
    self.assertEqual(len(re.findall('<select', html)), num_clusters)

  def testCreateExamples(self):
    clusters = np.random.random((5, 12, 14))
    labels = ['NONE', 'CLEF_TREBLE', 'NONE', 'NOTEHEAD_FILLED', 'CLEF_BASS']

# Path: moonlight/training/clustering/kmeans_labeler_request_handler.py
# class LabelerHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
#   def __init__(self, clusters, output_path, *args):
#   def do_GET(self):
#   def do_POST(self):
# def create_page(clusters, template):
# def _process_cluster(cluster):
# def create_highlighted_image(cluster, enlarge_ratio=10):
# def create_examples(clusters, labels):


# Path: moonlight/training/clustering/kmeans_labeler_request_handler_test.py
import re
import numpy as np
from absl.testing import absltest
from mako import template as mako_template
from tensorflow.core.example import example_pb2
from tensorflow.core.example import feature_pb2
from tensorflow.python.platform import resource_loader
from moonlight.protobuf import musicscore_pb2
from moonlight.training.clustering import kmeans_labeler_request_handler

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for the k-means labeler request handler."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function





class KmeansLabelerRequestHandlerTest(absltest.TestCase):

  def testCreatePage(self):
    num_clusters = 10
    clusters = np.random.random((num_clusters, 12, 14))
    template_src = resource_loader.get_path_to_datafile(
        'kmeans_labeler_template.html')
    template = mako_template.Template(open(template_src).read())
    html = kmeans_labeler_request_handler.create_page(clusters, template)
    self.assertEqual(len(re.findall('<img', html)), num_clusters)
    self.assertEqual(len(re.findall('<select', html)), num_clusters)

  def testCreateExamples(self):
    clusters = np.random.random((5, 12, 14))
    labels = ['NONE', 'CLEF_TREBLE', 'NONE', 'NOTEHEAD_FILLED', 'CLEF_BASS']

    examples = kmeans_labeler_request_handler.create_examples(clusters, labels)