"""
Tests for BSE metadata
"""

import os
import hashlib
import bse
from bse import curate

data_dir = bse.default_data_dir

def test_get_metadata():
    bse.get_metadata()


def test_metadata_uptodate():
    old_metadata = os.path.join(data_dir, 'METADATA.json')
    new_metadata = os.path.join(data_dir, 'METADATA.json.new')
    curate.create_metadata_file(new_metadata, data_dir)

    with open(old_metadata, 'rb') as f:
        old_hash = hashlib.sha1(f.read()).hexdigest()
    with open(new_metadata, 'rb') as f:
        new_hash = hashlib.sha1(f.read()).hexdigest()

    os.remove(new_metadata)

    if old_hash != new_hash:
        print("Old hash: ", old_hash)
        print("New hash: ", new_hash)
        raise RuntimeError("Metadata does not appear to be up to date")

@@ -46,23 +46,19 @@
 ort 
-hashlib
+bse
 %0Aimport 
 bse%0A
@@ -53,19 +53,20 @@
 %0Aimport 
-bse
+json
 %0Afrom bs
@@ -396,33 +396,32 @@
 old_metadata, 'r
-b
 ') as f:%0A       
@@ -429,48 +429,26 @@
 old_
-hash = hashlib.sha1(f.read()).hexdigest(
+data = json.load(f
 )%0A  
@@ -475,17 +475,16 @@
 data, 'r
-b
 ') as f:
@@ -500,48 +500,26 @@
 new_
-hash = hashlib.sha1(f.read()).hexdigest(
+data = json.load(f
 )%0A%0A 
@@ -561,20 +561,20 @@
 old_
-hash
+data
  != new_
 hash
@@ -573,89 +573,13 @@
 new_
-hash:%0A        print(%22Old hash: %22, old_hash)%0A        print(%22New hash: %22, new_hash)
+data:
 %0A   

Fix testing of metadata - hashing is too strict